Base class implements the methods needed to use the eZ components.
Source for this file: /Base/src/base.php
Version: | //autogentag// |
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. |
MODE_DEVELOPMENT
= 1
|
Denotes the development mode |
MODE_PRODUCTION
= 0
|
Denotes the production mode |
protected static array(string=>string) |
$autoloadArray
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 static array(string=>string) |
$externalAutoloadArray
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 static string |
$packageDir
The full path to the autoload directory. |
protected static array(string=>array) |
$repositoryDirs
Stores info with additional paths where autoload files and classes for autoloading could be found. Each item of $repositoryDirs looks like array( autoloadFileDir, baseDir ). The array key is the prefix belonging to classes within that repository - if provided when calling addClassRepository(), or an autoincrement integer otherwise. |
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 string |
getInstallationPath(
)
Returns the base path of the eZ Components installation |
public static string |
getInstallMethod(
)
Returns the installation method |
public static array(string=>ezcBaseRepositoryDirectory) |
getRepositoryDirectories(
)
Return the list of directories that contain class repositories. |
public static int |
getRunMode(
)
Returns the current development mode. |
public static bool |
inDevMode(
)
Returns true when we are in development mode. |
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 void |
setPackageDir(
)
Figures out the base path of the eZ Components installation. |
public static void |
setRunMode(
$runMode
)
Sets the development mode to the one specified. |
public static void |
setWorkingDirectory(
$directory
)
Sets the current working directory to $directory. |
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:
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":
"your_autoload.php":
The directory structure for the external repository is then:
To use this repository with the autoload mechanism you have to use the following code:
Name | Type | Description |
---|---|---|
$basePath |
string | |
$autoloadDirPath |
string | |
$prefix |
string |
Type | Description |
---|---|
ezcBaseFileNotFoundException |
if $autoloadDirPath or $basePath do not exist. |
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).
Name | Type | Description |
---|---|---|
$className |
string | The name of the class that should be loaded. |
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.
Name | Type | Description |
---|---|---|
$component |
string | |
$type |
int | |
$value |
mixed |
Returns the base path of the eZ Components installation
This method returns the base path, including a trailing directory separator.
Returns the installation method
Possible return values are 'custom', 'devel', 'tarball' and 'pear'. Only 'tarball' and 'pear' are returned for user-installed versions.
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
Returns the current development mode.
Returns true when we are in development mode.
Loads, require(), the given file name from an external package.
Name | Type | Description |
---|---|---|
$file |
string | The name of the file that should be loaded. |
Loads, require(), the given file name. If we are in development mode, "/src/" is inserted into the path.
Name | Type | Description |
---|---|---|
$file |
string | The name of the file that should be loaded. |
Tries to load the autoload array and, if loaded correctly, includes the class.
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. |
Associates an option object with this static class.
Name | Type | Description |
---|---|---|
$options |
ezcBaseAutoloadOptions |
Figures out the base path of the eZ Components installation.
It stores the path that it finds in a static member variable. The path depends on the installation method of the eZ Components. The SVN version has a different path than the PEAR installed version.
Sets the development mode to the one specified.
Name | Type | Description |
---|---|---|
$runMode |
int |
Sets the current working directory to $directory.
Name | Type | Description |
---|---|---|
$directory |
string |