EZ-Components

This commit is contained in:
Andreas Österreicher
2009-02-17 15:27:43 +00:00
parent 359c3c55c9
commit 0a8e90a8b3
572 changed files with 64490 additions and 0 deletions
+16
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
+251
View File
@@ -0,0 +1,251 @@
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.
+2
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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

@@ -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.
@@ -0,0 +1,9 @@
<?php
class erMyClass1
{
function toString()
{
echo "Class 'erMyClass1'\n";
}
}
?>
@@ -0,0 +1,9 @@
<?php
class erMyClass2
{
function toString()
{
echo "Class 'erMyClass2'\n";
}
}
?>
@@ -0,0 +1,9 @@
<?php
class erYourClass1
{
function toString()
{
echo "Class 'erYourClass1'\n";
}
}
?>
@@ -0,0 +1,9 @@
<?php
class erYourClass2
{
function toString()
{
echo "Class 'erYourClass2'\n";
}
}
?>
@@ -0,0 +1,6 @@
<?php
return array (
'erMyClass1' => 'Me/myclass1.php',
'erMyClass2' => 'Me/myclass2.php',
);
?>
@@ -0,0 +1,6 @@
<?php
return array (
'erYourClass1' => 'You/yourclass1.php',
'erYourClass2' => 'You/yourclass2.php',
);
?>
+224
View File
@@ -0,0 +1,224 @@
eZ Components - Base
~~~~~~~~~~~~~~~~~~~~
.. contents:: Table of Contents
Introduction
============
The Base component provides the basic functionality, such as autoloading, that
all eZ Components need to function properly. The Base component needs to be
loaded specifically. Base can also autoload external class repositories from
outside the eZ Components.
Aside from the autoload functionality, the Base component also contains a number of
generic Exception classes that all inherit from the ezcBaseException class.
Installation
============
The installation and configuration of the eZ Components environment is
described in a separate article. Please refer to the `Components Introduction`_
for instructions on installation and configuration of the eZ Components library
and the Base component.
.. _Components Introduction: /docs/install
Usage
=====
Debugging
---------
By default the ezcBase component's autoload mechanism will not throw an
exception when an autoload class can not be found. In some cases (during
development) it is useful to have an exception with detailed information
about which autoload files where search for, and in which directories.
ezcBase supports an option that enables this behavior::
<?php
$options = new ezcBaseAutoloadOptions;
$options->debug = true;
ezcBase::setOptions( $options );
?>
**Warning**: Exceptions are ignored when they are thrown from an autoload()
handler in PHP. In order to see the exception message that is thrown when a
class can not be found, you need to catch the exception *in* the autoload()
handler. Your autoload() function could then look like::
function __autoload( $className )
{
try
{
ezcBase::autoload( $className );
}
catch ( Exception $e )
{
echo $e->getMessage();
}
}
Preloading
----------
The default autoload policy of the eZ Components is to load every class
file on demand only. It is also possible to load all classes of one
component at the same time, when one of the component's classes is
requested for the first time. You can change this behavior with the
"preload" option that is available through the ezcBaseAutoloadOptions option
class. You can turn preloading on with::
<?php
$options = new ezcBaseAutoloadOptions;
$options->preload = true;
ezcBase::setOptions( $options );
?>
Please note that preloading will *not* be done for Exception classes.
Adding class repositories located outside eZ Components to autoload system
--------------------------------------------------------------------------
It can be useful to add repositories of user-defined classes to the eZ
Components autoload system. The ezcBase::addClassRepository() method can be
used to perform this task. You need to arrange the desired external classes
in a class repository. That is, make sure that classes and corresponding
\*_autoload.php files are named and placed according to the explanations below.
After they are in the proper structure, you can call addClassRepository() with
the proper parameters before you use the external classes.
External classes will then be loaded by autoload system.
ezcBase::addClassRepository() takes two arguments:
- $basePath is the base path for the whole class repository.
- $autoloadDirPath is the path where autoload files for this repository are found.
The paths in the autoload files are *not* relative to the package directory
as specified by the $basePath argument. In other words, class definition files will
only be searched for in the location $autoloadDirPath.
Consider the following example:
- There is a class repository stored in the directory "./repos".
- Autoload files for this repository are stored in "./repos/autoloads".
- There are two components in this repository: "Me" and "You".
- The "Me" component has the classes "erMyClass1" and "erMyClass2".
- The "You" component has the classes "erYourClass1" and "erYourClass2".
In this case, you need to create the following files in "./repos/autoloads".
Note that the prefix to _autoload.php ("my" and "your") in the filename is the
first part of the classname (excluding the lowercase classname prefix - "er").
Content of my_autoload.php:
.. include:: repos/autoloads/my_autoload.php
:literal:
Content of your_autoload.php:
.. include:: repos/autoloads/your_autoload.php
:literal:
The directory structure for the external repository is then: ::
./repos/autoloads/my_autoload.php
./repos/autoloads/your_autoload.php
./repos/Me/myclass1.php
./repos/Me/myclass2.php
./repos/You/yourclass1.php
./repos/You/yourclass2.php
To use this repository with the autoload mechanism, use the
following code:
.. include:: tutorial_example_01.php
:literal:
The above code will output: ::
Class 'erMyClass2'
Class 'erYourClass1'
Lazy initialization
-------------------
Lazy initialization is a mechanism to load and configure a component, only
when it is really used in your application. This mechanism saves time for
parsing the classes and configuration, when the component is not used at all
during one request. The implementation in ezcBaseInit may be reused by other
applications and components, like the following example will show.
.. include:: tutorial_lazy_initialization.php
:literal:
The example shows a random class implementing the singleton pattern, which may
be some database connection handler, or anything similar in your case. The
getInstance() method shows a typical PHP 5 implementation except the
additional line 14, which checks, if a configuration callback was provided
earlier and configures the newly created instance. If no configuration
callback was provided, nothing will happen. The customKey is used to receive
the right callback from ezcBaseInit and needs to be known by the user, who
wants to define a configuration callback for your class.
In line 32 the class used to configure your instance on creation is defined.
The first parameter is the key used earlier in the getInstance method, to
reference the right class, and the second parameter is the name of your
configuration class.
The configuration class beginning in line 22 just needs to implement the
ezcBaseConfigurationInitializer interface, which defines one
method: configureObject(). This method will be called with the object to
configure as a single parameter. In the example, a new public property on the
customSingleton instance is created, which will be echo'd later to show the
success of the configuration.
The configuration itself will not happen before the actual instance is created
in line 35 performing the static call on customSingleton::getInstance(). The
var_dump() in the following line shows, that the property value is set and
contains the earlier set value (int) 42.
File Operations
---------------
Finding files recursively
`````````````````````````
This example shows how to use the ezcBaseFile::findRecursive() method:
.. include:: tutorial_example_02.php
:literal:
The code in this example searches for files in the ``/dat/dev/ezcomponents``
directory. It will only include files that match *all* patterns in the
$includeFilters array (the second parameter). Files that match *any* of the
patterns in the $excludeFilters array (the third parameter) will not be returned.
In other words, the code above searches for files in the ``dat/dev/ezcomponents``
directory, which are in the ``src/`` directory and end with ``_autoload.php``,
except for files that are in the ``/autoload/`` directory.
Removing directories recursively
````````````````````````````````
This example shows how to use the ezcBaseFile::removeRecursive() method:
.. include:: tutorial_example_03.php
:literal:
This code simply removes the directory ``/dat/dev/ezcomponents/trash`` and all
of its files and sub-directories.
**Warning: Use this function with care, as it has the potential to erase
everything that the current user has access to.**
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,20 @@
<?php
$dir = dirname( __FILE__ );
$dirParts = explode( '/', $dir );
switch ( $dirParts[count( $dirParts ) - 3] )
{
case 'doc': require_once 'ezc/Base/base.php'; break; // pear
case 'trunk': require_once "$dir/../../Base/src/base.php"; break; // svn
default: require_once "$dir/../../Base/src/base.php"; break; // bundle
}
/**
* Autoload ezc classes
*
* @param string $className
*/
function __autoload( $className )
{
ezcBase::autoload( $className );
}
?>
@@ -0,0 +1,9 @@
<?php
require_once 'tutorial_autoload.php';
ezcBase::addClassRepository( './repos', './repos/autoloads' );
$myVar1 = new erMyClass2();
$myVar1->toString();
$yourVar1 = new erYourClass1();
$yourVar1->toString();
?>
@@ -0,0 +1,11 @@
<?php
require 'tutorial_autoload.php';
$data = ezcBaseFile::findRecursive(
"/dat/dev/ezcomponents",
array( '@src/.*_autoload.php$@' ),
array( '@/autoload/@' )
);
var_dump( $data );
?>
@@ -0,0 +1,6 @@
<?php
require 'tutorial_autoload.php';
ezcBaseFile::removeRecursive( '/dat/dev/ezcomponents/trash' );
?>
@@ -0,0 +1,38 @@
<?php
require_once 'tutorial_autoload.php';
// Create a custom class implementing the singleton pattern
class customSingleton
{
protected static $instance;
public static function getInstance()
{
if ( self::$instance === null )
{
self::$instance = new customSingleton();
ezcBaseInit::fetchConfig( 'customKey', self::$instance );
}
return self::$instance;
}
}
// Implement your configuration class
class customSingletonConfiguration implements ezcBaseConfigurationInitializer
{
public static function configureObject( customSingleton $object )
{
echo "Configure customSingleton.\n";
$object->value = 42;
}
}
// Register for lazy initilization
ezcBaseInit::setCallback( 'customKey', 'customSingletonConfiguration' );
// Configure on first initilization
$object = customSingleton::getInstance();
var_dump( $object->value );
?>
+23
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.
+592
View File
@@ -0,0 +1,592 @@
<?php
/**
* File containing the ezcBase class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
* @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";
/**
* Indirectly it determines the path where the autoloads are stored.
*
* @var string
*/
private static $libraryMode = "tarball";
/**
* 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;
/**
* 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;
}
}
?>
@@ -0,0 +1,38 @@
<?php
/**
* File containing the ezcBaseAutoloadException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 ) );
}
}
?>
@@ -0,0 +1,34 @@
<?php
/**
* File containing the ezcBaseDoubleClassRepositoryPrefixException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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}'." );
}
}
?>
@@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseException class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 ) );
}
}
}
?>
@@ -0,0 +1,38 @@
<?php
/**
* File containing the ezcBaseExtensionNotFoundException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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}" );
}
}
}
?>
@@ -0,0 +1,25 @@
<?php
/**
* File containing the ezcBaseFileException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
abstract class ezcBaseFileException extends ezcBaseException
{
const READ = 1;
const WRITE = 2;
const EXECUTE = 4;
const CHANGE = 8;
const REMOVE = 16;
}
?>
@@ -0,0 +1,50 @@
<?php
/**
* File containing the ezcBaseFileIoException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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" );
}
}
?>
@@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseFileNotFoundException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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" );
}
}
?>
@@ -0,0 +1,63 @@
<?php
/**
* File containing the ezcBaseFilePermissionException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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" );
}
}
?>
@@ -0,0 +1,31 @@
<?php
/**
* File containing the ezcBaseInitCallbackConfiguredException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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}'." );
}
}
?>
@@ -0,0 +1,31 @@
<?php
/**
* File containing the ezcBaseInitInvalidCallbackClassException class
*
* @package Configuration
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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." );
}
}
?>
@@ -0,0 +1,29 @@
<?php
/**
* File containing the ezcBaseInvalidParentClassException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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." );
}
}
?>
@@ -0,0 +1,30 @@
<?php
/**
* File containing the ezcBasePropertyNotFoundException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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}'." );
}
}
?>
@@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcPropertyReadOnlyException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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." );
}
}
?>
@@ -0,0 +1,29 @@
<?php
/**
* File containing the ezcBaseSettingNotFoundException class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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." );
}
}
?>
@@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcBaseSettingValueException class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
}
?>
@@ -0,0 +1,43 @@
<?php
/**
* File containing the ezcBaseValueException class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
}
?>
@@ -0,0 +1,40 @@
<?php
/**
* File containing the ezcBaseWhateverException class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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." );
}
}
?>
@@ -0,0 +1,39 @@
<?php
/**
* Include file that can be used for a quick setup of the eZ Components.
*
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
*/
$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 );
}
?>
+329
View File
@@ -0,0 +1,329 @@
<?php
/**
* File containing the ezcBaseFeatures class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 = $_ENV['PATH'];
if ( strlen( trim( $envPath ) ) == 0 )
{
$envPath = false;
}
}
else
{
$envPath = false;
}
switch ( self::os() )
{
case 'Unix':
case 'FreeBSD':
case 'Mac':
case 'MacOS':
case 'Darwin':
case 'Linux':
if ( $envPath )
{
$dirs = explode( ':', $envPath );
foreach ( $dirs as $dir )
{
if ( file_exists( "{$dir}/{$fileName}" ) )
{
return "{$dir}/{$fileName}";
}
}
}
elseif ( file_exists( "./{$fileName}" ) )
{
return $fileName;
}
break;
case 'Windows':
if ( $envPath )
{
$dirs = explode( ';', $envPath );
foreach ( $dirs as $dir )
{
if ( file_exists( "{$dir}\\{$fileName}.exe" ) )
{
return "{$dir}\\{$fileName}.exe";
}
}
}
elseif ( file_exists( "{$fileName}.exe" ) )
{
return "{$fileName}.exe";
}
break;
}
return null;
}
}
?>
+377
View File
@@ -0,0 +1,377 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @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 1.5
* @mainclass
*/
class ezcBaseFile
{
/**
* 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.
*
* 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 )
{
if ( !is_dir( $sourceDir ) )
{
throw new ezcBaseFileNotFoundException( $sourceDir, 'directory' );
}
$elements = array();
$d = @dir( $sourceDir );
if ( !$d )
{
throw new ezcBaseFilePermissionException( $sourceDir, ezcBaseFileException::READ );
}
// init statistics array
if ( !is_array( $statistics ) || !array_key_exists( 'size', $statistics ) || !array_key_exists( 'count', $statistics ) )
{
$statistics['size'] = 0;
$statistics['count'] = 0;
}
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
{
$subList = self::findRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry, $includeFilters, $excludeFilters, $statistics );
$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 ( $ok )
{
$elements[] = $sourceDir . DIRECTORY_SEPARATOR . $entry;
$statistics['count']++;
$statistics['size'] += $fileInfo['size'];
}
}
}
sort( $elements );
return $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 );
}
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 ) )
{
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.
* 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 );
$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 ) );
$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();
}
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;
}
}
?>
+125
View File
@@ -0,0 +1,125 @@
<?php
/**
* File containing the ezcBaseInit class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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;
}
}
?>
@@ -0,0 +1,30 @@
<?php
/**
* File containing the ezcBaseConfigurationInitializer class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
interface ezcBaseConfigurationInitializer
{
/**
* Sets the options for the writer.
*
* The options will be used the next time the save() method is called. The
* $options array is an associative array with the options for the writer.
* It depends on the specific writer which options are allowed here.
*
* @param array $options
*/
static public function configureObject( $options );
}
?>
@@ -0,0 +1,40 @@
<?php
/**
* File containing the ezcBasePersistable interface
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
?>
+174
View File
@@ -0,0 +1,174 @@
<?php
/**
* File containing the ezcBaseOptions class.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
}
?>
@@ -0,0 +1,75 @@
<?php
/**
* File containing the ezcBaseAutoloadOptions class
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
}
}
?>
+42
View File
@@ -0,0 +1,42 @@
<?php
/**
* File containing the ezcBaseStruct.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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 );
}
}
?>
@@ -0,0 +1,83 @@
<?php
/**
* File containing the ezcBaseRepositoryDirectory.
*
* @package Base
* @version 1.5
* @copyright Copyright (C) 2005-2008 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 1.5
*/
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'] );
}
}
?>
@@ -0,0 +1,81 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
require_once 'init/base_init_callback.php';
require_once 'init/base_init_class.php';
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseInitTest extends ezcTestCase
{
public function setUp()
{
testBaseInitClass::$instance = null;
}
public function testCallbackWithClassThatDoesNotExists()
{
try
{
ezcBaseInit::setCallback( 'testBaseInit', 'classDoesNotExist' );
$this->fail( "Expected exception not thrown." );
}
catch ( ezcBaseInitInvalidCallbackClassException $e )
{
$this->assertEquals( "Class 'classDoesNotExist' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
}
}
public function testCallbackWithClassThatDoesNotImplementTheInterface()
{
try
{
ezcBaseInit::setCallback( 'testBaseInit', 'ezcBaseFeatures' );
$this->fail( "Expected exception not thrown." );
}
catch ( ezcBaseInitInvalidCallbackClassException $e )
{
$this->assertEquals( "Class 'ezcBaseFeatures' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
}
}
public function testCallback1()
{
$obj = testBaseInitClass::getInstance();
$this->assertEquals( false, $obj->configured );
}
public function testCallback2()
{
ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
$obj = testBaseInitClass::getInstance();
$this->assertEquals( true, $obj->configured );
}
public function testCallback3()
{
try
{
ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
$this->fail( "Expected exception not thrown." );
}
catch ( ezcBaseInitCallbackConfiguredException $e )
{
$this->assertEquals( "The 'testBaseInit' is already configured with callback class 'testBaseInitCallback'.", $e->getMessage() );
}
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite("ezcBaseInitTest");
}
}
?>
@@ -0,0 +1,129 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
require_once dirname( __FILE__ ) . '/test_options.php';
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseOptionsTest extends ezcTestCase
{
public static function suite()
{
return new PHPUnit_Framework_TestSuite("ezcBaseOptionsTest");
}
public function testGetAccessFailure()
{
$opt = new ezcBaseTestOptions();
try
{
echo $opt->properties;
}
catch ( ezcBasePropertyNotFoundException $e )
{
return;
}
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
}
public function testGetOffsetAccessFailure()
{
$opt = new ezcBaseTestOptions();
try
{
echo $opt["properties"];
}
catch ( ezcBasePropertyNotFoundException $e )
{
return;
}
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
}
public function testSetOffsetAccessFailure()
{
$opt = new ezcBaseTestOptions();
try
{
$opt["properties"] = "foo";
}
catch ( ezcBasePropertyNotFoundException $e )
{
return;
}
$this->fail( "ezcBasePropertyNotFoundException not thrown on access to forbidden property \$properties" );
}
public function testConstructorWithParameters()
{
$options = new ezcBaseTestOptions( array( 'foo' => 'xxx' ) );
$this->assertEquals( 'xxx', $options->foo );
}
public function testMerge()
{
$options = new ezcBaseTestOptions();
$this->assertEquals( 'bar', $options->foo );
$options->merge( array( 'foo' => 'xxx' ) );
$this->assertEquals( 'xxx', $options->foo );
}
public function testOffsetExists()
{
$options = new ezcBaseTestOptions();
$this->assertEquals( true, $options->offsetExists( 'foo' ) );
$this->assertEquals( false, $options->offsetExists( 'bar' ) );
}
public function testOffsetSet()
{
$options = new ezcBaseTestOptions();
$this->assertEquals( 'bar', $options->foo );
$options->offsetSet( 'foo', 'xxx' );
$this->assertEquals( 'xxx', $options->foo );
}
public function testOffsetUnset()
{
$options = new ezcBaseTestOptions();
$this->assertEquals( 'bar', $options->foo );
$options->offsetUnset( 'foo' );
$this->assertEquals( null, $options->foo );
$this->assertEquals( true, $options->offsetExists( 'foo' ) );
}
public function testAutoloadOptions()
{
$options = new ezcBaseAutoloadOptions();
try
{
$options->no_such_property = 'value';
$this->fail( 'Expected exception was not thrown.' );
}
catch ( ezcBasePropertyNotFoundException $e )
{
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
}
try
{
$options->preload = 'wrong value';
$this->fail( 'Expected exception was not thrown.' );
}
catch ( ezcBaseValueException $e )
{
$this->assertEquals( "The value 'wrong value' that you were trying to assign to setting 'preload' is invalid. Allowed values are: bool.", $e->getMessage() );
}
}
}
?>
@@ -0,0 +1,497 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseTest extends ezcTestCase
{
/*
* For use with the method testInvalidClass().
*/
private $errorMessage = null;
public function testConfigExceptionUnknownSetting()
{
try
{
throw new ezcBaseSettingNotFoundException( 'broken' );
}
catch ( ezcBaseSettingNotFoundException $e )
{
$this->assertEquals( "The setting 'broken' is not a valid configuration setting.", $e->getMessage() );
}
}
public function testConfigExceptionOutOfRange1()
{
try
{
throw new ezcBaseSettingValueException( 'broken', 42 );
}
catch ( ezcBaseSettingValueException $e )
{
$this->assertEquals( "The value '42' that you were trying to assign to setting 'broken' is invalid.", $e->getMessage() );
}
}
public function testConfigExceptionOutOfRange2()
{
try
{
throw new ezcBaseSettingValueException( 'broken', 42, "int, 40 - 48" );
}
catch ( ezcBaseSettingValueException $e )
{
$this->assertEquals( "The value '42' that you were trying to assign to setting 'broken' is invalid. Allowed values are: int, 40 - 48", $e->getMessage() );
}
}
public function testConfigExceptionOutOfRange3()
{
try
{
throw new ezcBaseSettingValueException( 'broken', array(1, 1, 3, 4, 5), 'int' );
}
catch ( ezcBaseSettingValueException $e )
{
$this->assertEquals( "The value 'a:5:{i:0;i:1;i:1;i:1;i:2;i:3;i:3;i:4;i:4;i:5;}' that you were trying to assign to setting 'broken' is invalid. Allowed values are: int", $e->getMessage() );
}
}
public function testFileIoException1()
{
try
{
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::READ );
}
catch ( ezcBaseFileIoException $e )
{
$this->assertEquals( "An error occurred while reading from 'testfile.php'.", $e->getMessage() );
}
}
public function testFileIoException2()
{
try
{
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::WRITE );
}
catch ( ezcBaseFileIoException $e )
{
$this->assertEquals( "An error occurred while writing to 'testfile.php'.", $e->getMessage() );
}
}
public function testFileIoException3()
{
try
{
throw new ezcBaseFileIoException( 'testfile.php', ezcBaseFileException::WRITE, "Extra extra" );
}
catch ( ezcBaseFileIoException $e )
{
$this->assertEquals( "An error occurred while writing to 'testfile.php'. (Extra extra)", $e->getMessage() );
}
}
public function testFileNotFoundException1()
{
try
{
throw new ezcBaseFileNotFoundException( 'testfile.php' );
}
catch ( ezcBaseFileNotFoundException $e )
{
$this->assertEquals( "The file 'testfile.php' could not be found.", $e->getMessage() );
}
}
public function testFileNotFoundException2()
{
try
{
throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI' );
}
catch ( ezcBaseFileNotFoundException $e )
{
$this->assertEquals( "The INI file 'testfile.php' could not be found.", $e->getMessage() );
}
}
public function testFileNotFoundException3()
{
try
{
throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI', "Extra extra" );
}
catch ( ezcBaseFileNotFoundException $e )
{
$this->assertEquals( "The INI file 'testfile.php' could not be found. (Extra extra)", $e->getMessage() );
}
}
public function testFilePermissionException1()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::READ );
}
catch ( ezcBaseFilePermissionException $e )
{
$this->assertEquals( "The file 'testfile.php' can not be opened for reading.", $e->getMessage() );
}
}
public function testFilePermissionException2()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::WRITE );
}
catch ( ezcBaseFileException $e )
{
$this->assertEquals( "The file 'testfile.php' can not be opened for writing.", $e->getMessage() );
}
}
public function testFilePermissionException3()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFileException::EXECUTE );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The file 'testfile.php' can not be executed.", $e->getMessage() );
}
}
public function testFilePermissionException4()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::CHANGE, "Extra extra" );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The permissions for 'testfile.php' can not be changed. (Extra extra)", $e->getMessage() );
}
}
public function testFilePermissionException5()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::READ | ezcBaseFilePermissionException::WRITE, "Extra extra" );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The file 'testfile.php' can not be opened for reading and writing. (Extra extra)", $e->getMessage() );
}
}
public function testFilePermissionException6()
{
try
{
throw new ezcBaseFilePermissionException( 'testfile.php', ezcBaseFilePermissionException::REMOVE, "Extra extra" );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The file 'testfile.php' can not be removed. (Extra extra)", $e->getMessage() );
}
}
public function testPropertyNotFoundException()
{
try
{
throw new ezcBasePropertyNotFoundException( 'broken' );
}
catch ( ezcBasePropertyNotFoundException $e )
{
$this->assertEquals( "No such property name 'broken'.", $e->getMessage() );
}
}
public function testPropertyPermissionException1()
{
try
{
throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::READ );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The property 'broken' is read-only.", $e->getMessage() );
}
}
public function testPropertyPermissionException2()
{
try
{
throw new ezcBasePropertyPermissionException( 'broken', ezcBasePropertyPermissionException::WRITE );
}
catch ( ezcBaseException $e )
{
$this->assertEquals( "The property 'broken' is write-only.", $e->getMessage() );
}
}
public function testBaseValue1()
{
try
{
throw new ezcBaseValueException( 'broken', array( 42 ) );
}
catch ( ezcBaseValueException $e )
{
$this->assertEquals( "The value 'a:1:{i:0;i:42;}' that you were trying to assign to setting 'broken' is invalid.", $e->getMessage() );
}
}
public function testBaseValue2()
{
try
{
throw new ezcBaseValueException( 'broken', "string", "strings" );
}
catch ( ezcBaseValueException $e )
{
$this->assertEquals( "The value 'string' that you were trying to assign to setting 'broken' is invalid. Allowed values are: strings.", $e->getMessage() );
$this->assertEquals( "The value 'string' that you were trying to assign to setting 'broken' is invalid. Allowed values are: strings.", $e->originalMessage );
}
}
public function testExtraDirNotFoundException()
{
try
{
ezcBase::addClassRepository( 'wrongDir' );
}
catch ( ezcBaseFileNotFoundException $e )
{
$this->assertEquals( "The base directory file 'wrongDir' could not be found.", $e->getMessage() );
}
}
public function testExtraDirBaseNotFoundException()
{
try
{
ezcBase::addClassRepository( '.', './wrongAutoloadDir' );
}
catch ( ezcBaseFileNotFoundException $e )
{
$this->assertEquals( "The autoload directory file './wrongAutoloadDir' could not be found.", $e->getMessage() );
}
}
public function testBaseAddAndGetAutoloadDirs1()
{
ezcBase::addClassRepository( '.' );
$resultArray = ezcBase::getRepositoryDirectories();
if ( count( $resultArray ) != 2 )
{
$this->fail( "Duplicating or missing extra autoload dirs while adding." );
}
if ( !isset( $resultArray['ezc'] ) )
{
$this->fail( "No packageDir found in result of getRepositoryDirectories()" );
}
if ( !isset( $resultArray[0] ) || $resultArray[0]->basePath != getcwd() )
{
$this->fail( "Extra base dir '{$resultArray[0]->basePath}' is added incorrectly" );
}
if ( !isset( $resultArray[0] ) || $resultArray[0]->autoloadPath != getcwd() . '/autoload' )
{
$this->fail( "Extra autoload dir '{$resultArray[0]->autoloadPath}' is added incorrectly" );
}
}
// this test is sorta obsolete, but we keep it around for good measure
public function testBaseAddAndGetAutoloadDirs2()
{
ezcBase::addClassRepository( '.', './autoload' );
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
$resultArray = ezcBase::getRepositoryDirectories();
if ( count( $resultArray ) != 5 )
{
$this->fail( "Duplicating or missing extra autoload dirs while adding." );
}
if ( !isset( $resultArray['ezc'] ) )
{
$this->fail( "No packageDir found in result of getRepositoryDirectories()" );
}
if ( !isset( $resultArray[2] ) || $resultArray[2]->autoloadPath != getcwd() . '/Base/tests/test_repository/autoload_files' )
{
$this->fail( "Extra autoload dir '{$resultArray[2]->autoloadPath}' is added incorrectly" );
}
self::assertEquals( true, class_exists( 'trBasetestClass', true ) );
self::assertEquals( true, class_exists( 'trBasetestClass2', true ) );
try
{
self::assertEquals( false, class_exists( 'trBasetestClass3', true ) );
self::fail( 'The expected exception was not thrown.' );
}
catch ( ezcBaseAutoloadException $e )
{
$cwd = getcwd();
self::assertEquals( "Could not find a class to file mapping for 'trBasetestClass3'. Searched for basetest_class3_autoload.php, basetest_autoload.php, autoload.php in: $cwd/autoload, $cwd/autoload, $cwd/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files", $e->getMessage() );
}
self::assertEquals( true, class_exists( 'trBasetestLongClass', true ) );
try
{
class_exists( 'trBasetestClass4', true );
self::fail( 'The expected exception was not thrown.' );
}
catch ( ezcBaseFileNotFoundException $e )
{
self::assertEquals( "The file './Base/tests/test_repository/TestClasses/base_test_class_number_four.php' could not be found.", $e->getMessage() );
}
}
public function testBaseAddAndGetAutoloadDirs3()
{
ezcBase::addClassRepository( './Base/tests/extra_repository', null, 'ext' );
$resultArray = ezcBase::getRepositoryDirectories();
self::assertEquals( true, array_key_exists( 'ezc', $resultArray ) );
self::assertEquals( true, array_key_exists( 'ext', $resultArray ) );
self::assertEquals( true, class_exists( 'extTranslationTest', true ) );
self::assertEquals( true, class_exists( 'ezcTranslationTsBackend', true ) );
}
public function testBaseAddAndGetAutoloadDirs4()
{
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files', 'tr' );
try
{
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files', 'tr' );
}
catch ( ezcBaseDoubleClassRepositoryPrefixException $e )
{
self::assertEquals( "The class repository in './Base/tests/test_repository' (with autoload dir './Base/tests/test_repository/autoload_files') can not be added because another class repository already uses the prefix 'tr'.", $e->getMessage() );
}
$resultArray = ezcBase::getRepositoryDirectories();
self::assertEquals( 7, count( $resultArray ) );
self::assertEquals( true, array_key_exists( 'ezc', $resultArray ) );
self::assertEquals( true, array_key_exists( 'tr', $resultArray ) );
self::assertEquals( getcwd() . '/Base/tests/test_repository', $resultArray['tr']->basePath );
self::assertEquals( getcwd() . '/Base/tests/test_repository/autoload_files', $resultArray['tr']->autoloadPath );
}
public function testNoPrefixAutoload()
{
ezcBase::addClassRepository( './Base/tests/test_repository', './Base/tests/test_repository/autoload_files' );
__autoload( 'Object' );
if ( !class_exists( 'Object' ) )
{
$this->fail( "Autoload does not handle classes with no prefix" );
}
}
public function testCheckDependencyExtension()
{
ezcBase::checkDependency( 'Tester', ezcBase::DEP_PHP_EXTENSION, 'standard' );
}
public function testCheckDependencyVersion()
{
ezcBase::checkDependency( 'Tester', ezcBase::DEP_PHP_VERSION, '5.1.1' );
}
public function testInvalidClass()
{
try
{
self::assertEquals( false, class_exists( 'ezcNoSuchClass', true ) );
self::fail( 'The expected exception was not thrown.' );
}
catch ( ezcBaseAutoloadException $e )
{
$cwd = getcwd();
self::assertEquals( "Could not find a class to file mapping for 'ezcNoSuchClass'. Searched for no_such_autoload.php, no_autoload.php, autoload.php in: $cwd/autoload, $cwd/autoload, $cwd/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/extra_repository/autoload, $cwd/Base/tests/test_repository/autoload_files, $cwd/Base/tests/test_repository/autoload_files", $e->getMessage() );
}
}
public function testDebug()
{
try
{
class_exists( 'ezcTestingOne' );
self::fail( "There should have been an exception" );
}
catch ( ezcBaseAutoloadException $e )
{
}
}
public function testNoDebug()
{
try
{
$options = new ezcBaseAutoloadOptions;
$options->debug = false;
ezcBase::setOptions( $options );
class_exists( 'ezcTestingOne' );
}
catch ( Exception $e )
{
self::fail( "There should not have been an exception" );
}
}
public function testGetInstallationPath()
{
$path = ezcBase::getInstallationPath();
$pathParts = explode( DIRECTORY_SEPARATOR, $path );
self::assertEquals( array( 'trunk', '' ), array_splice( $pathParts, -2 ) );
self::assertEquals( DIRECTORY_SEPARATOR, substr( $path, -1 ) );
}
public function setup()
{
$options = new ezcBaseAutoloadOptions;
$options->debug = true;
ezcBase::setOptions( $options );
}
public function teardown()
{
$options = new ezcBaseAutoloadOptions;
$options->debug = true;
ezcBase::setOptions( $options );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite("ezcBaseTest");
}
}
?>
@@ -0,0 +1,5 @@
<?php
class extTranslationTest
{
}
?>
@@ -0,0 +1,5 @@
<?php
return array(
'extTranslationTest' => 'Translation/test.php',
);
?>
@@ -0,0 +1,145 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFeaturesTest extends ezcTestCase
{
protected function setUp()
{
$uname = php_uname( 's' );
if ( substr( $uname, 0, 7 ) == 'Windows' )
{
$this->markTestSkipped( 'Unix tests' );
}
}
public function testSupportsLink()
{
$this->assertEquals( true, ezcBaseFeatures::supportsLink() );
}
public function testSupportsSymLink()
{
$this->assertEquals( true, ezcBaseFeatures::supportsSymLink() );
}
public function testSupportsUserId()
{
$this->assertEquals( true, ezcBaseFeatures::supportsUserId() );
}
/* // Need to find a way to make this test work, as setting global enviroment variables
// is not working (putenv( "PATH=" ) doesn't unset $_ENV["PATH"])
// One solution would be to use in the ezcBaseFeatures::getPath():
// getenv( 'PATH' ) instead of $_ENV['PATH'] (but that won't work under IIS).
public function testHasImageIdentifyNoPath()
{
$envPath = getenv( 'PATH' );
putenv( "PATH=" );
$this->assertEquals( false, ezcBaseFeatures::hasImageIdentify() );
putenv( "PATH={$envPath}" );
}
*/
public function testHasImageConvert()
{
$this->assertEquals( true, ezcBaseFeatures::hasImageConvert() );
}
public function testGetImageConvertExecutable()
{
$this->assertEquals( '/usr/bin/convert', ezcBaseFeatures::getImageConvertExecutable() );
}
public function testGetImageIdentifyExecutable()
{
$this->assertEquals( '/usr/bin/identify', ezcBaseFeatures::getImageIdentifyExecutable() );
}
public function testHasImageIdentify()
{
$this->assertEquals( true, ezcBaseFeatures::hasImageIdentify() );
}
public function testHasExtensionSupport1()
{
$this->assertEquals( true, ezcBaseFeatures::hasExtensionSupport( 'standard' ) );
}
public function testHasExtensionSupportNotFound1()
{
$this->assertEquals( false, ezcBaseFeatures::hasExtensionSupport( 'non_existent_extension' ) );
try
{
throw new ezcBaseExtensionNotFoundException( 'non_existent_extension', null, 'This is just a test.' );
}
catch ( ezcBaseExtensionNotFoundException $e )
{
$this->assertEquals( "The extension 'non_existent_extension' could not be found. This is just a test.",
$e->getMessage() );
}
}
public function testHasExtensionSupportNotFound2()
{
$this->assertEquals( false, ezcBaseFeatures::hasExtensionSupport( 'non_existent_extension' ) );
try
{
throw new ezcBaseExtensionNotFoundException( 'non_existent_extension', '1.2', 'This is just a test.' );
}
catch ( ezcBaseExtensionNotFoundException $e )
{
$this->assertEquals( "The extension 'non_existent_extension' with version '1.2' could not be found. This is just a test.",
$e->getMessage() );
}
}
public function testHasFunction1()
{
$this->assertEquals( true, ezcBaseFeatures::hasFunction( 'function_exists' ) );
}
public function testHasFunction2()
{
$this->assertEquals( false, ezcBaseFeatures::hasFunction( 'non_existent_function_in_php' ) );
}
public function testHasExtensionSupport2()
{
$this->assertEquals( true, ezcBaseFeatures::hasExtensionSupport( 'date', '5.1.0' ) );
}
public function testClassExists()
{
$this->assertEquals( true, ezcBaseFeatures::classExists( 'Exception', false ) );
}
public function testClassExistsAutoload()
{
$this->assertEquals( true, ezcBaseFeatures::classExists( 'ezcBaseFeatures' ) );
}
public function testClassExistsNotFound()
{
$this->assertEquals( false, ezcBaseFeatures::classExists( 'ezcBaseNonExistingClass', false ) );
}
public function testClassExistsNotFoundAutoload()
{
$this->assertEquals( false, ezcBaseFeatures::classExists( 'ezcBaseNonExistingClass' ) );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite("ezcBaseFeaturesTest");
}
}
?>
@@ -0,0 +1,67 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
* @subpackage Tests
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFileCalculateRelativePathTest extends ezcTestCase
{
public function testRelative1()
{
$result = ezcBaseFile::calculateRelativePath( 'C:/foo/1/2/php.php', 'C:/foo/bar' );
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:/foo/bar/php.php', 'C:/foo/bar' );
self::assertEquals( 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:/php.php', 'C:/foo/bar/1/2');
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:/bar/php.php', 'C:/foo/bar/1/2');
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
}
public function testRelative2()
{
$result = ezcBaseFile::calculateRelativePath( 'C:\\foo\\1\\2\\php.php', 'C:\\foo\\bar' );
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:\\foo\\bar\\php.php', 'C:\\foo\\bar' );
self::assertEquals( 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:\\php.php', 'C:\\foo\\bar\\1\\2');
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( 'C:\\bar\\php.php', 'C:\\foo\\bar\\1\\2');
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
}
public function testRelative3()
{
$result = ezcBaseFile::calculateRelativePath( '/foo/1/2/php.php', '/foo/bar' );
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '1' . DIRECTORY_SEPARATOR . '2' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( '/foo/bar/php.php', '/foo/bar' );
self::assertEquals( 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( '/php.php', '/foo/bar/1/2');
self::assertEquals( '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php.php', $result );
$result = ezcBaseFile::calculateRelativePath( '/bar/php.php', '/foo/bar/1/2');
self::assertEquals('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'php.php', $result);
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcBaseFileCalculateRelativePathTest" );
}
}
?>
@@ -0,0 +1,234 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
* @subpackage Tests
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFileCopyRecursiveTest extends ezcTestCase
{
protected function setUp()
{
$this->tempDir = $this->createTempDir( __CLASS__ );
mkdir( $this->tempDir . '/dir1' );
mkdir( $this->tempDir . '/dir2' );
mkdir( $this->tempDir . '/dir2/dir1' );
mkdir( $this->tempDir . '/dir2/dir1/dir1' );
mkdir( $this->tempDir . '/dir2/dir2' );
mkdir( $this->tempDir . '/dir4' );
mkdir( $this->tempDir . '/dir5' );
mkdir( $this->tempDir . '/dir6' );
file_put_contents( $this->tempDir . '/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir1/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir1/.file3.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir2/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir4/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir4/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir5/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir5/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir6/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir6/file2.txt', 'test' );
chmod( $this->tempDir . '/dir4/file1.txt', 0 );
chmod( $this->tempDir . '/dir5', 0 );
chmod( $this->tempDir . '/dir6', 0400 );
}
protected function tearDown()
{
chmod( $this->tempDir . '/dir5', 0700 );
chmod( $this->tempDir . '/dir6', 0700 );
$this->removeTempDir();
}
public function testRecursiveCopyEmptyDir()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir1',
$this->tempDir . '/dest'
);
$this->assertEquals(
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir1' ) ),
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
);
$this->assertSame(
0775,
fileperms( $this->tempDir . '/dest' ) & 0777,
'Directory mode should equal 0775.'
);
}
public function testRecursiveCopyFile()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir1/file1.txt',
$this->tempDir . '/dest'
);
$this->assertTrue(
is_file( $this->tempDir . '/dest' )
);
$this->assertSame(
0664,
fileperms( $this->tempDir . '/dest' ) & 0777,
'File mode should equal 0664.'
);
}
public function testRecursiveCopyEmptyDirMode()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir1',
$this->tempDir . '/dest',
-1,
0777,
0777
);
$this->assertEquals(
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir1' ) ),
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
);
$this->assertSame(
0777,
fileperms( $this->tempDir . '/dest' ) & 0777,
'Directory mode should equal 0777.'
);
}
public function testRecursiveCopyFileMode()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir1/file1.txt',
$this->tempDir . '/dest',
-1,
0777,
0777
);
$this->assertTrue(
is_file( $this->tempDir . '/dest' )
);
$this->assertSame(
0777,
fileperms( $this->tempDir . '/dest' ) & 0777,
'File mode should equal 0777.'
);
}
public function testRecursiveCopyFullDir()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir2',
$this->tempDir . '/dest'
);
$this->assertEquals(
count( ezcBaseFile::findRecursive( $this->tempDir . '/dir2' ) ),
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
);
}
public function testRecursiveCopyFullDirDepthZero()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir2',
$this->tempDir . '/dest',
0
);
$this->assertEquals(
0,
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
);
$this->assertTrue(
is_dir( $this->tempDir . '/dest' )
);
}
public function testRecursiveCopyFullDirLimitedDepth()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir2',
$this->tempDir . '/dest',
2
);
$this->assertEquals(
3,
count( ezcBaseFile::findRecursive( $this->tempDir . '/dest' ) )
);
}
public function testRecursiveCopyFailureNotExisting()
{
try
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/not_existing',
$this->tempDir . '/dest'
);
}
catch ( ezcBaseFileNotFoundException $e )
{
return;
}
$this->fail( 'Expected ezcBaseFileNotFoundException.' );
}
public function testRecursiveCopyFailureNotReadable()
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir5',
$this->tempDir . '/dest'
);
$this->assertFalse(
is_dir( $this->tempDir . '/dest' )
);
$this->assertFalse(
is_file( $this->tempDir . '/dest' )
);
}
public function testRecursiveCopyFailureNotWriteable()
{
try
{
ezcBaseFile::copyRecursive(
$this->tempDir . '/dir2',
$this->tempDir . '/dir4'
);
}
catch ( ezcBaseFilePermissionException $e )
{
return;
}
$this->fail( 'Expected ezcBaseFilePermissionException.' );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( __CLASS__ );
}
}
?>
@@ -0,0 +1,142 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
* @subpackage Tests
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFileFindRecursiveTest extends ezcTestCase
{
public function testRecursive1()
{
$expected = array (
0 => 'File/CREDITS',
1 => 'File/ChangeLog',
2 => 'File/DESCRIPTION',
3 => 'File/design/class_diagram.png',
4 => 'File/design/design.txt',
5 => 'File/design/file.xml',
6 => 'File/design/file_operations.png',
7 => 'File/design/md5.png',
8 => 'File/design/requirements.txt',
9 => 'File/src/file.php',
10 => 'File/src/file_autoload.php',
11 => 'File/tests/file_calculate_relative_path_test.php',
12 => 'File/tests/file_find_recursive_test.php',
13 => 'File/tests/file_remove_recursive_test.php',
14 => 'File/tests/suite.php',
);
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array(), array( '@/docs/@', '@svn@', '@\.swp$@' ), $stats ) );
self::assertEquals( array( 'size' => 130984, 'count' => 15 ), $stats );
}
public function testRecursive2()
{
$expected = array (
0 => './File/CREDITS',
1 => './File/ChangeLog',
2 => './File/DESCRIPTION',
3 => './File/design/class_diagram.png',
4 => './File/design/design.txt',
5 => './File/design/file.xml',
6 => './File/design/file_operations.png',
7 => './File/design/md5.png',
8 => './File/design/requirements.txt',
9 => './File/src/file.php',
10 => './File/src/file_autoload.php',
11 => './File/tests/file_calculate_relative_path_test.php',
12 => './File/tests/file_find_recursive_test.php',
13 => './File/tests/file_remove_recursive_test.php',
14 => './File/tests/suite.php',
);
self::assertEquals( $expected, ezcBaseFile::findRecursive( ".", array( '@^\./File/@' ), array( '@/docs/@', '@\.svn@', '@\.swp$@' ), $stats ) );
self::assertEquals( array( 'size' => 130984, 'count' => 15 ), $stats );
}
public function testRecursive3()
{
$expected = array (
0 => 'File/design/class_diagram.png',
1 => 'File/design/file_operations.png',
2 => 'File/design/md5.png',
);
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@\.png$@' ), array( '@\.svn@' ), $stats ) );
self::assertEquals( array( 'size' => 17642, 'count' => 3 ), $stats );
}
public function testRecursive4()
{
$expected = array (
0 => 'File/design/class_diagram.png',
1 => 'File/design/design.txt',
2 => 'File/design/file.xml',
3 => 'File/design/file_operations.png',
4 => 'File/design/md5.png',
5 => 'File/design/requirements.txt',
);
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
self::assertEquals( array( 'size' => 114282, 'count' => 6 ), $stats );
}
public function testRecursive5()
{
$expected = array (
0 => 'File/design/design.txt',
1 => 'File/design/requirements.txt',
2 => 'File/src/file.php',
3 => 'File/src/file_autoload.php',
4 => 'File/tests/file_calculate_relative_path_test.php',
5 => 'File/tests/file_find_recursive_test.php',
6 => 'File/tests/file_remove_recursive_test.php',
7 => 'File/tests/suite.php',
);
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@\.(php|txt)$@' ), array( '@/docs/@', '@\.svn@' ) ) );
}
public function testRecursive6()
{
$expected = array();
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@xxx@' ) ) );
}
public function testNonExistingDirectory()
{
$expected = array();
try
{
ezcBaseFile::findRecursive( "NotHere", array( '@xxx@' ) );
}
catch ( ezcBaseFileNotFoundException $e )
{
self::assertEquals( "The directory file 'NotHere' could not be found.", $e->getMessage() );
}
}
public function testStatsEmptyArray()
{
$expected = array (
0 => 'File/design/class_diagram.png',
1 => 'File/design/design.txt',
2 => 'File/design/file.xml',
3 => 'File/design/file_operations.png',
4 => 'File/design/md5.png',
5 => 'File/design/requirements.txt',
);
$stats = array();
self::assertEquals( $expected, ezcBaseFile::findRecursive( "File", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
self::assertEquals( array( 'size' => 114282, 'count' => 6 ), $stats );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcBaseFileFindRecursiveTest" );
}
}
?>
@@ -0,0 +1,224 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
* @subpackage Tests
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFileIsAbsoluteTest extends ezcTestCase
{
public static function testAbsoluteWindows1()
{
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Windows' ) );
}
public static function testAbsoluteWindows2()
{
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Windows' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Windows' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Windows' ) );
}
public static function testAbsoluteWindows3()
{
if ( ezcBaseFeatures::os() !== 'Windows' )
{
self::markTestSkipped( 'Test is for Windows only' );
}
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
}
public static function testAbsoluteLinux1()
{
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Linux' ) );
}
public static function testAbsoluteLinux2()
{
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Linux' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Linux' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Linux' ) );
}
public static function testAbsoluteLinux3()
{
if ( ezcBaseFeatures::os() === 'Windows' )
{
self::markTestSkipped( 'Test is for unix-like systems only' );
}
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcBaseFileIsAbsoluteTest" );
}
}
?>
@@ -0,0 +1,131 @@
<?php
/**
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version 1.5
* @filesource
* @package Base
* @subpackage Tests
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseFileRemoveRecursiveTest extends ezcTestCase
{
protected function setUp()
{
$this->tempDir = $this->createTempDir( 'ezcBaseFileRemoveFileRecursiveTest' );
mkdir( $this->tempDir . '/dir1' );
mkdir( $this->tempDir . '/dir2' );
mkdir( $this->tempDir . '/dir2/dir1' );
mkdir( $this->tempDir . '/dir2/dir1/dir1' );
mkdir( $this->tempDir . '/dir2/dir2' );
mkdir( $this->tempDir . '/dir4' );
mkdir( $this->tempDir . '/dir5' );
mkdir( $this->tempDir . '/dir6' );
file_put_contents( $this->tempDir . '/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir1/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir1/.file3.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir1/dir1/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir2/dir2/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir4/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir4/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir5/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir5/file2.txt', 'test' );
file_put_contents( $this->tempDir . '/dir6/file1.txt', 'test' );
file_put_contents( $this->tempDir . '/dir6/file2.txt', 'test' );
chmod( $this->tempDir . '/dir4/file1.txt', 0 );
chmod( $this->tempDir . '/dir5', 0 );
chmod( $this->tempDir . '/dir6', 0400 );
}
protected function tearDown()
{
chmod( $this->tempDir . '/dir5', 0700 );
chmod( $this->tempDir . '/dir6', 0700 );
$this->removeTempDir();
}
public function testRecursive1()
{
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
ezcBaseFile::removeRecursive( $this->tempDir . '/dir1' );
self::assertEquals( 9, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
ezcBaseFile::removeRecursive( $this->tempDir . '/dir2' );
self::assertEquals( 4, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
}
public function testRecursive2()
{
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
try
{
ezcBaseFile::removeRecursive( $this->tempDir . '/dir3' );
}
catch ( ezcBaseFileNotFoundException $e )
{
self::assertEquals( "The directory file '{$this->tempDir}/dir3' could not be found.", $e->getMessage() );
}
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
}
public function testRecursive3()
{
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
try
{
ezcBaseFile::removeRecursive( $this->tempDir . '/dir4' );
}
catch ( ezcBaseFilePermissionException $e )
{
self::assertEquals( "The file '{$this->tempDir}/dir5' can not be opened for reading.", $e->getMessage() );
}
self::assertEquals( 10, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
}
public function testRecursive4()
{
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
try
{
ezcBaseFile::removeRecursive( $this->tempDir . '/dir5' );
}
catch ( ezcBaseFilePermissionException $e )
{
self::assertEquals( "The file '{$this->tempDir}/dir5' can not be opened for reading.", $e->getMessage() );
}
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
}
public function testRecursive5()
{
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
try
{
ezcBaseFile::removeRecursive( $this->tempDir . '/dir6' );
}
catch ( ezcBaseFilePermissionException $e )
{
// Make no asumption on which file is tryed to be removed first
self::assertEquals(
1,
preg_match(
"(The file '{$this->tempDir}/dir6/file[12].txt' can not be removed.)",
$e->getMessage()
)
);
}
self::assertEquals( 12, count( ezcBaseFile::findRecursive( $this->tempDir ) ) );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcBaseFileRemoveRecursiveTest" );
}
}
?>
@@ -0,0 +1,23 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Test class for ezcBaseInitTest.
*
* @package Base
* @subpackage Tests
*/
class testBaseInitCallback implements ezcBaseConfigurationInitializer
{
static public function configureObject( $objectToConfigure )
{
$objectToConfigure->configured = true;
}
}
?>
@@ -0,0 +1,31 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Test class for ezcBaseInitTest.
*
* @package Base
* @subpackage Tests
*/
class testBaseInitClass
{
public $configured = false;
public static $instance;
public static function getInstance()
{
if ( is_null( self::$instance ) )
{
self::$instance = new testBaseInitClass();
ezcBaseInit::fetchConfig( 'testBaseInit', self::$instance );
}
return self::$instance;
}
}
?>
@@ -0,0 +1,53 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseStructTest extends ezcTestCase
{
public function testBaseStructGetSet()
{
$struct = new ezcBaseStruct();
try
{
$struct->no_such_property = 'value';
$this->fail( 'Expected exception was not thrown.' );
}
catch ( ezcBasePropertyNotFoundException $e )
{
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
}
try
{
$value = $struct->no_such_property;
$this->fail( 'Expected exception was not thrown.' );
}
catch ( ezcBasePropertyNotFoundException $e )
{
$this->assertEquals( "No such property name 'no_such_property'.", $e->getMessage() );
}
}
public function testBaseRepositoryDirectorySetState()
{
$dir = ezcBaseRepositoryDirectory::__set_state( array( 'type' => ezcBaseRepositoryDirectory::TYPE_EXTERNAL, 'basePath' => '/tmp', 'autoloadPath' => '/tmp/autoload' ) );
$this->assertEquals( ezcBaseRepositoryDirectory::TYPE_EXTERNAL, $dir->type );
$this->assertEquals( '/tmp', $dir->basePath );
$this->assertEquals( '/tmp/autoload', $dir->autoloadPath );
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcBaseStructTest" );
}
}
?>
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* @package Base
* @subpackage Tests
* @version 1.5
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
require_once( "base_test.php");
require_once( "base_init_test.php");
require_once( "features_test.php");
require_once( "base_options_test.php");
require_once( "struct_test.php");
require_once 'file_find_recursive_test.php';
require_once 'file_is_absolute_path.php';
require_once 'file_copy_recursive_test.php';
require_once 'file_remove_recursive_test.php';
require_once 'file_calculate_relative_path_test.php';
/**
* @package Base
* @subpackage Tests
*/
class ezcBaseSuite extends PHPUnit_Framework_TestSuite
{
public function __construct()
{
parent::__construct();
$this->setName("Base");
$this->addTest( ezcBaseTest::suite() );
$this->addTest( ezcBaseInitTest::suite() );
$this->addTest( ezcBaseFeaturesTest::suite() );
$this->addTest( ezcBaseOptionsTest::suite() );
$this->addTest( ezcBaseStructTest::suite() );
$this->addTest( ezcBaseFileCalculateRelativePathTest::suite() );
$this->addTest( ezcBaseFileFindRecursiveTest::suite() );
$this->addTest( ezcBaseFileIsAbsoluteTest::suite() );
$this->addTest( ezcBaseFileCopyRecursiveTest::suite() );
$this->addTest( ezcBaseFileRemoveRecursiveTest::suite() );
}
public static function suite()
{
return new ezcBaseSuite();
}
}
?>
@@ -0,0 +1,18 @@
<?php
class ezcBaseTestOptions extends ezcBaseOptions
{
protected $properties = array( "foo" => "bar" );
public function __set( $propertyName, $propertyValue )
{
if ( $this->__isset( $propertyName ) )
{
$this->properties[$propertyName] = $propertyValue;
}
else
{
throw new ezcBasePropertyNotFoundException( $propertyName );
}
}
}
?>
@@ -0,0 +1,4 @@
<?php
class trBasetestClass {
}
?>
@@ -0,0 +1,4 @@
<?php
class trBasetestClass2 {
}
?>
@@ -0,0 +1,4 @@
<?php
class trBasetestLongClass {
}
?>
@@ -0,0 +1,7 @@
<?php
return array(
'trBasetestClass' => 'TestClasses/base_test_class.php',
'trBasetestClass2' => 'TestClasses/base_test_class_number_two.php',
'trBasetestClass4' => 'TestClasses/base_test_class_number_four.php',
);
?>
@@ -0,0 +1,5 @@
<?php
return array(
'trBasetestLongClass' => 'TestClasses/base_test_long_class.php',
);
?>
@@ -0,0 +1,5 @@
<?php
return array(
'Object' => 'object/object.php',
);
?>
@@ -0,0 +1,4 @@
<?php
class Object{
}
?>