Futilities/human/lib/cFolderator: Difference between revisions

From Woozle Writes Code
< Futilities‎ | human‎ | lib
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
The flow typically starts with <code>StartSpider()</code>, which retrieves the source-path from Options (<code>GetSourcePath()</code>) and then passes control to <code>OnWantedFolder</code>. (We assume that the folder in the source-path is wanted, even if it fails inclusion criteria that are applied to its sub-folders.)
The flow typically starts with <code>StartSpider()</code>, which retrieves the source-path from Options (<code>GetSourcePath()</code>) and then passes control to <code>OnWantedFolder</code>. (We assume that the folder in the source-path is wanted, even if it fails inclusion criteria that are applied to its sub-folders.)


This initiates a recursive loop guided in part by the app's Matcher object, which is an app-defined ({{l/same|caMatch}} podling.
This initiates a recursive loop guided in part by the app's Matcher object, which is an app-defined {{l/same|caMatch}} podling.
===OnWantedFolder===
===OnWantedFolder===
At its core, <syntaxhighlight lang=php inline>OnWantedFolder(caPathPiece $op)</syntaxhighlight> gets a directory listing for <code>$op$</code>, puts that list in an array, and then for each entry in the array sets that entry as the last entry in <code>$opCurr</code> and passes it to <code>OnPath($opCurr)</code>.
At its core, <syntaxhighlight lang=php inline>OnWantedFolder(caPathPiece $op)</syntaxhighlight> gets a directory listing for <code>$op$</code>, puts that list in an array, and then for each entry in the array sets that entry as the last entry in <code>$opCurr</code> and passes it to <code>OnPath($opCurr)</code>.
 
===OnPath===
<code>OnPath({{l/same|caPathPiece}} $op)</code> checks the filespec in <code>$op</code> to see whether it's a file or a folder (it is assumed to exist). In simplified form:
<code>OnPath({{l/same|caPathPiece}} $op)</code> checks the filespec in <code>$op</code> to see whether it's a file or a folder (it is assumed to exist). In simplified form:
<syntaxhighlight lang=php>
<syntaxhighlight lang=php>
Line 17: Line 17:
===OnFolder===
===OnFolder===
<code>OnFolder(caPathNamed $op)</code> asks the Matcher if the folder is wanted:
<code>OnFolder(caPathNamed $op)</code> asks the Matcher if the folder is wanted:
<syntaxhighlight lang=php inline>if ($this->GetMatcher()->IsFolderWanted($op)) { $this->OnWantedFolder($op); }</syntaxhighlight> -- starting a new iteration.
<syntaxhighlight lang=php inline>if ($this->GetMatcher()->IsFolderWanted($op)) { $this->OnWantedFolder($op); }</syntaxhighlight>
 
If the Matcher declares that the folder passes muster, this starts a new iteration.
===OnFile===
===OnFile===
<code>OnFile(caPathNamed $op)</code> asks the Matcher if the file is wanted:
<code>OnFile(caPathNamed $op)</code> asks the Matcher if the file is wanted:
<syntaxhighlight lang=php inline>if ($this->GetMatcher()->IsFileWanted($op)) { $this->GetMatcher()->HandleFile($op); }
<syntaxhighlight lang=php inline>if ($this->GetMatcher()->IsFileWanted($op)) { $this->GetMatcher()->HandleFile($op); }</syntaxhighlight>


Note the slight difference between this and OnFolder(): because we don't need to recurse into files (at least until we support entering .tar/.zip archives), we can just pass control over to the Matcher to decide if the file is wanted ''and'' to handle it if it is.
Note the slight difference between this and OnFolder(): because we don't need to recurse into files (at least until we support entering .tar/.zip archives), we can just pass control over to the Matcher to decide if the file is wanted ''and'' to handle it if it is.

Revision as of 00:52, 28 September 2022

Human Futilities: cFolderator class

Flow

The flow typically starts with StartSpider(), which retrieves the source-path from Options (GetSourcePath()) and then passes control to OnWantedFolder. (We assume that the folder in the source-path is wanted, even if it fails inclusion criteria that are applied to its sub-folders.)

This initiates a recursive loop guided in part by the app's Matcher object, which is an app-defined caMatch podling.

OnWantedFolder

At its core, OnWantedFolder(caPathPiece $op) gets a directory listing for $op$, puts that list in an array, and then for each entry in the array sets that entry as the last entry in $opCurr and passes it to OnPath($opCurr).

OnPath

OnPath(caPathPiece $op) checks the filespec in $op to see whether it's a file or a folder (it is assumed to exist). In simplified form:

if ($op->IsFolder()) {
  $this->OnFolder($op);
} else {
  $this->OnFile($op);
}

OnFolder

OnFolder(caPathNamed $op) asks the Matcher if the folder is wanted: if ($this->GetMatcher()->IsFolderWanted($op)) { $this->OnWantedFolder($op); }

If the Matcher declares that the folder passes muster, this starts a new iteration.

OnFile

OnFile(caPathNamed $op) asks the Matcher if the file is wanted: if ($this->GetMatcher()->IsFileWanted($op)) { $this->GetMatcher()->HandleFile($op); }

Note the slight difference between this and OnFolder(): because we don't need to recurse into files (at least until we support entering .tar/.zip archives), we can just pass control over to the Matcher to decide if the file is wanted and to handle it if it is.

Functions

actions

  • StartSpider(caMatch $om)
    • formerly DoSearch() (kept for now as an alias)

events

state

  • protected function ResetCount() { $this->nFi = 0; $this->nFo = 0; }
  • protected function IncFiles() { $this->nFi++; }
  • protected function IncFolders() { $this->nFo++; }
  • protected function SummarizeCount() : string { ... }: returns a string summarizing file & folder counts
  • protected function ShortCount() : string { ... }: like SummarizeCount(), but shorter string ("fo:#/fi:#")

object

This pair sets and returns a Matcher object:

  • protected function SetMatcher(caMatch $om) { $this->om = $om; }
    • This is only called from DoSearch().
  • protected function GetMatcher() : caMatch { return $this->om; }