Class: I2CE FileSearch: Difference between revisions

From IHRIS Wiki
(Created page with 'This article desrcibes the class '''I2CE_FileSearch''' It is contained in the module I2CE in the package [https://launchpad.net/i2ce I2CE] The class is…')
 
(Redirected page to Class: I2CE FileSearch (4.1.12))
 
(27 intermediate revisions by one other user not shown)
Line 1: Line 1:
This article desrcibes the class '''I2CE_FileSearch'''
#REDIRECT [[Class: I2CE_FileSearch (4.1.12)]]
It is contained in the module [[iHRIS Module List#I2CE|I2CE]] in the package [https://launchpad.net/i2ce I2CE]
The class is defined in the file: [http://bazaar.launchpad.net/~intrahealth+informatics/i2ce/4.0.0-release/files/head:lib/I2CE_FileSearch.php lib/I2CE_FileSearch.php]
Class to handle file searching.
@package I2CE
==Variables==
===$found_locales===
The found locale(s)
 
.  One of: FALSE, a string, or an
array.  The former two in the case of a single serach, the
later in case of a $find_all search
*Type: protected [http://www.php.net/manual/en/language.pseudo-types.php mixed] $found_locales
 
===$preferred_locales===
.  Keys are
categories. Values are arrrays of string, the preferred
locales.
*Type: protected y $preferred_locales
 
===$ordered_paths===
*Type: protected $ordered_paths
 
===$absolut===
protected $var boolean $absolut -- wheter or not to make
relative paths absolut based on the directory of the
calling file
*Type: protected $absolut
 
===$search_hidden===
protected $var boolean $search_hidden.  Whether or not to
search hidden sub-directories
*Type: protected $search_hidden
 
===$search_cwd===
protected @var boolean $search_cwd. Whether or not to
seach the current working directory
*Type: protected $search_cwd
 
===$last_order===
protected @var array $last_order values are the order of
the last thing added to the category keys are the classes.
*Type: protected $last_order
 
===$checked_directories===
protected @var array $checked_directories array with keys
directories and values boolean It is true if the directory
has already been checked.  Used to avoid recursion,
*Type: protected $checked_directories
 
==Methods==
===__construct()===
Constructor for the FileSearch class
hidden sub-directories.  At the moment it does not have meaning
on non unix like platforms.
search the current working directory for the file.  If so, it
checks there first, before the other paths.
or not to make a relative path absolute when adding it.
*Signature: public function __construct($hidden,$current_working,$make_absolut)
Parameters:
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $hidden<br/>Defaults to false.  Whether or not to search
**Default Value: false
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $current_working<br/>Defaults to false. Whether or not to
**Default Value: false
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $make_absolut<br/>Defaults to false.  Whether
**Default Value: false
===_resolve()===
Function to search through a list of paths to find a specified file.
 
$regExp is a list of regular expression to match file names
on.
 
want to search, the values are the locale they are in
 
otherwise we return on the first match
 
onto the file name.
*Signature: protected function _resolve($regExps,$paths,$find_all,$dir_prefix,$reset_found_locales)
Parameters:
* [http://www.php.net/manual/en/language.types.array.php array] $regExps<br/>If desired_file is null then, then
* [http://www.php.net/manual/en/language.types.array.php array] $paths<br/>of string.  The keys are the paths we
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $find_all<br/>If true we find all files,
* [http://www.php.net/manual/en/language.types.string.php string] $dir_prefix<br/>any directory we want to prepend
**Default Value: ''
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $reset_found_locales<br/>Defualts to false
**Default Value: false
===absolut()===
Makes a relative file path or file url absolute relative
to the directory that the function was called in.
 
consider the calling file defaults to 0 which is
the file that is calling this.
*Signature: static public function absolut($path,$indx)
*Returns: [http://www.php.net/manual/en/language.types.string.php string] the absolute path or URL
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $path<br/>a path or URL
* [http://www.php.net/manual/en/language.types.integer.php int] $indx<br/>the index, from the top level, to
**Default Value: 0
===addPath()===
A path to search for a category of files.
A trailing '**' means that the paths should be added recursivley
Paths are automatically checked for localized version by the presence of a 'en_US' subdirectory.
specifically, if a path is added such as /my/path  and there is a subdir called /my/path/en_US  then
all subdirectories which are in the preffered locales (or $locales below) are added.
 
Examples:  /usr/share/fonts/      adds in this directory to the search paths
/usr/share/fonts/*  adds in all subdirectories
/usr/share/fonts/**  recusively adds in all subdirecties
/usr/share/fonts/truetype/ttf*  adds in all directories begining with ttf
The lower the number, the higher the priority.
If multiple paths share the same order, the order in which they are searched is not specfied
The are also special string values of $order (all are relative to the category specified):
<ul>
<li>'LAST' -- add at the last added order </li>
<li>'LOWEST' -- add so it has the lowest order thus far  </li>
<li>'HIGHEST' -- add so it has the highest order thus far </li>
<li>'EVEN_LOWER' -- add so it has lower order than anything thus far. This is the default behavior </li>
<li>'EVEN_HIGHER' -- add so it has higher  order than anything thus far </li>
</ul>
overide (but not change) the global behaviour of this instance.
It is the list of localized sub-directories to search for, if the given glob is a subdirectory.
*Signature: public function addPath($category,$path,$order,$absolut,$path_prefix,$locales)
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category<br/>the category of files.
* [http://www.php.net/manual/en/language.types.string.php string] $path<br/>the parh (or glob pattern for a path) to add.  There a a few modifications to the globbing...
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $order<br/>If it is a  number, then it indicates the order in which this path is  searched.
**Default Value: 'EVEN_LOWER'
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $absolut<br/>whether or not to try to make a relative path absolut.  It will
**Default Value: null
* [http://www.php.net/manual/en/language.types.string.php string] $path_prefix<br/>Defaults to null.  Any prefix to add to a relative class path (if we do make absolute)
**Default Value: null
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $locales<br/>null(default) , string or array of string.  Used to override the default locale settings when not the defaults of null.
**Default Value: null
===changeRelativeToAbsolut()===
Set whether or not to make relative paths absolute
*Signature: public function changeRelativeToAbsolut($absolut)
Parameters:
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $absolut
===convertUnixToWin()===
Convert a relative windows path with / to  one with \
returns $string
*Signature: static public function convertUnixToWin($path)
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $path
===findByRegularExpression()===
Finds all files with a given extension in the category
 
 
it is a regular expression to match file names on.  It may
be an array of strings, them we attempt a match against
each of the regular expressions specified by the strings.
 
otherwise we return on the first match
 
onto the file name.
*Signature: public function findByRegularExpression($category,$regExps,$find_all,$dir_prefix)
*Returns: [http://www.php.net/manual/en/language.types.array.php array] of string
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $regExps<br/>It may be a string, in which case
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $find_all<br/>If true we find all files,
* [http://www.php.net/manual/en/language.types.string.php string] $dir_prefix<br/>any directory we want to prepend
**Default Value: ''
===findWinShortFileName()===
On windows, convert a given file in a given directory to a 8.3 filename
*Signature: static protected function findWinShortFileName($file,$dir)
*Returns: [http://www.php.net/manual/en/language.types.string.php string]
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $file
*$dir
===findWinShortPathName()===
Attempt to convert a windows long path name to its 8.3 version
*Signature: static public function findWinShortPathName($file)
*Returns: @string
 
Example:  C:\Program Files\my_long_dir  becomes c:\program~1\my_lon~1
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $file<br/>The absoluate path to a file/directory
===getCategories()===
Get the categories specified
*Signature: public function getCategories()
*Returns: [http://www.php.net/manual/en/language.types.array.php array] of string
===getLastOrder()===
Get the last order set for the specified category.
*Signature: public function getLastOrder($category)
*Returns: [http://www.php.net/manual/en/language.types.integer.php int]
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
===getLocaleOfLastSearch()===
Get the locale(s) of the results of the last search.
*Signature: public function getLocaleOfLastSearch()
*Returns: mixed.  If the last search has $find_all = false then either false if no file was found or a string, the locale in which the
the results was found.  If the $find_all was true, then it is an array of string, the locales of the files found.
===getSearchPath()===
Gets the search path for the specified catgegory
*Signature: public function getSearchPath($category,$localized)
*Returns: array.  If not localized with keys integers, the
orders, and values an array of strings, the paths for that
order, if $localized is TRUE, and keys are paths values are
locales.
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $localized<br/>(FALSE)
**Default Value: FALSE
===isAbsolut()===
Checks to see if a path is absolute. All files identified
by a URI/L are considered to be absolute
*Signature: static public function isAbsolut($path)
*Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean]
Parameters:
*$path
===limitToSubdir()===
Remove sub-directories from a category
*Signature: public function limitToSubdir($category,$limit)
*Returns: [http://www.php.net/manual/en/language.types.array.php array]  List of directories
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.types.string.php string] $limit<br/>The subdirectory to limit to.
**Default Value: ""
===removePath()===
Remove a path in a category
 
relative path absolut.  It will overide (but not
change) the global behaviour of this instance.
to add to a relative class path (if we do make
absolute)
*Signature: public function removePath($category,$path,$absolut,$path_prefix)
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.types.string.php string] $path
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $absolut<br/>whether or not to try to make a
**Default Value: FALSE
* [http://www.php.net/manual/en/language.types.string.php string] $path_prefix<br/>Defaults to null.  Any prefix
**Default Value: NULL
===removePaths()===
Remove a list of paths from the category path list.
*Signature: public function removePaths($category,$path_list)
*Returns: [http://www.php.net/manual/en/language.types.array.php array]  List of directories
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.types.array.php array] $path_list<br/>The subdirectory to limit to.
===reset()===
*Signature: public function reset()
===resetFoundLocales()===
Reset the found locales
*Signature: protected function resetFoundLocales($multiple)
Parameters:
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $multiple<br/>If true setup so we are returning multiple resutls.  otherwise we return a single result
===resolve()===
Function to search through a list of paths to find a specified file.
 
$regExp is a list of regular expression to match file names
on.
 
want to search, the values are the locale they are in
 
otherwise we return on the first match
 
onto the file name.
*Signature: public function resolve($regExps,$paths,$find_all,$dir_prefix,$reset_found_locales)
Parameters:
* [http://www.php.net/manual/en/language.types.array.php array] $regExps<br/>If desired_file is null then, then
* [http://www.php.net/manual/en/language.types.array.php array] $paths<br/>of string.  The keys are the paths we
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $find_all<br/>If true we find all files,
* [http://www.php.net/manual/en/language.types.string.php string] $dir_prefix<br/>any directory we want to prepend
**Default Value: ''
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $reset_found_locales<br/>Defualts to false
**Default Value: false
===search()===
Find a file (or directory) of a certain category
*Signature: public function search($category,$filename,$find_all)
*Returns: mixed.  Returns either a string which is the path
and file name of the file we found, or null if we did not
find the file, or an array of file names if $find_all was
set to true
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category<br/>the category of the file
* [http://www.php.net/manual/en/language.types.string.php string] $filename<br/>the file name of the file we wish to find
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $find_all<br/>Defaults to false
**Default Value: FALSE
===searchCurrentWorkingDirectory()===
*Signature: public function searchCurrentWorkingDirectory($search)
Parameters:
*$search
===searchHiddenSubdirectories()===
*Signature: public function searchHiddenSubdirectories($search)
Parameters:
*$search
===searchPaths()===
Search paths for matches to the regular expression
*Signature: public function searchPaths($find_all,$regExps,$paths,$prefix)
*Returns: [http://www.php.net/manual/en/language.types.array.php array]  List of directories
Parameters:
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $find_all<br/>FALSE = return only the first hit.
* [http://www.php.net/manual/en/language.types.array.php array] $regExps<br/>Regular expressions to match
* [http://www.php.net/manual/en/language.types.array.php array] $paths<br/>Paths to look in
* [http://www.php.net/manual/en/language.types.string.php string] $prefix<br/>Directory prefix
===setPreferredLocales()===
Set the preferred locale(s) for a category. If not set,
defaults the locales default to I2CE::DEFAULT_LOCALE
*Signature: public function setPreferredLocales($category,$locales,$validate)
Parameters:
* [http://www.php.net/manual/en/language.types.string.php string] $category
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $locales<br/>string or array of string. The locales.
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $validate<br/>Defaults to true.
**Default Value: true
 
 
[[Category:Class Documentation]]

Latest revision as of 10:43, 18 August 2015