Path

ez components / documentation / api reference / 1.1.1 / base


eZ Components 1.1.1

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.
libraryMode = "devel" Indirectly it determines the path where the autoloads are stored.

Member Variables

protected array $autoloadArray = array()
protected array $externalAutoloadArray = array()
protected string $packageDir
protected array(string->array) $repositoryDirs = array()

Method Summary

public static void addClassRepository( $basePath, [$autoloadDirPath = 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=>array) 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 )
Tries to load the autoload array and, if loaded correctly, includes the 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).

Methods

addClassRepository

void addClassRepository( string $basePath, [string $autoloadDirPath = 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
$autoloadDirPath string  
$basePath 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  

getRepositoryDirectories

array(string=>array) 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 => array( $type, autoloadDirectory ) The $type is either "ezc" for the eZ components directory or "external" for external repositories.

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

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

Last updated: Thu, 01 Nov 2007