rapila
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ResourceFinder Class Reference

Allows to easily find files residing inside rapila’s site structure, following the precedence rules (site > plugins > base). More...

Public Member Functions

 __construct ($aPath=array(), $iFlag=null)
 
 byExpressions ($bByExpressions=true)
 
 all ($bFindAll=true)
 
 returnObjects ($bReturnObjects=true)
 
 noCache ($bNoCache=true)
 
 mainOnly ()
 
 baseOnly ()
 
 siteOnly ()
 
 pluginsOnly ()
 
 baseFirst ()
 
 siteFirst ()
 
 pluginsFirst ()
 
 searchMainOnly ()
 
 searchBaseOnly ()
 
 searchSiteOnly ()
 
 searchPluginsOnly ()
 
 searchBaseFirst ()
 
 searchSiteFirst ()
 
 searchPluginsFirst ()
 
 resultIsArray ()
 
 resultIsAssoc ()
 
 returnsObjects ()
 
 addPath ()
 
 addExpression ()
 
 addOptionalPath ()
 
 addRecursion ()
 
 addAnyPath ($bOptional=false)
 
 addDirPath ($bOptional=false)
 
 addFilePath ($bOptional=false)
 
 addSame ($bCamelized=false)
 
 find ()
 

Static Public Member Functions

static create ($aPath=array(), $iFlag=null)
 
static findResource ($mRelativePath, $iFlag=null, $bByExpressions=false, $bFindAll=false, $bReturnObjects=false)
 
static findAllResources ($mRelativePath, $iFlag=null)
 
static findResourceByExpressions ($aExpressions, $iFlag=null)
 
static findResourcesByExpressions ($aExpressions, $iFlag=null)
 
static findAllResourcesByExpressions ($aExpressions, $iFlag=null)
 
static findResourceObject ($mRelativePath, $iFlag=null)
 
static findAllResourceObjects ($mRelativePath, $iFlag=null)
 
static findResourceObjectByExpressions ($aExpressions, $iFlag=null)
 
static findResourceObjectsByExpressions ($aExpressions, $iFlag=null)
 
static findAllResourceObjectsByExpressions ($aExpressions, $iFlag=null)
 
static pluginFinder ()
 
static parsePathArguments ($sBaseDirname=null, $mPath=null, $sFileName=null)
 
static getFolderContents ($sPath, $bIncludeInvisibles=false)
 
static mimeTypeOfFile ($sFile)
 
static recursiveUnlink ($sFileName)
 

Public Attributes

const SEARCH_MAIN_ONLY = 0
 
const SEARCH_BASE_ONLY = 1
 
const SEARCH_SITE_ONLY = 2
 
const SEARCH_PLUGINS_ONLY = 5
 
const SEARCH_BASE_FIRST = 3
 
const SEARCH_SITE_FIRST = 4
 
const SEARCH_PLUGINS_FIRST = 6
 
const WILDCARD_ANY = null
 
const WILDCARD_DIR = false
 
const WILDCARD_FILE = true
 
const ANY_NAME_OR_TYPE_PATTERN = '/^[\\w_]+$/'
 

Detailed Description

Allows to easily find files residing inside rapila’s site structure, following the precedence rules (site > plugins > base).

Member Function Documentation

ResourceFinder::addSame (   $bCamelized = false)

Adds a resource that needs to have the same name as the parent folder.

Parameters
$bCamelizedwill camelize the parent name before matching.
ResourceFinder::find ( )
Returns
bool|string|FileResource|array the matched path(s)
static ResourceFinder::findAllResourceObjects (   $mRelativePath,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bFindAll and $bReturnObjects set.

static ResourceFinder::findAllResourceObjectsByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bFindAll, $bByExpressions and $bReturnObjects set.

static ResourceFinder::findAllResources (   $mRelativePath,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bFindAll set.

static ResourceFinder::findAllResourcesByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bFindAll and $bByExpressions set.

static ResourceFinder::findResource (   $mRelativePath,
  $iFlag = null,
  $bByExpressions = false,
  $bFindAll = false,
  $bReturnObjects = false 
)
static

Finds files which reside inside the CMS’ main direcory. The goal of findResource is to provide a way of accessing all the desired resources from the most specific location. Files in the site folder override files in the plugins folders which, in turn, override files in the base folder. The return type varies depending on the given options ($bByExpressions, $bFindAll, $bReturnObjects). If $bReturnObjects is false, the returned value(s) will be strings containing the files canonical full path on the file system. $bReturnObjects set to true will return FileResource objects which store much more information and can be used to get to things such as the relative path, the directory the relative path was found in, or the frontend path which is used to directly render a file to the user agent. If $bByExpressions and $bFindAll are set to false, only a single string/object is returned (null if not found). Otherwise, an array is returned. If $bFindAll is set, the returned array is index-based; if only $bByExpressions is set, the returned array’s keys are the relative paths of the respective files.

Parameters
array | string$mRelativePathrelative path to search for in base, plugins or site folders. This can be an array or a string of /-separated directory/file names (or expressions if $bByExpressions is true).
int$iFlagcan be one of either ResourceFinder::SEARCH_MAIN_ONLY, ResourceFinder::SEARCH_BASE_ONLY, ResourceFinder::SEARCH_SITE_ONLY, ResourceFinder::SEARCH_PLUGINS_ONLY, ResourceFinder::SEARCH_BASE_FIRST, ResourceFinder::SEARCH_SITE_FIRST, ResourceFinder::SEARCH_PLUGINS_FIRST. The *_ONLY constants are – except for SEARCH_PLUGINS_ONLY – just for convenience: since they only find files in specific directories, you might just as well do file_exists(MAIN_DIR.'my/dir').
boolean$bByExpressionsIf set, $mRelativePath becomes not a fixed set of names but an array of regular expressions to evaluate against possible matches. This is slow when used on large directories. There are the following values which can be used as part of the expression: ${parent_name} and ${parent_name_camelized} which do exactly what you would expect. For convenience, any array item not starting with a slash is considered to be a regular file name. This means that a slash is the only accepted delimiter. In addition to regular strings and expressions, you can also pass null for a complete wildcard, true to match all files and false for a wildcard matching only directories. Any expression item packed into an array will be optional. An empty array (as an item of $mRelativePath) will match all items recursively (should not be used in frontend-production environments).
boolean$bFindAllIf set, all matching files will be returned even if they have the same relative path inside different instance prefixes. Note: when used in conjunction with $bByExpressions, the return value becomes an index-based array since there could be duplicate relative urls.
boolean$bReturnObjectsIf set, all returned paths become FileResource objects. This is much cheaper than calling new FileResource() on the returned value(s) because a) FileResource objects are used internally by findResource and b) the additional information maintained by FileResource was added when it was already known and does not have to be deducted.
Returns
mixed
static ResourceFinder::findResourceByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Alias for ResourceFinder::findResourcesByExpressions(). Exists for historical reasons.

static ResourceFinder::findResourceObject (   $mRelativePath,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bReturnObjects set.

static ResourceFinder::findResourceObjectByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Alias for ResourceFinder::findResourceObjectsByExpressions(). Exists for historical reasons.

static ResourceFinder::findResourceObjectsByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bByExpressions and $bReturnObjects set.

static ResourceFinder::findResourcesByExpressions (   $aExpressions,
  $iFlag = null 
)
static

Shorthand for ResourceFinder::findResource() with $bByExpressions set.

static ResourceFinder::parsePathArguments (   $sBaseDirname = null,
  $mPath = null,
  $sFileName = null 
)
static

Helper function for classes that are given a filename, base path and path name.

ResourceFinder::searchBaseFirst ( )
Deprecated:
use baseFirst()
ResourceFinder::searchBaseOnly ( )
Deprecated:
use baseOnly()
ResourceFinder::searchMainOnly ( )
Deprecated:
use mainOnly()
ResourceFinder::searchPluginsFirst ( )
Deprecated:
use pluginsFirst()
ResourceFinder::searchPluginsOnly ( )
Deprecated:
use pluginsOnly()
ResourceFinder::searchSiteFirst ( )
Deprecated:
use siteFirst()
ResourceFinder::searchSiteOnly ( )
Deprecated:
use siteOnly()

The documentation for this class was generated from the following file: