Base: ezcBase
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcBase
|
Base class implements the methods needed to use the eZ components. [
source]
Constants
DEP_PHP_EXTENSION
= "extension"
|
Used for dependency checking, to check for a PHP extension. |
DEP_PHP_VERSION
= "version"
|
Used for dependency checking, to check for a PHP version. |
Member Variables
|
protected array(string=>string) |
$autoloadArray
= array()
This variable stores all the elements from the autoload arrays. When a new autoload file is loaded, their files are added to this array. |
|
protected array(string=>string) |
$externalAutoloadArray
= array()
This variable stores all the elements from the autoload arrays for external repositories. When a new autoload file is loaded, their files are added to this array. |
|
protected string |
$packageDir
The full path to the autoload directory. |
|
protected array(string=>array) |
$repositoryDirs
= array()
Stores info with additional paths where autoload files and classes for |
Method Summary
|
public static void |
addClassRepository(
$basePath, [$autoloadDirPath = null], [$prefix = null] )
Adds an additional class repository. |
|
public static bool |
autoload(
$className )
Tries to autoload the given className. If the className could be found this method returns true, otherwise false. |
|
public static void |
checkDependency(
$component, $type, $value )
Checks for dependencies on PHP versions or extensions |
|
public static array(string=>ezcBaseRepositoryDirectory) |
getRepositoryDirectories(
)
Return the list of directories that contain class repositories. |
|
protected static void |
loadExternalFile(
$file )
Loads, require(), the given file name from an external package. |
|
protected static void |
loadFile(
$file )
Loads, require(), the given file name. If we are in development mode, "/src/" is inserted into the path. |
|
protected static bool |
requireFile(
$fileName, $className, $prefix )
Tries to load the autoload array and, if loaded correctly, includes the class. |
|
public static void |
setOptions(
$options )
Associates an option object with this static class. |
|
protected static string |
setPackageDir(
)
Returns the path to the autoload directory. The path depends on the installation of the ezComponents. The SVN version has different paths than the PEAR installed version. (For now). |
|
public static void |
setWorkingDirectory(
$directory )
Sets the current working directory to $directory. |
Methods
addClassRepository
void addClassRepository(
string
$basePath, [string
$autoloadDirPath = null], [string
$prefix = null] )
Adds an additional class repository.
Used for adding class repositoryies outside the eZ components to be loaded by the autoload system.
This function takes two arguments: $basePath is the base path for the whole class repository and $autoloadDirPath the path where autoload files for this repository are found. The paths in the autoload files are relative to the package directory as specified by the $basePath argument. I.e. class definition file will be searched at location $basePath + path to the class definition file as stored in the autoload file.
addClassRepository() should be called somewhere in code before external classes are used.
Example: Take the following facts:
- there is a class repository stored in the directory "./repos"
- autoload files for that repository are stored in "./repos/autoloads"
- there are two components in this repository: "Me" and "You"
- the "Me" component has the classes "erMyClass1" and "erMyClass2"
- the "You" component has the classes "erYourClass1" and "erYourClass2"
In this case you would need to create the following files in "./repos/autoloads". Please note that the part before _autoload.php in the filename is the first part of the classname, not considering the all lower-case letter prefix.
"my_autoload.php":
1. <?php
2. return array (
3. 'erMyClass1' => 'Me/myclass1.php',
4. 'erMyClass2' => 'Me/myclass2.php',
5. );
6. ?>
"your_autoload.php":
1. <?php
2. return array (
3. 'erYourClass1' => 'You/yourclass1.php',
4. 'erYourClass2' => 'You/yourclass2.php',
5. );
6. ?>
The directory structure for the external repository is then:
1. ./repos/autoloads/my_autoload.php
2. ./repos/autoloads/you_autoload.php
3. ./repos/Me/myclass1.php
4. ./repos/Me/myclass2.php
5. ./repos/You/yourclass1.php
6. ./repos/You/yourclass2.php
To use this repository with the autoload mechanism you have to use the following code:
1. <?php
2. ezcBase::addClassRepository( './repos', './repos/autoloads' );
3. $myVar = new erMyClass2();
4. ?>
Parameters
| Name |
Type |
Description |
$basePath |
string |
|
$autoloadDirPath |
string |
|
$prefix |
string |
|
Throws
| Class | Description |
ezcBaseFileNotFoundException |
if $autoloadDirPath or $basePath do not exist. |
autoload
bool autoload(
string
$className )
Tries to autoload the given className. If the className could be found this method returns true, otherwise false.
This class caches the requested class names (including the ones who failed to load).
Parameters
| Name |
Type |
Description |
$className |
string |
The name of the class that should be loaded. |
checkDependency
void checkDependency(
string
$component, int
$type, mixed
$value )
Checks for dependencies on PHP versions or extensions
The function as called by the $component component checks for the $type dependency. The dependency $type is compared against the $value. The function aborts the script if the dependency is not matched.
Parameters
| Name |
Type |
Description |
$component |
string |
|
$type |
int |
|
$value |
mixed |
|
getRepositoryDirectories
array(string=>ezcBaseRepositoryDirectory) getRepositoryDirectories(
)
Return the list of directories that contain class repositories.
The path to the eZ components directory is always included in the result array. Each element in the returned array has the format of: packageDirectory => ezcBaseRepositoryDirectory
loadExternalFile
void loadExternalFile(
string
$file )
Loads, require(), the given file name from an external package.
Parameters
| Name |
Type |
Description |
$file |
string |
The name of the file that should be loaded. |
loadFile
void loadFile(
string
$file )
Loads, require(), the given file name. If we are in development mode, "/src/" is inserted into the path.
Parameters
| Name |
Type |
Description |
$file |
string |
The name of the file that should be loaded. |
requireFile
bool requireFile(
string
$fileName, string
$className, string
$prefix )
Tries to load the autoload array and, if loaded correctly, includes the class.
Parameters
| Name |
Type |
Description |
$fileName |
string |
Name of the autoload file. |
$className |
string |
Name of the class that should be autoloaded. |
$prefix |
string |
The prefix of the class repository. |
setOptions
void setOptions(
$options )
Associates an option object with this static class.
Parameters
| Name |
Type |
Description |
$options |
ezcBaseAutoloadOptions |
|
setPackageDir
string setPackageDir(
)
Returns the path to the autoload directory. The path depends on the installation of the ezComponents. The SVN version has different paths than the PEAR installed version. (For now).
setWorkingDirectory
void setWorkingDirectory(
string
$directory )
Sets the current working directory to $directory.
Parameters
| Name |
Type |
Description |
$directory |
string |
|
Last updated: Mon, 17 Dec 2007