First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,16 @@
CREDITS
=======
eZ Components team
------------------
- Sergey Alexeev
- Sebastian Bergmann
- Jan Borsodi
- Raymond Bosman
- Frederik Holljen
- Kore Nordmann
- Derick Rethans
- Vadym Savchuk
- Tobias Schlitt
- Alexandru Stanoi

View file

@ -0,0 +1,326 @@
1.7 - Monday 29 June 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes
1.7rc1 - Monday 22 June 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an issue with the PEAR reader as sometimes the returned structure is
different.
1.7beta1 - Monday 08 June 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Made sure that we (try) to load the PEAR Registry class so that PEAR doesn't
have to be in autoload.
1.7alpha1 - Tuesday 26 May 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added 'SunOS' to the list of Unices to make finding binaries work on Solaris
as well.
- Implemented issue #13718: Include metadata about installed components that
can be queried to figure out required PHP versions, dependencies and
component versions.
1.6.1 - Monday 09 February 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #14402: Auto detection of external programs (binaries) does not
throw warnings anymore.
1.6 - Monday 05 January 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added a workaround for a segfault in call_user_func() in PHP 5.2.x.
1.6rc1 - Monday 15 December 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Implemented issue #12542: Refactored the ezcBaseFile::findRecursive() method
into the ezcBase::walkRecursive() method so that you can setup your own
callbacks to "do things". The findRecursive() method is now implemented
through this.
- Fixed issue #14091: Incorrect documentation for
ezcBaseConfigurationInitializer.
1.6beta1 - Monday 01 December 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the exception class ezcBaseFunctionalityNotSupportedException.
1.5.2 - Monday 06 October 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an issue in ezcBaseFile::removeRecursive, where the parent directory
could not be written to. We now make sure nothing is deleted until we're sure
everything can be deleted.
1.5.1 - Monday 04 August 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #13370: Infinitive loop in ezcBaseFile::calculateRelativePath().
- Implemented issue #11865: Different development modes.
1.5 - Monday 16 June 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.5rc1 - Tuesday 10 June 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes
1.5beta1 - Tuesday 27 May 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBasePersistable interface that can be used to ensure that the
object implementing this interface can be used with PersistentObject and
Search.
1.5alpha2 - Tuesday 13 May 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed a bug in ezcBaseFile::findRecursive that prevented you from passing an
empty array to collect statistics.
- Changed ezcBase::getInstallationPath() so that it always returns a trailing
directory separator.
1.5alpha1 - Monday 07 April 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Implemented issue #8529: Added a by-reference argument to
ezcBaseFile::findRecursive that returns statistsics (count and total size)
of all files that are returned by this function.
- Implemented issue #11506: Added the static method
ezcBase::getInstallationPath().
- Implemented issue #12694: replace reflection test for class type with spl
function.
1.4.1 - Monday 14 January 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #11448: ezc_bootsrap.php uses relative paths.
- Fixed issue #12316: Numbers in own component prefix not possible.
- Fixed issue #12329: ezcBaseFeatures::findExecutableInPath's return value
does not include the extension to the executable at the end on Windows.
- Added an optional argument to the ezcBaseValueException constructor to allow
the exception to be used for non-property/setting type violations as well.
1.4 - Monday 17 December 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.4rc1 - Wednesday 05 December 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.4beta1 - Wednesday 28 November 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.4alpha2 - Monday 29 October 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBaseFile::copyRecursive() method, to recursively copy files or
directories
- Fixed issue #11540: Problems with ezcFile::findRecursive and
ezcFile::calculateRelativePath on systems where DIRECTORY_SEPERATOR is not
//.
1.4alpha1 - Tuesday 18 September 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBaseFile class, which was moved from the File component.
- Added the ezcBaseFile::isAbsolutePath() method, which returns whether a path
is absolute or relative.
1.3.1 - Monday 30 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #11057: The ezcBaseConfigurationInitializer inteface is not
enforced for callback classes.
1.3 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Documentation fixes and updates.
1.3rc1 - Monday 25 June 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Documentation fixes and updates.
1.3beta2 - Thursday 31 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #10704: Autoload fails on class not found. The exception is now
off by default, but can be turned on through the "debug" property of the
ezcBaseAutoloadOptions class. This option class can be set with
ezcBase::setOptions().
1.3beta1 - Monday 07 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #8433: ezcBase::getRepositoryDirectories() problems.
- Fixed issue #10583: ezcBaseOptions misses __isset().
- Fixed issue #10666: ezc_bootstrap.php fails on Windows.
- Implemented issue #9569: Add "autoload.php" as 3rd fallback autoload file to
search for.
- Implemented issue #9988: Implement component preloading for better opcode
cache performance.
- Added exception class ezcBaseExtensionNotFoundException to be thrown when an
extension is required but is not found.
- Changed the ezcBaseInit::fetchConfig() method to return the value that was
returned from the callback function.
1.2 - Monday 18 December 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #9658: Checking if $_ENV['PATH'] is set before using it in
ezcBaseFeatures.
- Fixed issue #9780: ezcBaseFeatures throws notice about non-existing array
key "PATH".
- Fixed issue #9819: Let all components deal with the ezcBaseAutoloadException
properly.
- Fixed the exception name for 'ezcBaseDoubleClassRepositoryPrefix' - it was
missing "Exception".
- Implemented issue #9811: If a file for a class can not be found through
autoloading, we now throw the ezcBaseAutoloadException which makes debugging
easier.
- Added the static method ezcBaseFeatures::findExecutableInPath() that searches the
path for the given executable.
- Added the static method ezcBaseFeatures::os() that returns a sanitized
version of the current OS' name.
1.2beta2 - Monday 20 November 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #8507: Two autoload directories with the same basepath don't
work.
- Fixed issue #9390: Classes in external repositories that map to the same
autoload filename of an internal component were added to the external
autoload cache array as well.
1.2beta1 - Tuesday 24 October 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBaseFeatures class to check whether the current PHP
installation and environment provides features that can be used in the
components.
- Added the ezcBaseInit class that assists you by setting up on-demand
configurations for objects (most notable useful for singleton classes).
- Implemented FR #8508: Display search paths for the autoload files in case of
a missing class.
- Implemented FR #8753: Added the 'Base/ezc_bootstrap.php' file which sets up
the autoload environment for you to facilitate an easier way of starting to
use the eZ components.
1.1.1 - Monday 28 August 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBaseStruct class from which all structs in all components
should inherit from.
1.1 - Friday 09 June 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed bug #8434: ezcBase autoload system does not handle classes without a
prefix.
- Fixed bug #8435: ezcBase::addClassRepository assumes the ezc way of
structuring files. From now on the path specifying the autoload directory is
*not* relative to the repository directory anymore.
1.1rc1 - Monday 29 May 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed bug #8252: Autoloading for external repositories only works for the
first such class.
1.1beta2 - Tuesday 09 May 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added support for external class repositories. You can now add a class
repository to the autoload mechanism by using the addClassRepository()
method.
- Added a method to return all configured class repositories.
- Added the REMOVE constant to the ezcBaseFileException.
- Added the ezcBaseOptions class that serves as base class for all option
classes in the components.
1.1beta1 - Wednesday 19 April 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Changed the way how files are included when the SVN checkout of the eZ
components was used. This does not affect normal use of the components.
- Fixed class descriptions for the exceptions in the documentation.
1.0 - Monday 30 January 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added HTML escaping of exception messages so that they show up correctly in
a browser. The original message is stored in the originalMessage property
in the exception object.
1.0rc1 - Monday 16 January 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBaseException that all exceptions in the components library
should descent from.
- Added generic File and IO exceptions that all other components can use
instead of having to reimplement them.
- Added ezcBase::checkDependency() method that allows components to specify
dependencies on either a PHP version or a PHP extension.
1.0beta2 - Wednesday 21 December 2005
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added the ezcBasePropertyException that can be used by components to signal
that an property was assigned a value which it does not allows.
1.0beta1 - Tuesday 22 November 2005
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Initial release of this package.

View file

@ -0,0 +1,2 @@
The Base package provides the basic infrastructure that all packages rely on.
Therefore every component relies on this package.

View file

@ -0,0 +1,44 @@
{
"authors": [
{
"name": "Sergey Alexeev"
},
{
"name": "Sebastian Bergmann"
},
{
"name": "Jan Borsodi"
},
{
"name": "Raymond Bosman"
},
{
"name": "Frederik Holljen"
},
{
"name": "Kore Nordmann"
},
{
"name": "Derick Rethans"
},
{
"name": "Vadym Savchuk"
},
{
"name": "Tobias Schlitt"
},
{
"name": "Alexandru Stanoi"
}
],
"autoload": {
"classmap": [
"src"
]
},
"description": "The Base package provides the basic infrastructure that all packages rely on. Therefore every component relies on this package.",
"homepage": "https://github.com/zetacomponents",
"license": "apache2",
"name": "zetacomponents/base",
"type": "library"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 KiB

View file

@ -0,0 +1,9 @@
Base
====
Purpose
-------
This is the base package of the eZ publish components, offering the basic
support that all Components need. In the first version this will be the
autoload support.

View file

@ -0,0 +1,23 @@
Review Alexandru 2008-05-08
===========================
[X] Regarding feature request #8529 (a du -s implementation). The documentation
for ezcBaseFile::findRecursive() says that you can supply an empty array
as the 4th argument to get the statistics.
If I pass for example $stats which I initialized with array() before, then
I get notices: "Undefined index: count in /home/as/dev/ezcomponents/trunk/Base/src/file.php
on line 139", and the same notice for index "size".
Also the documentation does not mention that you need to pass a variable and not
a value - if I pass array() as the 4th argument I get the error "Cannot pass
parameter 4 by reference"
If I pass $stats which I initialize with null, false or empty string before,
then the function works.
Also all the file recursive tests fail on Windows (slash issues mostly).
[X] Regarding feature request #11506 (method ezcBase::getInstallationPath()). On
Linux it returns the path without any slash at the end, but on Windows (Vista)
it adds a Windows slash at the end.

View file

@ -0,0 +1,656 @@
<?php
/**
* File containing the ezcBase class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Base class implements the methods needed to use the eZ components.
*
* @package Base
* @version //autogentag//
* @mainclass
*/
class ezcBase
{
/**
* Used for dependency checking, to check for a PHP extension.
*/
const DEP_PHP_EXTENSION = "extension";
/**
* Used for dependency checking, to check for a PHP version.
*/
const DEP_PHP_VERSION = "version";
/**
* Denotes the production mode
*/
const MODE_PRODUCTION = 0;
/**
* Denotes the development mode
*/
const MODE_DEVELOPMENT = 1;
/**
* Indirectly it determines the path where the autoloads are stored.
*
* @var string
*/
private static $libraryMode = "devel";
/**
* Contains the current working directory, which is used when the
* $libraryMode is set to "custom".
*
* @var string
*/
private static $currentWorkingDirectory = null;
/**
* The full path to the autoload directory.
*
* @var string
*/
protected static $packageDir = null;
/**
* Contains which development mode is used. It's "development" by default,
* because of backwards compatibility reasons.
*/
private static $runMode = self::MODE_DEVELOPMENT;
/**
* 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.
*
* @var array(string=>array)
*/
protected static $repositoryDirs = 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.
*
* @var array(string=>string)
*/
protected static $autoloadArray = 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.
*
* @var array(string=>string)
*/
protected static $externalAutoloadArray = array();
/**
* Options for the ezcBase class.
*
* @var ezcBaseOptions
*/
static private $options;
/**
* Associates an option object with this static class.
*
* @param ezcBaseAutoloadOptions $options
*/
static public function setOptions( ezcBaseAutoloadOptions $options )
{
self::$options = $options;
}
/**
* 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).
*
* @param string $className The name of the class that should be loaded.
*
* @return bool
*/
public static function autoload( $className )
{
ezcBase::setPackageDir();
// Check whether the classname is already in the cached autoloadArray.
if ( array_key_exists( $className, ezcBase::$autoloadArray ) )
{
// Is it registered as 'unloadable'?
if ( ezcBase::$autoloadArray[$className] == false )
{
return false;
}
ezcBase::loadFile( ezcBase::$autoloadArray[$className] );
return true;
}
// Check whether the classname is already in the cached autoloadArray
// for external repositories.
if ( array_key_exists( $className, ezcBase::$externalAutoloadArray ) )
{
// Is it registered as 'unloadable'?
if ( ezcBase::$externalAutoloadArray[$className] == false )
{
return false;
}
ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] );
return true;
}
// Not cached, so load the autoload from the package.
// Matches the first and optionally the second 'word' from the classname.
$fileNames = array();
if ( preg_match( "/^([a-z0-9]*)([A-Z][a-z0-9]*)([A-Z][a-z0-9]*)?/", $className, $matches ) !== false )
{
$autoloadFile = "";
// Try to match with both names, if available.
switch ( sizeof( $matches ) )
{
case 4:
// check for x_y_autoload.php
$autoloadFile = strtolower( "{$matches[2]}_{$matches[3]}_autoload.php" );
$fileNames[] = $autoloadFile;
if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) )
{
return true;
}
// break intentionally missing.
case 3:
// check for x_autoload.php
$autoloadFile = strtolower( "{$matches[2]}_autoload.php" );
$fileNames[] = $autoloadFile;
if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) )
{
return true;
}
// check for autoload.php
$autoloadFile = 'autoload.php';
$fileNames[] = $autoloadFile;
if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) )
{
return true;
}
break;
}
// Maybe there is another autoload available.
// Register this classname as false.
ezcBase::$autoloadArray[$className] = false;
}
$path = ezcBase::$packageDir . 'autoload/';
$realPath = realpath( $path );
if ( $realPath == '' )
{
// Can not be tested, because if this happens, then the autoload
// environment has not been set-up correctly.
trigger_error( "Couldn't find autoload directory '$path'", E_USER_ERROR );
}
$dirs = self::getRepositoryDirectories();
if ( ezcBase::$options && ezcBase::$options->debug )
{
throw new ezcBaseAutoloadException( $className, $fileNames, $dirs );
}
return false;
}
/**
* Sets the current working directory to $directory.
*
* @param string $directory
*/
public static function setWorkingDirectory( $directory )
{
self::$libraryMode = 'custom';
self::$currentWorkingDirectory = $directory;
}
/**
* 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.
*/
protected static function setPackageDir()
{
if ( ezcBase::$packageDir !== null )
{
return;
}
// Get the path to the components.
$baseDir = dirname( __FILE__ );
switch ( ezcBase::$libraryMode )
{
case "custom":
ezcBase::$packageDir = self::$currentWorkingDirectory . '/';
break;
case "devel":
case "tarball":
ezcBase::$packageDir = $baseDir. "/../../";
break;
case "pear";
ezcBase::$packageDir = $baseDir. "/../";
break;
}
}
/**
* Tries to load the autoload array and, if loaded correctly, includes the class.
*
* @param string $fileName Name of the autoload file.
* @param string $className Name of the class that should be autoloaded.
* @param string $prefix The prefix of the class repository.
*
* @return bool True is returned when the file is correctly loaded.
* Otherwise false is returned.
*/
protected static function requireFile( $fileName, $className, $prefix )
{
$autoloadDir = ezcBase::$packageDir . "autoload/";
// We need the full path to the fileName. The method file_exists() doesn't
// automatically check the (php.ini) library paths. Therefore:
// file_exists( "ezc/autoload/$fileName" ) doesn't work.
if ( $prefix === 'ezc' && file_exists( "$autoloadDir$fileName" ) )
{
$array = require( "$autoloadDir$fileName" );
if ( is_array( $array) && array_key_exists( $className, $array ) )
{
// Add the array to the cache, and include the requested file.
ezcBase::$autoloadArray = array_merge( ezcBase::$autoloadArray, $array );
if ( ezcBase::$options !== null && ezcBase::$options->preload && !preg_match( '/Exception$/', $className ) )
{
foreach ( $array as $loadClassName => $file )
{
if ( $loadClassName !== 'ezcBase' && !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false ) && !preg_match( '/Exception$/', $loadClassName ) /*&& !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false )*/ )
{
ezcBase::loadFile( ezcBase::$autoloadArray[$loadClassName] );
}
}
}
else
{
ezcBase::loadFile( ezcBase::$autoloadArray[$className] );
}
return true;
}
}
// It is not in components autoload/ dir.
// try to search in additional dirs.
foreach ( ezcBase::$repositoryDirs as $repositoryPrefix => $extraDir )
{
if ( gettype( $repositoryPrefix ) === 'string' && $repositoryPrefix !== $prefix )
{
continue;
}
if ( file_exists( $extraDir['autoloadDirPath'] . '/' . $fileName ) )
{
$array = array();
$originalArray = require( $extraDir['autoloadDirPath'] . '/' . $fileName );
// Building paths.
// Resulting path to class definition file consists of:
// path to extra directory with autoload file +
// basePath provided for current extra directory +
// path to class definition file stored in autoload file.
foreach ( $originalArray as $class => $classPath )
{
$array[$class] = $extraDir['basePath'] . '/' . $classPath;
}
if ( is_array( $array ) && array_key_exists( $className, $array ) )
{
// Add the array to the cache, and include the requested file.
ezcBase::$externalAutoloadArray = array_merge( ezcBase::$externalAutoloadArray, $array );
ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] );
return true;
}
}
}
// Nothing found :-(.
return false;
}
/**
* Loads, require(), the given file name. If we are in development mode,
* "/src/" is inserted into the path.
*
* @param string $file The name of the file that should be loaded.
*/
protected static function loadFile( $file )
{
switch ( ezcBase::$libraryMode )
{
case "devel":
case "tarball":
list( $first, $second ) = explode( '/', $file, 2 );
$file = $first . "/src/" . $second;
break;
case "custom":
list( $first, $second ) = explode( '/', $file, 2 );
// Add the "src/" after the package name.
if ( $first == 'Base' || $first == 'UnitTest' )
{
list( $first, $second ) = explode( '/', $file, 2 );
$file = $first . "/src/" . $second;
}
else
{
list( $first, $second, $third ) = explode( '/', $file, 3 );
$file = $first . '/' . $second . "/src/" . $third;
}
break;
case "pear":
/* do nothing, it's already correct */
break;
}
if ( file_exists( ezcBase::$packageDir . $file ) )
{
require( ezcBase::$packageDir . $file );
}
else
{
// Can not be tested, because if this happens, then one of the
// components has a broken autoload file.
throw new ezcBaseFileNotFoundException( ezcBase::$packageDir.$file );
}
}
/**
* Loads, require(), the given file name from an external package.
*
* @param string $file The name of the file that should be loaded.
*/
protected static function loadExternalFile( $file )
{
if ( file_exists( $file ) )
{
require( $file );
}
else
{
throw new ezcBaseFileNotFoundException( $file );
}
}
/**
* 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.
*
* @param string $component
* @param int $type
* @param mixed $value
*/
public static function checkDependency( $component, $type, $value )
{
switch ( $type )
{
case self::DEP_PHP_EXTENSION:
if ( extension_loaded( $value ) )
{
return;
}
else
{
// Can not be tested as it would abort the PHP script.
die( "\nThe {$component} component depends on the default PHP extension '{$value}', which is not loaded.\n" );
}
break;
case self::DEP_PHP_VERSION:
$phpVersion = phpversion();
if ( version_compare( $phpVersion, $value, '>=' ) )
{
return;
}
else
{
// Can not be tested as it would abort the PHP script.
die( "\nThe {$component} component depends on the PHP version '{$value}', but the current version is '{$phpVersion}'.\n" );
}
break;
}
}
/**
* 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
*
* @return array(string=>ezcBaseRepositoryDirectory)
*/
public static function getRepositoryDirectories()
{
$autoloadDirs = array();
ezcBase::setPackageDir();
$repositoryDir = self::$currentWorkingDirectory ? self::$currentWorkingDirectory : ( realpath( dirname( __FILE__ ) . '/../../' ) );
$autoloadDirs['ezc'] = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_INTERNAL, $repositoryDir, $repositoryDir . "/autoload" );
foreach ( ezcBase::$repositoryDirs as $extraDirKey => $extraDirArray )
{
$repositoryDirectory = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_EXTERNAL, realpath( $extraDirArray['basePath'] ), realpath( $extraDirArray['autoloadDirPath'] ) );
$autoloadDirs[$extraDirKey] = $repositoryDirectory;
}
return $autoloadDirs;
}
/**
* 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:
* <ul>
* <li>there is a class repository stored in the directory "./repos"</li>
* <li>autoload files for that repository are stored in "./repos/autoloads"</li>
* <li>there are two components in this repository: "Me" and "You"</li>
* <li>the "Me" component has the classes "erMyClass1" and "erMyClass2"</li>
* <li>the "You" component has the classes "erYourClass1" and "erYourClass2"</li>
* </ul>
*
* 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 <b>classname</b>, not considering
* the all lower-case letter prefix.
*
* "my_autoload.php":
* <code>
* <?php
* return array (
* 'erMyClass1' => 'Me/myclass1.php',
* 'erMyClass2' => 'Me/myclass2.php',
* );
* ?>
* </code>
*
* "your_autoload.php":
* <code>
* <?php
* return array (
* 'erYourClass1' => 'You/yourclass1.php',
* 'erYourClass2' => 'You/yourclass2.php',
* );
* ?>
* </code>
*
* The directory structure for the external repository is then:
* <code>
* ./repos/autoloads/my_autoload.php
* ./repos/autoloads/you_autoload.php
* ./repos/Me/myclass1.php
* ./repos/Me/myclass2.php
* ./repos/You/yourclass1.php
* ./repos/You/yourclass2.php
* </code>
*
* To use this repository with the autoload mechanism you have to use the
* following code:
* <code>
* <?php
* ezcBase::addClassRepository( './repos', './repos/autoloads' );
* $myVar = new erMyClass2();
* ?>
* </code>
*
* @throws ezcBaseFileNotFoundException if $autoloadDirPath or $basePath do not exist.
* @param string $basePath
* @param string $autoloadDirPath
* @param string $prefix
*/
public static function addClassRepository( $basePath, $autoloadDirPath = null, $prefix = null )
{
// check if base path exists
if ( !is_dir( $basePath ) )
{
throw new ezcBaseFileNotFoundException( $basePath, 'base directory' );
}
// calculate autoload path if it wasn't given
if ( is_null( $autoloadDirPath ) )
{
$autoloadDirPath = $basePath . '/autoload';
}
// check if autoload dir exists
if ( !is_dir( $autoloadDirPath ) )
{
throw new ezcBaseFileNotFoundException( $autoloadDirPath, 'autoload directory' );
}
// add info to $repositoryDirs
if ( $prefix === null )
{
$array = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath );
// add info to the list of extra dirs
ezcBase::$repositoryDirs[] = $array;
}
else
{
if ( array_key_exists( $prefix, ezcBase::$repositoryDirs ) )
{
throw new ezcBaseDoubleClassRepositoryPrefixException( $prefix, $basePath, $autoloadDirPath );
}
// add info to the list of extra dirs, and use the prefix to identify the new repository.
ezcBase::$repositoryDirs[$prefix] = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath );
}
}
/**
* Returns the base path of the eZ Components installation
*
* This method returns the base path, including a trailing directory
* separator.
*
* @return string
*/
public static function getInstallationPath()
{
self::setPackageDir();
$path = realpath( self::$packageDir );
if ( substr( $path, -1 ) !== DIRECTORY_SEPARATOR )
{
$path .= DIRECTORY_SEPARATOR;
}
return $path;
}
/**
* Sets the development mode to the one specified.
*
* @param int $runMode
*/
public static function setRunMode( $runMode )
{
if ( !in_array( $runMode, array( ezcBase::MODE_PRODUCTION, ezcBase::MODE_DEVELOPMENT ) ) )
{
throw new ezcBaseValueException( 'runMode', $runMode, 'ezcBase::MODE_PRODUCTION or ezcBase::MODE_DEVELOPMENT' );
}
self::$runMode = $runMode;
}
/**
* Returns the current development mode.
*
* @return int
*/
public static function getRunMode()
{
return self::$runMode;
}
/**
* Returns true when we are in development mode.
*
* @return bool
*/
public static function inDevMode()
{
return self::$runMode == ezcBase::MODE_DEVELOPMENT;
}
/**
* Returns the installation method
*
* Possible return values are 'custom', 'devel', 'tarball' and 'pear'. Only
* 'tarball' and 'pear' are returned for user-installed versions.
*
* @return string
*/
public static function getInstallMethod()
{
return self::$libraryMode;
}
}
?>

View file

@ -0,0 +1,46 @@
<?php
/**
* Autoloader definition for the Base component.
*
* @copyright Copyright (C) 2005-2009 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version //autogentag//
* @filesource
* @package Base
*/
return array(
'ezcBaseException' => 'Base/exceptions/exception.php',
'ezcBaseFileException' => 'Base/exceptions/file_exception.php',
'ezcBaseAutoloadException' => 'Base/exceptions/autoload.php',
'ezcBaseDoubleClassRepositoryPrefixException' => 'Base/exceptions/double_class_repository_prefix.php',
'ezcBaseExtensionNotFoundException' => 'Base/exceptions/extension_not_found.php',
'ezcBaseFileIoException' => 'Base/exceptions/file_io.php',
'ezcBaseFileNotFoundException' => 'Base/exceptions/file_not_found.php',
'ezcBaseFilePermissionException' => 'Base/exceptions/file_permission.php',
'ezcBaseFunctionalityNotSupportedException' => 'Base/exceptions/functionality_not_supported.php',
'ezcBaseInitCallbackConfiguredException' => 'Base/exceptions/init_callback_configured.php',
'ezcBaseInitInvalidCallbackClassException' => 'Base/exceptions/invalid_callback_class.php',
'ezcBaseInvalidParentClassException' => 'Base/exceptions/invalid_parent_class.php',
'ezcBasePropertyNotFoundException' => 'Base/exceptions/property_not_found.php',
'ezcBasePropertyPermissionException' => 'Base/exceptions/property_permission.php',
'ezcBaseSettingNotFoundException' => 'Base/exceptions/setting_not_found.php',
'ezcBaseSettingValueException' => 'Base/exceptions/setting_value.php',
'ezcBaseValueException' => 'Base/exceptions/value.php',
'ezcBaseWhateverException' => 'Base/exceptions/whatever.php',
'ezcBaseOptions' => 'Base/options.php',
'ezcBaseStruct' => 'Base/struct.php',
'ezcBase' => 'Base/base.php',
'ezcBaseAutoloadOptions' => 'Base/options/autoload.php',
'ezcBaseConfigurationInitializer' => 'Base/interfaces/configuration_initializer.php',
'ezcBaseFeatures' => 'Base/features.php',
'ezcBaseFile' => 'Base/file.php',
'ezcBaseFileFindContext' => 'Base/structs/file_find_context.php',
'ezcBaseInit' => 'Base/init.php',
'ezcBaseMetaData' => 'Base/metadata.php',
'ezcBaseMetaDataPearReader' => 'Base/metadata/pear.php',
'ezcBaseMetaDataTarballReader' => 'Base/metadata/tarball.php',
'ezcBasePersistable' => 'Base/interfaces/persistable.php',
'ezcBaseRepositoryDirectory' => 'Base/structs/repository_directory.php',
);
?>

View file

@ -0,0 +1,38 @@
<?php
/**
* File containing the ezcBaseAutoloadException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseAutoloadException is thrown whenever a class can not be found with
* the autoload mechanism.
*
* @package Base
* @version //autogen//
*/
class ezcBaseAutoloadException extends ezcBaseException
{
/**
* Constructs a new ezcBaseAutoloadException for the $className that was
* searched for in the autoload files $fileNames from the directories
* specified in $dirs.
*
* @param string $className
* @param array(string) $files
* @param array(ezcBaseRepositoryDirectory) $dirs
*/
function __construct( $className, $files, $dirs )
{
$paths = array();
foreach ( $dirs as $dir )
{
$paths[] = realpath( $dir->autoloadPath );
}
parent::__construct( "Could not find a class to file mapping for '{$className}'. Searched for ". implode( ', ', $files ) . " in: " . implode( ', ', $paths ) );
}
}
?>

View file

@ -0,0 +1,34 @@
<?php
/**
* File containing the ezcBaseDoubleClassRepositoryPrefixException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseDoubleClassRepositoryPrefixException is thrown whenever you try to
* register a class repository with a prefix that has already been added
* before.
*
* @package Base
* @version //autogen//
*/
class ezcBaseDoubleClassRepositoryPrefixException extends ezcBaseException
{
/**
* Constructs a new ezcBaseDoubleClassRepositoryPrefixException for the
* $prefix that points to $basePath with autoload directory
* $autoloadDirPath.
*
* @param string $prefix
* @param string $basePath
* @param string $autoloadDirPath
*/
function __construct( $prefix, $basePath, $autoloadDirPath )
{
parent::__construct( "The class repository in '{$basePath}' (with autoload dir '{$autoloadDirPath}') can not be added because another class repository already uses the prefix '{$prefix}'." );
}
}
?>

View file

@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseException class.
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseException is a container from which all other exceptions in the
* components library descent.
*
* @package Base
* @version //autogen//
*/
abstract class ezcBaseException extends Exception
{
/**
* Original message, before escaping
*/
public $originalMessage;
/**
* Constructs a new ezcBaseException with $message
*
* @param string $message
*/
public function __construct( $message )
{
$this->originalMessage = $message;
if ( php_sapi_name() == 'cli' )
{
parent::__construct( $message );
}
else
{
parent::__construct( htmlspecialchars( $message ) );
}
}
}
?>

View file

@ -0,0 +1,38 @@
<?php
/**
* File containing the ezcBaseExtensionNotFoundException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseExtensionNotFoundException is thrown when a requested PHP extension was not found.
*
* @package Base
* @version //autogen//
*/
class ezcBaseExtensionNotFoundException extends ezcBaseException
{
/**
* Constructs a new ezcBaseExtensionNotFoundException.
*
* @param string $name The name of the extension
* @param string $version The version of the extension
* @param string $message Additional text
*/
function __construct( $name, $version = null, $message = null )
{
if ( $version === null )
{
parent::__construct( "The extension '{$name}' could not be found. {$message}" );
}
else
{
parent::__construct( "The extension '{$name}' with version '{$version}' could not be found. {$message}" );
}
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
/**
* File containing the ezcBaseFileException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseFileException is the exception from which all file related exceptions
* inherit.
*
* @package Base
* @version //autogen//
*/
abstract class ezcBaseFileException extends ezcBaseException
{
const READ = 1;
const WRITE = 2;
const EXECUTE = 4;
const CHANGE = 8;
const REMOVE = 16;
}
?>

View file

@ -0,0 +1,50 @@
<?php
/**
* File containing the ezcBaseFileIoException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseFileIoException is thrown when a problem occurs while writing
* and reading to/from an open file.
*
* @package Base
* @version //autogen//
*/
class ezcBaseFileIoException extends ezcBaseFileException
{
/**
* Constructs a new ezcBaseFileIoException for the file $path.
*
* @param string $path The name of the file.
* @param int $mode The mode of the property that is allowed
* (ezcBaseFileException::READ, ezcBaseFileException::WRITE,
* ezcBaseFileException::EXECUTE or
* ezcBaseFileException::CHANGE).
* @param string $message A string with extra information.
*/
function __construct( $path, $mode, $message = null )
{
switch ( $mode )
{
case ezcBaseFileException::READ:
$operation = "An error occurred while reading from '{$path}'";
break;
case ezcBaseFileException::WRITE:
$operation = "An error occurred while writing to '{$path}'";
break;
}
$messagePart = '';
if ( $message )
{
$messagePart = " ($message)";
}
parent::__construct( "$operation.$messagePart" );
}
}
?>

View file

@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseFileNotFoundException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseFileNotFoundException is thrown when a file or directory was tried to
* be opened, but did not exist.
*
* @package Base
* @version //autogen//
*/
class ezcBaseFileNotFoundException extends ezcBaseFileException
{
/**
* Constructs a new ezcBaseFileNotFoundException.
*
* @param string $path The name of the file.
* @param string $type The type of the file.
* @param string $message A string with extra information.
*/
function __construct( $path, $type = null, $message = null )
{
$typePart = '';
if ( $type )
{
$typePart = "$type ";
}
$messagePart = '';
if ( $message )
{
$messagePart = " ($message)";
}
parent::__construct( "The {$typePart}file '{$path}' could not be found.$messagePart" );
}
}
?>

View file

@ -0,0 +1,63 @@
<?php
/**
* File containing the ezcBaseFilePermissionException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseFilePermissionException is thrown whenever a permission problem with
* a file, directory or stream occurred.
*
* @package Base
* @version //autogen//
*/
class ezcBaseFilePermissionException extends ezcBaseFileException
{
/**
* Constructs a new ezcPropertyPermissionException for the property $name.
*
* @param string $path The name of the file.
* @param int $mode The mode of the property that is allowed
* (ezcBaseFileException::READ, ezcBaseFileException::WRITE,
* ezcBaseFileException::EXECUTE,
* ezcBaseFileException::CHANGE or
* ezcBaseFileException::REMOVE).
* @param string $message A string with extra information.
*/
function __construct( $path, $mode, $message = null )
{
switch ( $mode )
{
case ezcBaseFileException::READ:
$operation = "The file '{$path}' can not be opened for reading";
break;
case ezcBaseFileException::WRITE:
$operation = "The file '{$path}' can not be opened for writing";
break;
case ezcBaseFileException::EXECUTE:
$operation = "The file '{$path}' can not be executed";
break;
case ezcBaseFileException::CHANGE:
$operation = "The permissions for '{$path}' can not be changed";
break;
case ezcBaseFileException::REMOVE:
$operation = "The file '{$path}' can not be removed";
break;
case ( ezcBaseFileException::READ || ezcBaseFileException::WRITE ):
$operation = "The file '{$path}' can not be opened for reading and writing";
break;
}
$messagePart = '';
if ( $message )
{
$messagePart = " ($message)";
}
parent::__construct( "$operation.$messagePart" );
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
/**
* File containing the ezcBaseFunctionalityNotSupportedException class.
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* The ezcBaseFunctionalityNotSupportedException is thrown when a requested
* PHP function was not found.
*
* @package Base
* @version //autogen//
*/
class ezcBaseFunctionalityNotSupportedException extends ezcBaseException
{
/**
* Constructs a new ezcBaseFunctionalityNotSupportedException.
*
* @param string $message The message to throw
* @param string $reason The reason for the exception
*/
function __construct( $message, $reason )
{
parent::__construct( "{$message} is not supported. Reason: {$reason}." );
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
/**
* File containing the ezcBaseInitCallbackConfiguredException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseInitCallbackConfiguredException is thrown when you try to assign a
* callback clasname to an identifier, while there is already a callback class
* configured for this identifier.
*
* @package Base
* @version //autogen//
*/
class ezcBaseInitCallbackConfiguredException extends ezcBaseException
{
/**
* Constructs a new ezcBaseInitCallbackConfiguredException.
*
* @param string $identifier
* @param string $originalCallbackClassName
*/
function __construct( $identifier, $originalCallbackClassName )
{
parent::__construct( "The '{$identifier}' is already configured with callback class '{$originalCallbackClassName}'." );
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
/**
* File containing the ezcBaseInitInvalidCallbackClassException class
*
* @package Configuration
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Exception that is thrown if an invalid class is passed as callback class for
* delayed object configuration.
*
* @package Configuration
* @version //autogen//
*/
class ezcBaseInitInvalidCallbackClassException extends ezcBaseException
{
/**
* Constructs a new ezcBaseInitInvalidCallbackClassException for the $callbackClass.
*
* @param string $callbackClass
* @return void
*/
function __construct( $callbackClass )
{
parent::__construct( "Class '{$callbackClass}' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface." );
}
}
?>

View file

@ -0,0 +1,29 @@
<?php
/**
* File containing the ezcBaseInvalidParentClassException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Exception that is thrown if an invalid class is passed as custom class.
*
* @package Base
* @version //autogen//
*/
class ezcBaseInvalidParentClassException extends ezcBaseException
{
/**
* Constructs an ezcBaseInvalidParentClassException for custom class $customClass
*
* @param string $expectedParentClass
* @param string $customClass
*/
function __construct( $expectedParentClass, $customClass )
{
parent::__construct( "Class '{$customClass}' does not exist, or does not inherit from the '{$expectedParentClass}' class." );
}
}
?>

View file

@ -0,0 +1,30 @@
<?php
/**
* File containing the ezcBasePropertyNotFoundException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBasePropertyNotFoundException is thrown whenever a non existent property
* is accessed in the Components library.
*
* @package Base
* @version //autogen//
*/
class ezcBasePropertyNotFoundException extends ezcBaseException
{
/**
* Constructs a new ezcBasePropertyNotFoundException for the property
* $name.
*
* @param string $name The name of the property
*/
function __construct( $name )
{
parent::__construct( "No such property name '{$name}'." );
}
}
?>

View file

@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcPropertyReadOnlyException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBasePropertyPermissionException is thrown whenever a read-only property
* is tried to be changed, or when a write-only property was accessed for reading.
*
* @package Base
* @version //autogen//
*/
class ezcBasePropertyPermissionException extends ezcBaseException
{
/**
* Used when the property is read-only.
*/
const READ = 1;
/**
* Used when the property is write-only.
*/
const WRITE = 2;
/**
* Constructs a new ezcPropertyPermissionException for the property $name.
*
* @param string $name The name of the property.
* @param int $mode The mode of the property that is allowed (::READ or ::WRITE).
*/
function __construct( $name, $mode )
{
parent::__construct( "The property '{$name}' is " .
( $mode == self::READ ? "read" : "write" ) .
"-only." );
}
}
?>

View file

@ -0,0 +1,29 @@
<?php
/**
* File containing the ezcBaseSettingNotFoundException class.
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseSettingNotFoundException is thrown whenever there is a name passed as
* part as the options array to setOptions() for an option that doesn't exist.
*
* @package Base
* @version //autogen//
*/
class ezcBaseSettingNotFoundException extends ezcBaseException
{
/**
* Constructs a new ezcBaseSettingNotFoundException for $settingName.
*
* @param string $settingName The name of the setting that does not exist.
*/
function __construct( $settingName )
{
parent::__construct( "The setting '{$settingName}' is not a valid configuration setting." );
}
}
?>

View file

@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcBaseSettingValueException class.
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseSettingValueExeception is thrown whenever a value to a class'
* configuration option is either of the wrong type, or has a wrong value.
*
* @package Base
* @version //autogen//
*/
class ezcBaseSettingValueException extends ezcBaseException
{
/**
* Constructs a new ezcBaseConfigException
*
* @param string $settingName The name of the setting where something was
* wrong with.
* @param mixed $value The value that the option was tried to be set too.
* @param string $expectedValue A string explaining the allowed type and value range.
*/
function __construct( $settingName, $value, $expectedValue = null )
{
$type = gettype( $value );
if ( in_array( $type, array( 'array', 'object', 'resource' ) ) )
{
$value = serialize( $value );
}
$msg = "The value '{$value}' that you were trying to assign to setting '{$settingName}' is invalid.";
if ( $expectedValue )
{
$msg .= " Allowed values are: " . $expectedValue;
}
parent::__construct( $msg );
}
}
?>

View file

@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseValueException class.
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseValueException is thrown whenever the type or value of the given
* variable is not as expected.
*
* @package Base
* @version //autogen//
*/
class ezcBaseValueException extends ezcBaseException
{
/**
* Constructs a new ezcBaseValueException on the $name variable.
*
* @param string $settingName The name of the setting where something was
* wrong with.
* @param mixed $value The value that the option was tried to be set too.
* @param string $expectedValue A string explaining the allowed type and value range.
* @param string $variableType What type of variable was tried to be set (setting, argument).
*/
function __construct( $settingName, $value, $expectedValue = null, $variableType = 'setting' )
{
$type = gettype( $value );
if ( in_array( $type, array( 'array', 'object', 'resource' ) ) )
{
$value = serialize( $value );
}
$msg = "The value '{$value}' that you were trying to assign to $variableType '{$settingName}' is invalid.";
if ( $expectedValue )
{
$msg .= " Allowed values are: " . $expectedValue . '.';
}
parent::__construct( $msg );
}
}
?>

View file

@ -0,0 +1,40 @@
<?php
/**
* File containing the ezcBaseWhateverException class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* ezcBaseWhateverException is thrown whenever something is so seriously wrong.
*
* If this happens it is not possible to repair anything gracefully. An
* example for this could be, that your eZ components installation has thrown
* far to many exceptions. Whenever you receive an ezcBaseWhateverException, do
* not even try to catch it, but forget your project completely and immediately
* stop coding! ;)
*
* @access private
* @package Base
* @version //autogen//
*/
class ezcBaseWhateverException extends ezcBaseException
{
/**
* Constructs a new ezcBaseWhateverException.
*
* @param string $what What happened?
* @param string $where Where did it happen?
* @param string $who Who is responsible?
* @param string $why Why did is happen?
* @access protected
* @return void
*/
function __construct( $what, $where, $who, $why )
{
parent::__construct( "Thanks for using eZ components. Hope you like it! Greetings from Amos, Derick, El Frederico, Ray and Toby." );
}
}
?>

View file

@ -0,0 +1,40 @@
<?php
/**
* Include file that can be used for a quick setup of the eZ Components.
*
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version //autogentag//
* @filesource
* @package Base
* @access private
*/
$dir = dirname( __FILE__ );
$dirParts = explode( DIRECTORY_SEPARATOR, $dir );
if ( $dirParts[count( $dirParts ) - 1] === 'src' )
{
$baseDir = join( DIRECTORY_SEPARATOR, array_slice( $dirParts, 0, -2 ) );
require $baseDir . '/Base/src/base.php'; // svn, bundle
}
else if ( $dirParts[count( $dirParts ) - 2] === 'ezc' )
{
$baseDir = join( DIRECTORY_SEPARATOR, array_slice( $dirParts, 0, -2 ) );
require $baseDir . '/ezc/Base/base.php'; // pear
}
else
{
die( "Your environment isn't properly set-up. Please refer to the eZ components documentation at http://components.ez.no/doc ." );
}
/**
* Implements the __autoload mechanism for PHP - which can only be done once
* per request.
*
* @param string $className The name of the class that should be loaded.
*/
function __autoload( $className )
{
ezcBase::autoload( $className );
}
?>

View file

@ -0,0 +1,365 @@
<?php
/**
* File containing the ezcBaseFeatures class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Provides methods needed to check for features.
*
* Example:
* <code>
* <?php
* echo "supports uid: " . ezcBaseFeatures::supportsUserId() . "\n";
* echo "supports symlink: " . ezcBaseFeatures::supportsSymLink() . "\n";
* echo "supports hardlink: " . ezcBaseFeatures::supportsLink() . "\n";
* echo "has imagemagick identify: " . ezcBaseFeatures::hasImageIdentify() . "\n";
* echo " identify path: " . ezcBaseFeatures::getImageIdentifyExecutable() . "\n";
* echo "has imagemagick convert: " . ezcBaseFeatures::hasImageConvert() . "\n";
* echo " convert path: " . ezcBaseFeatures::getImageConvertExecutable() . "\n";
* echo "has gzip extension: " . ezcBaseFeatures::hasExtensionSupport( 'zlib' ) . "\n";
* echo "has pdo_mysql 1.0.2: " . ezcBaseFeatures::hasExtensionSupport( 'pdo_mysql', '1.0.2' ) . "\n"
* ?>
* </code>
*
* @package Base
* @version //autogentag//
*/
class ezcBaseFeatures
{
/**
* Used to store the path of the ImageMagick convert utility.
*
* It is initialized in the {@link getImageConvertExecutable()} function.
*
* @var string
*/
private static $imageConvert = null;
/**
* Used to store the path of the ImageMagick identify utility.
*
* It is initialized in the {@link getImageIdentifyExecutable()} function.
*
* @var string
*/
private static $imageIdentify = null;
/**
* Used to store the operating system.
*
* It is initialized in the {@link os()} function.
*
* @var string
*/
private static $os = null;
/**
* Determines if hardlinks are supported.
*
* @return bool
*/
public static function supportsLink()
{
return function_exists( 'link' );
}
/**
* Determines if symlinks are supported.
*
* @return bool
*/
public static function supportsSymLink()
{
return function_exists( 'symlink' );
}
/**
* Determines if posix uids are supported.
*
* @return bool
*/
public static function supportsUserId()
{
return function_exists( 'posix_getpwuid' );
}
/**
* Determines if the ImageMagick convert utility is installed.
*
* @return bool
*/
public static function hasImageConvert()
{
return !is_null( self::getImageConvertExecutable() );
}
/**
* Returns the path to the ImageMagick convert utility.
*
* On Linux, Unix,... it will return something like: /usr/bin/convert
* On Windows it will return something like: C:\Windows\System32\convert.exe
*
* @return string
*/
public static function getImageConvertExecutable()
{
if ( !is_null( self::$imageConvert ) )
{
return self::$imageConvert;
}
return ( self::$imageConvert = self::findExecutableInPath( 'convert' ) );
}
/**
* Determines if the ImageMagick identify utility is installed.
*
* @return bool
*/
public static function hasImageIdentify()
{
return !is_null( self::getImageIdentifyExecutable() );
}
/**
* Returns the path to the ImageMagick identify utility.
*
* On Linux, Unix,... it will return something like: /usr/bin/identify
* On Windows it will return something like: C:\Windows\System32\identify.exe
*
* @return string
*/
public static function getImageIdentifyExecutable()
{
if ( !is_null( self::$imageIdentify ) )
{
return self::$imageIdentify;
}
return ( self::$imageIdentify = self::findExecutableInPath( 'identify' ) );
}
/**
* Determines if the specified extension is loaded.
*
* If $version is specified, the specified extension will be tested also
* against the version of the loaded extension.
*
* Examples:
* <code>
* hasExtensionSupport( 'gzip' );
* </code>
* will return true if gzip extension is loaded.
*
* <code>
* hasExtensionSupport( 'pdo_mysql', '1.0.2' );
* </code>
* will return true if pdo_mysql extension is loaded and its version is at least 1.0.2.
*
* @param string $extension
* @param string $version
* @return bool
*/
public static function hasExtensionSupport( $extension, $version = null )
{
if ( is_null( $version ) )
{
return extension_loaded( $extension );
}
return extension_loaded( $extension ) && version_compare( phpversion( $extension ), $version, ">=" ) ;
}
/**
* Determines if the specified function is available.
*
* Examples:
* <code>
* ezcBaseFeatures::hasFunction( 'imagepstext' );
* </code>
* will return true if support for Type 1 fonts is available with your GD
* extension.
*
* @param string $functionName
* @return bool
*/
public static function hasFunction( $functionName )
{
return function_exists( $functionName );
}
/**
* Returns if a given class exists.
* Checks for a given class name and returns if this class exists or not.
* Catches the ezcBaseAutoloadException and returns false, if it was thrown.
*
* @param string $className The class to check for.
* @param bool $autoload True to use __autoload(), otherwise false.
* @return bool True if the class exists. Otherwise false.
*/
public static function classExists( $className, $autoload = true )
{
try
{
if ( class_exists( $className, $autoload ) )
{
return true;
}
return false;
}
catch ( ezcBaseAutoloadException $e )
{
return false;
}
}
/**
* Returns the operating system on which PHP is running.
*
* This method returns a sanitized form of the OS name, example
* return values are "Windows", "Mac", "Linux" and "FreeBSD". In
* all other cases it returns the value of the internal PHP constant
* PHP_OS.
*
* @return string
*/
public static function os()
{
if ( is_null( self::$os ) )
{
$uname = php_uname( 's' );
if ( substr( $uname, 0, 7 ) == 'Windows' )
{
self::$os = 'Windows';
}
elseif ( substr( $uname, 0, 3 ) == 'Mac' )
{
self::$os = 'Mac';
}
elseif ( strtolower( $uname ) == 'linux' )
{
self::$os = 'Linux';
}
elseif ( strtolower( substr( $uname, 0, 7 ) ) == 'freebsd' )
{
self::$os = 'FreeBSD';
}
else
{
self::$os = PHP_OS;
}
}
return self::$os;
}
/**
* Returns the path of the specified executable, if it can be found in the system's path.
*
* It scans the PATH enviroment variable based on the OS to find the
* $fileName. For Windows, the path is with \, not /. If $fileName is not
* found, it returns null.
*
* @todo consider using getenv( 'PATH' ) instead of $_ENV['PATH']
* (but that won't work under IIS)
*
* @param string $fileName
* @return string
*/
public static function findExecutableInPath( $fileName )
{
if ( array_key_exists( 'PATH', $_ENV ) )
{
$envPath = trim( $_ENV['PATH'] );
}
else if ( ( $envPath = getenv( 'PATH' ) ) !== false )
{
$envPath = trim( $envPath );
}
if ( is_string( $envPath ) && strlen( trim( $envPath ) ) == 0 )
{
$envPath = false;
}
switch ( self::os() )
{
case 'Unix':
case 'FreeBSD':
case 'Mac':
case 'MacOS':
case 'Darwin':
case 'Linux':
case 'SunOS':
if ( $envPath )
{
$dirs = explode( ':', $envPath );
foreach ( $dirs as $dir )
{
// The @-operator is used here mainly to avoid
// open_basedir warnings. If open_basedir (or any other
// circumstance) prevents the desired file from being
// accessed, it is fine for file_exists() to return
// false, since it is useless for use then, anyway.
if ( file_exists( "{$dir}/{$fileName}" ) )
{
return "{$dir}/{$fileName}";
}
}
}
// The @-operator is used here mainly to avoid open_basedir
// warnings. If open_basedir (or any other circumstance)
// prevents the desired file from being accessed, it is fine
// for file_exists() to return false, since it is useless for
// use then, anyway.
elseif ( @file_exists( "./{$fileName}" ) )
{
return $fileName;
}
break;
case 'Windows':
if ( $envPath )
{
$dirs = explode( ';', $envPath );
foreach ( $dirs as $dir )
{
// The @-operator is used here mainly to avoid
// open_basedir warnings. If open_basedir (or any other
// circumstance) prevents the desired file from being
// accessed, it is fine for file_exists() to return
// false, since it is useless for use then, anyway.
if ( @file_exists( "{$dir}\\{$fileName}.exe" ) )
{
return "{$dir}\\{$fileName}.exe";
}
}
}
// The @-operator is used here mainly to avoid open_basedir
// warnings. If open_basedir (or any other circumstance)
// prevents the desired file from being accessed, it is fine
// for file_exists() to return false, since it is useless for
// use then, anyway.
elseif ( @file_exists( "{$fileName}.exe" ) )
{
return "{$fileName}.exe";
}
break;
}
return null;
}
/**
* Reset the cached information.
*
* @return void
* @access private
* @ignore
*/
public static function reset()
{
self::$imageIdentify = null;
self::$imageConvert = null;
self::$os = null;
}
}
?>

View file

@ -0,0 +1,495 @@
<?php
/**
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version //autogentag//
* @filesource
* @package Base
*/
/**
* Provides a selection of static independent methods to provide functionality
* for file and file system handling.
*
* This example shows how to use the findRecursive method:
* <code>
* <?php
* // lists all the files under /etc (including subdirectories) that end in
* // .conf
* $confFiles = ezcBaseFile::findRecursive( "/etc", array( '@\.conf$@' ) );
*
* // lists all autoload files in the components source tree and excludes the
* // ones in the autoload subdirectory. Statistics are returned in the $stats
* // variable which is passed by reference.
* $files = ezcBaseFile::findRecursive(
* "/dat/dev/ezcomponents",
* array( '@src/.*_autoload.php$@' ),
* array( '@/autoload/@' ),
* $stats
* );
*
* // lists all binaries in /bin except the ones starting with a "g"
* $data = ezcBaseFile::findRecursive( "/bin", array(), array( '@^/bin/g@' ) );
* ?>
* </code>
*
* @package Base
* @version //autogentag//
* @mainclass
*/
class ezcBaseFile
{
/**
* This is the callback used by findRecursive to collect data.
*
* This callback method works together with walkRecursive() and is called
* for every file/and or directory. The $context is a callback specific
* container in which data can be stored and shared between the different
* calls to the callback function. The walkRecursive() function also passes
* in the full absolute directory in $sourceDir, the filename in $fileName
* and file information (such as size, modes, types) as an array as
* returned by PHP's stat() in the $fileInfo parameter.
*
* @param ezcBaseFileFindContext $context
* @param string $sourceDir
* @param string $fileName
* @param array(stat) $fileInfo
*/
static protected function findRecursiveCallback( ezcBaseFileFindContext $context, $sourceDir, $fileName, $fileInfo )
{
// ignore if we have a directory
if ( $fileInfo['mode'] & 0x4000 )
{
return;
}
// update the statistics
$context->elements[] = $sourceDir . DIRECTORY_SEPARATOR . $fileName;
$context->count++;
$context->size += $fileInfo['size'];
}
/**
* Walks files and directories recursively on a file system
*
* This method walks over a directory and calls a callback from every file
* and directory it finds. You can use $includeFilters to include only
* specific files, and $excludeFilters to exclude certain files from being
* returned. The function will always go into subdirectories even if the
* entry would not have passed the filters.
*
* The callback is passed in the $callback parameter, and the
* $callbackContext will be send to the callback function/method as
* parameter so that you can store data in there that persists with all the
* calls and recursive calls to this method. It's up to the callback method
* to do something useful with this. The callback function's parameters are
* in order:
*
* <ul>
* <li>ezcBaseFileFindContext $context</li>
* <li>string $sourceDir</li>
* <li>string $fileName</li>
* <li>array(stat) $fileInfo</li>
* </ul>
*
* See {@see findRecursiveCallback()} for an example of a callback function.
*
* Filters are regular expressions and are therefore required to have
* starting and ending delimiters. The Perl Compatible syntax is used as
* regular expression language.
*
* @param string $sourceDir
* @param array(string) $includeFilters
* @param array(string) $excludeFilters
* @param callback $callback
* @param mixed $callbackContext
*
* @throws ezcBaseFileNotFoundException if the $sourceDir directory is not
* a directory or does not exist.
* @throws ezcBaseFilePermissionException if the $sourceDir directory could
* not be opened for reading.
* @return array
*/
static public function walkRecursive( $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), $callback, &$callbackContext )
{
if ( !is_dir( $sourceDir ) )
{
throw new ezcBaseFileNotFoundException( $sourceDir, 'directory' );
}
$elements = array();
$d = @dir( $sourceDir );
if ( !$d )
{
throw new ezcBaseFilePermissionException( $sourceDir, ezcBaseFileException::READ );
}
while ( ( $entry = $d->read() ) !== false )
{
if ( $entry == '.' || $entry == '..' )
{
continue;
}
$fileInfo = @stat( $sourceDir . DIRECTORY_SEPARATOR . $entry );
if ( !$fileInfo )
{
$fileInfo = array( 'size' => 0, 'mode' => 0 );
}
if ( $fileInfo['mode'] & 0x4000 )
{
// We need to ignore the Permission exceptions here as it can
// be normal that a directory can not be accessed. We only need
// the exception if the top directory could not be read.
try
{
call_user_func_array( $callback, array( $callbackContext, $sourceDir, $entry, $fileInfo ) );
$subList = self::walkRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry, $includeFilters, $excludeFilters, $callback, $callbackContext );
$elements = array_merge( $elements, $subList );
}
catch ( ezcBaseFilePermissionException $e )
{
}
}
else
{
// By default a file is included in the return list
$ok = true;
// Iterate over the $includeFilters and prohibit the file from
// being returned when atleast one of them does not match
foreach ( $includeFilters as $filter )
{
if ( !preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
{
$ok = false;
break;
}
}
// Iterate over the $excludeFilters and prohibit the file from
// being returns when atleast one of them matches
foreach ( $excludeFilters as $filter )
{
if ( preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
{
$ok = false;
break;
}
}
// If everything's allright, call the callback and add the
// entry to the elements array
if ( $ok )
{
call_user_func( $callback, $callbackContext, $sourceDir, $entry, $fileInfo );
$elements[] = $sourceDir . DIRECTORY_SEPARATOR . $entry;
}
}
}
sort( $elements );
return $elements;
}
/**
* Finds files recursively on a file system
*
* With this method you can scan the file system for files. You can use
* $includeFilters to include only specific files, and $excludeFilters to
* exclude certain files from being returned. The function will always go
* into subdirectories even if the entry would not have passed the filters.
* It uses the {@see walkRecursive()} method to do the actually recursion.
*
* Filters are regular expressions and are therefore required to have
* starting and ending delimiters. The Perl Compatible syntax is used as
* regular expression language.
*
* If you pass an empty array to the $statistics argument, the function
* will in details about the number of files found into the 'count' array
* element, and the total filesize in the 'size' array element. Because this
* argument is passed by reference, you *have* to pass a variable and you
* can not pass a constant value such as "array()".
*
* @param string $sourceDir
* @param array(string) $includeFilters
* @param array(string) $excludeFilters
* @param array() $statistics
*
* @throws ezcBaseFileNotFoundException if the $sourceDir directory is not
* a directory or does not exist.
* @throws ezcBaseFilePermissionException if the $sourceDir directory could
* not be opened for reading.
* @return array
*/
static public function findRecursive( $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), &$statistics = null )
{
// init statistics array
if ( !is_array( $statistics ) || !array_key_exists( 'size', $statistics ) || !array_key_exists( 'count', $statistics ) )
{
$statistics['size'] = 0;
$statistics['count'] = 0;
}
// create the context, and then start walking over the array
$context = new ezcBaseFileFindContext;
self::walkRecursive( $sourceDir, $includeFilters, $excludeFilters, array( 'ezcBaseFile', 'findRecursiveCallback' ), $context );
// collect the statistics
$statistics['size'] = $context->size;
$statistics['count'] = $context->count;
// return the found and pattern-matched files
sort( $context->elements );
return $context->elements;
}
/**
* Removes files and directories recursively from a file system
*
* This method recursively removes the $directory and all its contents.
* You should be <b>extremely</b> careful with this method as it has the
* potential to erase everything that the current user has access to.
*
* @param string $directory
*/
static public function removeRecursive( $directory )
{
$sourceDir = realpath( $directory );
if ( !$sourceDir )
{
throw new ezcBaseFileNotFoundException( $directory, 'directory' );
}
$d = @dir( $sourceDir );
if ( !$d )
{
throw new ezcBaseFilePermissionException( $directory, ezcBaseFileException::READ );
}
// check if we can remove the dir
$parentDir = realpath( $directory . DIRECTORY_SEPARATOR . '..' );
if ( !is_writable( $parentDir ) )
{
throw new ezcBaseFilePermissionException( $parentDir, ezcBaseFileException::WRITE );
}
// loop over contents
while ( ( $entry = $d->read() ) !== false )
{
if ( $entry == '.' || $entry == '..' )
{
continue;
}
if ( is_dir( $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
{
self::removeRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry );
}
else
{
if ( @unlink( $sourceDir . DIRECTORY_SEPARATOR . $entry ) === false )
{
throw new ezcBaseFilePermissionException( $directory . DIRECTORY_SEPARATOR . $entry, ezcBaseFileException::REMOVE );
}
}
}
$d->close();
rmdir( $sourceDir );
}
/**
* Recursively copy a file or directory.
*
* Recursively copy a file or directory in $source to the given
* destination. If a depth is given, the operation will stop, if the given
* recursion depth is reached. A depth of -1 means no limit, while a depth
* of 0 means, that only the current file or directory will be copied,
* without any recursion.
*
* You may optionally define modes used to create files and directories.
*
* @throws ezcBaseFileNotFoundException
* If the $sourceDir directory is not a directory or does not exist.
* @throws ezcBaseFilePermissionException
* If the $sourceDir directory could not be opened for reading, or the
* destination is not writeable.
*
* @param string $source
* @param string $destination
* @param int $depth
* @param int $dirMode
* @param int $fileMode
* @return void
*/
static public function copyRecursive( $source, $destination, $depth = -1, $dirMode = 0775, $fileMode = 0664 )
{
// Check if source file exists at all.
if ( !is_file( $source ) && !is_dir( $source ) )
{
throw new ezcBaseFileNotFoundException( $source );
}
// Destination file should NOT exist
if ( is_file( $destination ) || is_dir( $destination ) )
{
throw new ezcBaseFilePermissionException( $destination, ezcBaseFileException::WRITE );
}
// Skip non readable files in source directory
if ( !is_readable( $source ) )
{
return;
}
// Copy
if ( is_dir( $source ) )
{
mkdir( $destination );
// To ignore umask, umask() should not be changed with
// multithreaded servers...
chmod( $destination, $dirMode );
}
elseif ( is_file( $source ) )
{
copy( $source, $destination );
chmod( $destination, $fileMode );
}
if ( ( $depth === 0 ) ||
( !is_dir( $source ) ) )
{
// Do not recurse (any more)
return;
}
// Recurse
$dh = opendir( $source );
while ( ( $file = readdir( $dh ) ) !== false )
{
if ( ( $file === '.' ) ||
( $file === '..' ) )
{
continue;
}
self::copyRecursive(
$source . '/' . $file,
$destination . '/' . $file,
$depth - 1, $dirMode, $fileMode
);
}
}
/**
* Calculates the relative path of the file/directory '$path' to a given
* $base path.
*
* $path and $base should be fully absolute paths. This function returns the
* answer of "How do I go from $base to $path". If the $path and $base are
* the same path, the function returns '.'. This method does not touch the
* filesystem.
*
* @param string $path
* @param string $base
* @return string
*/
static public function calculateRelativePath( $path, $base )
{
// Sanitize the paths to use the correct directory separator for the platform
$path = strtr( $path, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR );
$base = strtr( $base, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR );
$base = explode( DIRECTORY_SEPARATOR, $base );
$path = explode( DIRECTORY_SEPARATOR, $path );
// If the paths are the same we return
if ( $base === $path )
{
return '.';
}
$result = '';
$pathPart = array_shift( $path );
$basePart = array_shift( $base );
while ( $pathPart == $basePart )
{
$pathPart = array_shift( $path );
$basePart = array_shift( $base );
}
if ( $pathPart != null )
{
array_unshift( $path, $pathPart );
}
if ( $basePart != null )
{
array_unshift( $base, $basePart );
}
$result = str_repeat( '..' . DIRECTORY_SEPARATOR, count( $base ) );
// prevent a trailing DIRECTORY_SEPARATOR in case there is only a ..
if ( count( $path ) == 0 )
{
$result = substr( $result, 0, -strlen( DIRECTORY_SEPARATOR ) );
}
$result .= join( DIRECTORY_SEPARATOR, $path );
return $result;
}
/**
* Returns whether the passed $path is an absolute path, giving the current $os.
*
* With the $os parameter you can tell this function to use the semantics
* for a different operating system to determine whether a path is
* absolute. The $os argument defaults to the OS that the script is running
* on.
*
* @param string $path
* @param string $os
* @return bool
*/
public static function isAbsolutePath( $path, $os = null )
{
if ( $os === null )
{
$os = ezcBaseFeatures::os();
}
// Stream wrapper like phar can also be considered absolute paths
if ( preg_match( '(^[a-z]{3,}://)S', $path ) )
{
return true;
}
switch ( $os )
{
case 'Windows':
// Sanitize the paths to use the correct directory separator for the platform
$path = strtr( $path, '\\/', '\\\\' );
// Absolute paths with drive letter: X:\
if ( preg_match( '@^[A-Z]:\\\\@i', $path ) )
{
return true;
}
// Absolute paths with network paths: \\server\share\
if ( preg_match( '@^\\\\\\\\[A-Z]+\\\\[^\\\\]@i', $path ) )
{
return true;
}
break;
case 'Mac':
case 'Linux':
case 'FreeBSD':
default:
// Sanitize the paths to use the correct directory separator for the platform
$path = strtr( $path, '\\/', '//' );
if ( $path[0] == '/' )
{
return true;
}
}
return false;
}
}
?>

View file

@ -0,0 +1,125 @@
<?php
/**
* File containing the ezcBaseInit class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Provides a method to implement delayed initialization of objects.
*
* With the methods in this class you can implement callbacks to configure
* singleton classes. In order to do so you will have to change the
* getInstance() method of your singleton class to include a call to
* ezcBaseInit::fetchConfig() as in the following example:
*
* <code>
* <?php
* public static function getInstance()
* {
* if ( is_null( self::$instance ) )
* {
* self::$instance = new ezcConfigurationmanager();
* ezcBaseInit::fetchConfig( 'ezcInitConfigurationManager', self::$instance );
* }
* return self::$instance;
* }
* ?>
* </code>
*
* You will also need to configure which callback class to call. This you do
* with the ezcBaseInit::setCallback() method. The following examples sets the
* callback classname for the configuration identifier
* 'ezcInitConfigurationManager' to 'cfgConfigurationManager':
*
* <code>
* <?php
* ezcBaseInit::setCallback( 'ezcInitConfigurationManager', 'cfgConfigurationManager' );
* ?>
* </code>
*
* The class 'cfgConfigurationManager' is required to implement the
* ezcBaseConfigurationInitializer interface, which defines only one method:
* configureObject(). An example on how to implement such a class could be:
*
* <code>
* <?php
* class cfgConfigurationManager implements ezcBaseConfigurationInitializer
* {
* static public function configureObject( ezcConfigurationManager $cfgManagerObject )
* {
* $cfgManagerObject->init( 'ezcConfigurationIniReader', 'settings', array( 'useComments' => true ) );
* }
* }
* ?>
* </code>
*
* Of course the implementation of this callback class is up to the application
* developer that uses the component (in this example the Configuration
* component's class ezcConfigurationManager).
*
* @package Base
* @version //autogentag//
*/
class ezcBaseInit
{
/**
* Contains the callback where the identifier is the key of the array, and the classname to callback to the value.
*
* @var array(string=>string)
*/
static private $callbackMap = array();
/**
* Adds the classname $callbackClassname as callback for the identifier $identifier.
*
* @param string $identifier
* @param string $callbackClassname
*/
public static function setCallback( $identifier, $callbackClassname )
{
if ( array_key_exists( $identifier, self::$callbackMap ) )
{
throw new ezcBaseInitCallbackConfiguredException( $identifier, self::$callbackMap[$identifier] );
}
else
{
// Check if the passed classname actually exists
if ( !ezcBaseFeatures::classExists( $callbackClassname, true ) )
{
throw new ezcBaseInitInvalidCallbackClassException( $callbackClassname );
}
// Check if the passed classname actually implements the interface.
if ( !in_array( 'ezcBaseConfigurationInitializer', class_implements( $callbackClassname ) ) )
{
throw new ezcBaseInitInvalidCallbackClassException( $callbackClassname );
}
self::$callbackMap[$identifier] = $callbackClassname;
}
}
/**
* Uses the configured callback belonging to $identifier to configure the $object.
*
* The method will return the return value of the callback method, or null
* in case there was no callback set for the specified $identifier.
*
* @param string $identifier
* @param object $object
* @return mixed
*/
public static function fetchConfig( $identifier, $object )
{
if ( isset( self::$callbackMap[$identifier] ) )
{
$callbackClassname = self::$callbackMap[$identifier];
return call_user_func( array( $callbackClassname, 'configureObject' ), $object );
}
return null;
}
}
?>

View file

@ -0,0 +1,32 @@
<?php
/**
* File containing the ezcBaseConfigurationInitializer class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* This class provides the interface that classes need to implement to act as
* an callback initializer class to work with the delayed initialization
* mechanism.
*
* @package Base
* @version //autogen//
*/
interface ezcBaseConfigurationInitializer
{
/**
* Configures the given object, or returns the proper object depending on
* the given identifier.
*
* In case a string identifier was given, it should return the associated
* object, in case an object was given the method should return null.
*
* @param string|object $object
* @return mixed
*/
static public function configureObject( $object );
}
?>

View file

@ -0,0 +1,40 @@
<?php
/**
* File containing the ezcBasePersistable interface
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* This class provides the interface that classes need to implement to be able
* to be used by the PersistentObject and Search components.
*
* @package Base
* @version //autogen//
*/
interface ezcBasePersistable
{
/**
* The constructor for the object needs to be able to accept no arguments.
*
* The data is later set through the setState() method.
*/
public function __construct();
/**
* Returns all the object's properties so that they can be stored or indexed.
*
* @return array(string=>mixed)
*/
public function getState();
/**
* Accepts an array containing data for one or more of the class' properties.
*
* @param array $properties
*/
public function setState( array $properties );
}
?>

View file

@ -0,0 +1,120 @@
<?php
/**
* File containing the ezcBaseMetaData class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Base class implements ways of fetching information about the installed
* eZ Components. It knows whether to use the PEAR registry or the bundled XML
* file, depending on how eZ Components is installed.
*
* @package Base
* @version //autogentag//
* @mainclass
*/
class ezcBaseMetaData
{
/**
* Creates a ezcBaseMetaData object
*
* The sole parameter $installMethod should only be used if you are really
* sure that you need to use it. It is mostly there to make testing at
* least slightly possible. Again, do not set it unless instructed.
*
* @param string $installMethod
*/
public function __construct( $installMethod = NULL )
{
$installMethod = $installMethod !== NULL ? $installMethod : ezcBase::getInstallMethod();
// figure out which reader to use
switch ( $installMethod )
{
case 'tarball':
$this->reader = new ezcBaseMetaDataTarballReader;
break;
case 'pear':
$this->reader = new ezcBaseMetaDataPearReader;
break;
default:
throw new ezcBaseMetaDataReaderException( "Unknown install method '$installMethod'." );
break;
}
}
/**
* Returns the version string for the installed eZ Components bundle.
*
* A version string such as "2008.2.2" is returned.
*
* @return string
*/
public function getBundleVersion()
{
return $this->reader->getBundleVersion();
}
/**
* Returns a PHP version string that describes the required PHP version for
* this installed eZ Components bundle.
*
* @return string
*/
public function getRequiredPhpVersion()
{
return $this->reader->getRequiredPhpVersion();
}
/**
* Returns whether $componentName is installed
*
* If installed with PEAR, it checks the PEAR registry whether the
* component is there. In case the tarball installation method is used, it
* will return true for every component that exists (because all of them
* are then available).
*
* @return bool
*/
public function isComponentInstalled( $componentName )
{
return $this->reader->isComponentInstalled( $componentName );
}
/**
* Returns the version string of the available $componentName or false when
* the component is not installed.
*
* @return string
*/
public function getComponentVersion( $componentName )
{
return $this->reader->getComponentVersion( $componentName );
}
/**
* Returns a list of components that $componentName depends on.
*
* If $componentName is left empty, all installed components are returned.
*
* The returned array has as keys the component names, and as values the
* version of the components.
*
* @return array(string=>string).
*/
public function getComponentDependencies( $componentName = null )
{
if ( $componentName === null )
{
return $this->reader->getComponentDependencies();
}
else
{
return $this->reader->getComponentDependencies( $componentName );
}
}
}
?>

View file

@ -0,0 +1,129 @@
<?php
/**
* File containing the ezcBaseMetaDataPearReader class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
@require 'PEAR/Registry.php';
/**
* Base class implements ways of fetching information about the installed
* eZ Components when installed as tarball.
*
* Note: there are lots of @ used here, because PEAR still lives in the stone
* age with their PHP 3 code and general liberal use of throwing warnings and
* notices.
*
* @package Base
* @version //autogentag//
* @mainclass
*/
class ezcBaseMetaDataPearReader
{
/**
* Stores the PEAR_Registry to query for information
*
* @var PEAR_Registry
*/
private $registry;
/**
* Creates the reader object and initialized the registry for querying
*/
public function __construct()
{
@$this->registry = new PEAR_Registry;
}
/**
* Returns the version string for the installed eZ Components bundle.
*
* A version string such as "2008.2.2" is returned.
*
* @return string
*/
public function getBundleVersion()
{
@$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
return $packageInfo['version']['release'];
}
/**
* Returns a PHP version string that describes the required PHP version for
* this installed eZ Components bundle.
*
* @return string
*/
public function getRequiredPhpVersion()
{
@$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
if ( array_key_exists( 'required', $packageInfo['dependencies'] ) )
{
return $packageInfo['dependencies']['required']['php']['min'];
}
return $packageInfo['dependencies']['php']['min'];
}
/**
* Returns whether $componentName is installed
*
* Checks the PEAR registry whether the component is there.
*
* @return bool
*/
public function isComponentInstalled( $componentName )
{
@$packageInfo = $this->registry->packageInfo( $componentName, null, 'components.ez.no' );
return is_array( $packageInfo );
}
/**
* Returns the version string of the available $componentName or false when
* the component is not installed.
*
* @return string
*/
public function getComponentVersion( $componentName )
{
@$packageInfo = $this->registry->packageInfo( $componentName, null, 'components.ez.no' );
$release = $packageInfo['version']['release'];
return $release === null ? false : $release;
}
/**
* Returns a list of components that $componentName depends on.
*
* If $componentName is left empty, all installed components are returned.
*
* The returned array has as keys the component names, and as values the
* version of the components.
*
* @return array(string=>string).
*/
public function getComponentDependencies( $componentName = 'ezcomponents' )
{
@$packageInfo = $this->registry->packageInfo( $componentName, 'dependencies', 'components.ez.no' );
if ( isset( $packageInfo['required']['package'] ) )
{
$deps = array();
if ( isset( $packageInfo['required']['package']['name'] ) )
{
$deps[$packageInfo['required']['package']['name']] = $packageInfo['required']['package']['min'];
}
else
{
foreach ( $packageInfo['required']['package'] as $package )
{
$deps[$package['name']] = $package['min'];
}
}
return $deps;
}
return array();
}
}
?>

View file

@ -0,0 +1,153 @@
<?php
/**
* File containing the ezcBaseMetaDataTarballReader class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Base class implements ways of fetching information about the installed
* eZ Components when installed as tarball.
*
* @package Base
* @version //autogentag//
* @mainclass
*/
class ezcBaseMetaDataTarballReader
{
/**
* Contains the handler to the XML file containing the release information.
* @var SimpleXmlElement
*/
private $xml;
/**
* Creates the reader object and opens the release-info file.
*/
public function __construct()
{
$filename = dirname( __FILE__ ) . '/../../../release-info.xml';
$this->xml = simplexml_load_file( $filename );
}
/**
* Returns the version string for the installed eZ Components bundle.
*
* A version string such as "2008.2.2" is returned.
*
* @return string
*/
public function getBundleVersion()
{
return (string) $this->xml->version;
}
/**
* Returns a PHP version string that describes the required PHP version for
* this installed eZ Components bundle.
*
* @return string
*/
public function getRequiredPhpVersion()
{
return (string) $this->xml->deps->php;
}
/**
* Returns whether $componentName is installed
*
* Returns true for every component that exists (because all of them are
* then available).
*
* @return bool
*/
public function isComponentInstalled( $componentName )
{
$root = $this->xml->deps->packages->package;
foreach ( $root as $package )
{
if ( (string) $package['name'] == $componentName )
{
return true;
}
}
return false;
}
/**
* Returns the version string of the available $componentName or false when
* the component is not installed.
*
* @return string
*/
public function getComponentVersion( $componentName )
{
$root = $this->xml->deps->packages->package;
foreach ( $root as $package )
{
if ( (string) $package['name'] == $componentName )
{
return (string) $package['version'];
}
}
return false;
}
/**
* Returns a list of components that $componentName depends on.
*
* If $componentName is left empty, all installed components are returned.
*
* The returned array has as keys the component names, and as values the
* version of the components. It returns null of the $componentName
* is not found.
*
* @return array(string=>string).
*/
public function getComponentDependencies( $componentName = null )
{
$baseVersion = false;
$root = $this->xml->deps->packages;
$found = $componentName === null ? true : false;
// in case $componentName != null, we loop through all the components
// in the file, and figure out the new root that we can list dependency
// packages from.
foreach ( $root->package as $package )
{
if ( (string) $package['name'] == 'Base' )
{
$baseVersion = $package['version'];
}
if ( !$found && (string) $package['name'] == $componentName )
{
$root = $package->deps;
$found = true;
}
}
if ( !$found )
{
return null;
}
// We always add the Base dependency even though it's not in the dependency file.
$deps = array();
$deps['Base'] = (string) $baseVersion;
if ( !isset( $root->package ) )
{
return $deps;
}
foreach ( $root->package as $package )
{
$deps[(string) $package['name']] = (string) $package['version'];
}
return $deps;
}
}
?>

View file

@ -0,0 +1,174 @@
<?php
/**
* File containing the ezcBaseOptions class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Base options class for all eZ components.
*
* @package Base
* @version //autogentag//
*/
abstract class ezcBaseOptions implements ArrayAccess
{
/**
* Container to hold the properties
*
* @var array(string=>mixed)
*/
protected $properties;
/**
* Construct a new options object.
* Options are constructed from an option array by default. The constructor
* automatically passes the given options to the __set() method to set them
* in the class.
*
* @throws ezcBasePropertyNotFoundException
* If trying to access a non existent property.
* @throws ezcBaseValueException
* If the value for a property is out of range.
* @param array(string=>mixed) $options The initial options to set.
*/
public function __construct( array $options = array() )
{
foreach ( $options as $option => $value )
{
$this->__set( $option, $value );
}
}
/**
* Merge an array into the actual options object.
* This method merges an array of new options into the actual options object.
*
* @throws ezcBasePropertyNotFoundException
* If trying to access a non existent property.
* @throws ezcBaseValueException
* If the value for a property is out of range.
* @param array(string=>mixed) $newOptions The new options.
*/
public function merge( array $newOptions )
{
foreach ( $newOptions as $key => $value )
{
$this->__set( $key, $value );
}
}
/**
* Property get access.
* Simply returns a given option.
*
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @param string $propertyName The name of the option to get.
* @return mixed The option value.
* @ignore
*
* @throws ezcBasePropertyNotFoundException
* if the given property does not exist.
* @throws ezcBasePropertyPermissionException
* if the property to be set is a write-only property.
*/
public function __get( $propertyName )
{
if ( $this->__isset( $propertyName ) === true )
{
return $this->properties[$propertyName];
}
throw new ezcBasePropertyNotFoundException( $propertyName );
}
/**
* Sets an option.
* This method is called when an option is set.
*
* @param string $propertyName The name of the option to set.
* @param mixed $propertyValue The option value.
* @ignore
*
* @throws ezcBasePropertyNotFoundException
* if the given property does not exist.
* @throws ezcBaseValueException
* if the value to be assigned to a property is invalid.
* @throws ezcBasePropertyPermissionException
* if the property to be set is a read-only property.
*/
abstract public function __set( $propertyName, $propertyValue );
/**
* Returns if a option exists.
*
* @param string $propertyName Option name to check for.
* @return bool Whether the option exists.
* @ignore
*/
public function __isset( $propertyName )
{
return array_key_exists( $propertyName, $this->properties );
}
/**
* Returns if an option exists.
* Allows isset() using ArrayAccess.
*
* @param string $propertyName The name of the option to get.
* @return bool Whether the option exists.
*/
public function offsetExists( $propertyName )
{
return $this->__isset( $propertyName );
}
/**
* Returns an option value.
* Get an option value by ArrayAccess.
*
* @throws ezcBasePropertyNotFoundException
* If $propertyName is not a key in the $properties array.
* @param string $propertyName The name of the option to get.
* @return mixed The option value.
*/
public function offsetGet( $propertyName )
{
return $this->__get( $propertyName );
}
/**
* Set an option.
* Sets an option using ArrayAccess.
*
* @throws ezcBasePropertyNotFoundException
* If $propertyName is not a key in the $properties array.
* @throws ezcBaseValueException
* If the value for a property is out of range.
* @param string $propertyName The name of the option to set.
* @param mixed $propertyValue The value for the option.
*/
public function offsetSet( $propertyName, $propertyValue )
{
$this->__set( $propertyName, $propertyValue );
}
/**
* Unset an option.
* Unsets an option using ArrayAccess.
*
* @throws ezcBasePropertyNotFoundException
* If $propertyName is not a key in the $properties array.
* @throws ezcBaseValueException
* If a the value for a property is out of range.
* @param string $propertyName The name of the option to unset.
*/
public function offsetUnset( $propertyName )
{
$this->__set( $propertyName, null );
}
}
?>

View file

@ -0,0 +1,75 @@
<?php
/**
* File containing the ezcBaseAutoloadOptions class
*
* @package Base
* @version //autogen//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Class containing the basic options for ezcBase' autoload.
*
* @property bool $preload
* If component preloading is enabled then as soon as one of the
* classes of a component is request, all other classes in the
* component are loaded as well (except for Exception classes).
* @property bool $debug
* If debug is enabled then the autoload method will show exceptions
* when a class can not be found. Because exceptions are ignored by
* PHP in the autoload handler, you have to catch them in autoload()
* yourself and do something with the exception message.
*
* @package Base
* @version //autogen//
*/
class ezcBaseAutoloadOptions extends ezcBaseOptions
{
/**
* Constructs an object with the specified values.
*
* @throws ezcBasePropertyNotFoundException
* if $options contains a property not defined
* @throws ezcBaseValueException
* if $options contains a property with a value not allowed
* @param array(string=>mixed) $options
*/
public function __construct( array $options = array() )
{
$this->preload = false;
$this->debug = false;
parent::__construct( $options );
}
/**
* Sets the option $name to $value.
*
* @throws ezcBasePropertyNotFoundException
* if the property $name is not defined
* @throws ezcBaseValueException
* if $value is not correct for the property $name
* @param string $name
* @param mixed $value
* @ignore
*/
public function __set( $name, $value )
{
switch ( $name )
{
case 'debug':
case 'preload':
if ( !is_bool( $value ) )
{
throw new ezcBaseValueException( $name, $value, 'bool' );
}
$this->properties[$name] = $value;
break;
default:
throw new ezcBasePropertyNotFoundException( $name );
}
}
}
?>

View file

@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcBaseStruct.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Base class for all struct classes.
*
* @package Base
* @version //autogentag//
*/
class ezcBaseStruct
{
/**
* Throws a BasePropertyNotFound exception.
*
* @param string $name
* @param mixed $value
* @ignore
*/
final public function __set( $name, $value )
{
throw new ezcBasePropertyNotFoundException( $name );
}
/**
* Throws a BasePropertyNotFound exception.
*
* @param string $name
* @ignore
*/
final public function __get( $name )
{
throw new ezcBasePropertyNotFoundException( $name );
}
}
?>

View file

@ -0,0 +1,72 @@
<?php
/**
* File containing the ezcBaseFileFindContext class.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Struct which defines the information collected by the file walker for locating files.
*
* @package Base
* @version //autogentag//
*/
class ezcBaseFileFindContext extends ezcBaseStruct
{
/**
* The list of files
*
* @var array(string)
*/
public $elements;
/**
* The number of files
*
* @var int
*/
public $count;
/**
* The total file size of all files found
*
* @var int
*/
public $size;
/**
* Constructs a new ezcBaseFileFindContext with initial values.
*
* @param array(string) $elements
* @param int $count
* @param int $size
*/
public function __construct( $elements = array(), $count = 0, $size = 0 )
{
$this->elements = $elements;
$this->count = $count;
$this->size = $size;
}
/**
* Returns a new instance of this class with the data specified by $array.
*
* $array contains all the data members of this class in the form:
* array('member_name'=>value).
*
* __set_state makes this class exportable with var_export.
* var_export() generates code, that calls this method when it
* is parsed with PHP.
*
* @param array(string=>mixed) $array
* @return ezcBaseFileFindContext
*/
static public function __set_state( array $array )
{
return new ezcBaseFileFindContext( $array['elements'], $array['count'], $array['size'] );
}
}
?>

View file

@ -0,0 +1,83 @@
<?php
/**
* File containing the ezcBaseRepositoryDirectory.
*
* @package Base
* @version //autogentag//
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Struct which defines a repository directory.
*
* @package Base
* @version //autogentag//
*/
class ezcBaseRepositoryDirectory extends ezcBaseStruct
{
/**
* Specifies that the entry is for the eZ Components repository.
*/
const TYPE_INTERNAL = 0;
/**
* Specifies that the entry is for an external (user defined) repository.
*/
const TYPE_EXTERNAL = 1;
/**
* The $type is one of the two TYPE_* constants defined in this class.
*
* @var string
*/
public $type;
/**
* The path to the configured repository.
*
* @var string
*/
public $basePath;
/**
* The path to the autoload files.
*
* @var string
*/
public $autoloadPath;
/**
* Constructs a new ezcBaseRepositoryDirectory of type $type with base path
* $basePath and autoload path $autoloadPath.
*
* @param string $type
* @param string $basePath
* @param string $autoloadPath
*/
public function __construct( $type, $basePath, $autoloadPath )
{
$this->type = $type;
$this->basePath = $basePath;
$this->autoloadPath = $autoloadPath;
}
/**
* Returns a new instance of this class with the data specified by $array.
*
* $array contains all the data members of this class in the form:
* array('member_name'=>value).
*
* __set_state makes this class exportable with var_export.
* var_export() generates code, that calls this method when it
* is parsed with PHP.
*
* @param array(string=>mixed) $array
* @return ezcBaseRepositoryDirectory
*/
static public function __set_state( array $array )
{
return new ezcBaseRepositoryDirectory( $array['type'], $array['basePath'], $array['autoloadPath'] );
}
}
?>