Path

ez components / documentation / api reference / trunk / base


eZ Components trunk

Base: ezcBase

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

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.
MODE_DEVELOPMENT = 1 Denotes the development mode
MODE_PRODUCTION = 0 Denotes the production mode

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 = null
The full path to the autoload directory.
protected array(string=>array) $repositoryDirs = array()
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.

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 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.

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

ClassDescription
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  

getInstallationPath

string getInstallationPath( )
Returns the base path of the eZ Components installation
This method returns the base path, including a trailing directory separator.

getInstallMethod

string getInstallMethod( )
Returns the installation method
Possible return values are 'custom', 'devel', 'tarball' and 'pear'. Only 'tarball' and 'pear' are returned for user-installed versions.

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

getRunMode

int getRunMode( )
Returns the current development mode.

inDevMode

bool inDevMode( )
Returns true when we are in development mode.

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

void setPackageDir( )
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.

setRunMode

void setRunMode( int $runMode )
Sets the development mode to the one specified.

Parameters

Name Type Description
$runMode int  

setWorkingDirectory

void setWorkingDirectory( string $directory )
Sets the current working directory to $directory.

Parameters

Name Type Description
$directory string  

Last updated: Mon, 21 Dec 2009