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{
}
?>
File diff suppressed because it is too large Load Diff
+27
View File
@@ -0,0 +1,27 @@
CREDITS
=======
eZ Components team
------------------
- Sergey Alexeev
- Sebastian Bergmann
- Jan Borsodi
- Raymond Bosman
- Frederik Holljen
- Kore Nordmann
- Derick Rethans
- Vadym Savchuk
- Tobias Schlitt
- Alexandru Stanoi
Contributors
------------
- Lars Jankowski
* ODO Meter Charts
- Elger Thiele
* Custom highlight values in line and bar charts.
+228
View File
@@ -0,0 +1,228 @@
1.3 - Monday 16 June 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.3rc1 - Tuesday 10 June 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #12581: Wrong axis captions in bar charts with manual min/max
values
1.3beta1 - Tuesday 27 May 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- No changes.
1.3alpha1 - Monday 05 May 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Implemented feature #10829: Get resource from driver.
- Implemented feature #10957: Embed glyphs for exact SVG font width
estimation.
(Patch by Freddie Witherden)
- Implemented feature #11979: Line width configurable per data set.
- Implemented feature #12382: Enhance line chart to allow invisible lines.
- Fixed issue #12483: Average dataset does not work with a single value.
1.2.1 - Monday 21 January 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Implemented feature #9407: Cairo driver.
- Fixed issue #11777: Optionally independent axis font configuration.
- Fixed issue #12254: Bad property-check for strokeLineJoin in SVG driver.
- Fixed issue #12295: Broken automatic scaling with manually set min value,
not divisible by major step.
- Fixed issue #12326: Per datapoint colors not used with bar charts.
- Fixed issue #12405: Highlightfontsize reduced when padding > 0 in highlight
font options.
1.2 - Monday 17 December 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #12238: Documentation error.
- Fixed issue #12246: dataBorder doesn't works in 2D renderer for piecharts.
1.2beta1 - Wednesday 28 November 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #12064: Gradients are not rendered correctly in Flash driver.
- Implemented support for odometer charts. Thanks to Lars Jankowski from Oxid
esales for the initial patch.
1.2alpha1 - Monday 29 October 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #11640: Polygon size reducement fails for very thin four edged
polygons.
- Fixed issue #11511: Line thickness wasn't used for rendering.
- Fixed issue #11509: Typo in line chart option.
- Implemented feature #10978: Add support for stacked bar charts.
- Implemented feature #11325: Allow values of 0 to be added to pie charts, to
be included in the legend and not rendered in the actual pie.
- Implemented feature #11247: Custom highlight values in line and bar charts.
Thanks to Elger Thiele for the basic patch.
- Implemented feature #10322 and #10565: Support for multiple x, y axis,
vertical and horizontal lines in line and bar charts.
1.1.1 - Monday 13 August 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #11107: Floating point inaccuracies caused missing grid in line
chart.
- Fixed issue #11157: Wrong display of single record with labeled axis.
- Fixed issue #11180: Color Palette: $dataSetColor in ezcGraphPalette starts
with index 1 and not zero in pie charts.
- Fixed issue #11207: Missing URL property for legend, or missing legend, may
cause PHP notice.
- Fixed issue #11233: Path for circular arcs in SVG driver may break because
of locale settings.
- Fixed issue #11235: In interactive 3D bar charts circle and bullet bars are
not linked.
- Fixed issue #11236: Legend is not properly linked in interactive 3D line and
bar charts.
1.1 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Documentation updates.
1.1rc1 - Monday 25 June 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #10828: PHP error when overwriting renderer in extended
ezGraphPieChart.
- Documentation updates and fixes.
1.1beta2 - Thursday 31 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #10741: Make ezcGraphOutOfLogithmicalBoundingsException more
descriptive.
- Fixed issue #10744: ExactAxisLabelRenderer shows last value at position of
second last value if showLastValue is disabled.
- Fixed issue #10745 (BaxedAxisLabelRenderer wrong label positions for angles:
(135 <= $angle <= 325).
- Fixed issue #10746: Border size reducement algorithm fails for polygones
with edge lengths < reducement.
- Fixed issue #10747: axisLabelRotatedRenderer accesses unitialised variables
for Angles % 90 != .0
- Fixed issue #10750: SVG drivers output broken with wrong LC_NUMERIC.
- Fixed issue #10759: Unset implementation broken in array access in datasets
and dataset properties.
- Fixed issue #10830: Automatically shorten labels if not enough space is
available.
- Fixed issue #10842: Pie charts fatal error with datasets with value sum <=
0.
- Fixed issue #10846: Division by zero in polygon size reducement algorithm
for edges with an angle equals 0 degree.
- Fixed issue #10848: Missing pie segment labels in pie charts with 3d
renderer.
- Fixed issue #10852: Fixed radar chart documentation.
- Fixed issue #10858: Document on how to embed the SVG graphs in an HTML
document.
- Fixed issue #10861: Circle sector size reducement failes for very big
angles.
- Fixed issue #10881: Wrong labeling with ezcGraphDateAxis.
1.1beta1 - Monday 07 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed issue #9916: Not documented: ArrayDataSet also can use Iterators.
- Fixed issue #9926: Float values with date axis result in date parsing
exception.
- Fixed issue #9948: Make ezcGraphPolynom documentation public.
- Fixed issue #9950: Improved ezcGraphPolynom::__toString method for more
exact output.
- Fixed issue #10018: Axis scale incorrect when startDate != first day of
month.
- Fixed issue #10025: Wrong statement in tutorial about swf versions supported
by ext/ming.
- Fixed issue #10074: Use iconv instead of mbstring.
- Fixed issue #10055: Improve chart class documentation with chart elements.
- Fixed issue #10056: Fixed drawing order for boxes with background and
border.
- Fixed issue #10199: Use saveXML instead of save( 'php://output' ) to work
around PHP bug #40429.
- Fixed issue #10246: sprintf output modification in PHP 5.2.1.
- Fixed issue #10275: Low label count on labeled axis, when having (prime
number > 10) + 1 labels.
- Fixed issue #10536: Bar side polygons are drawn at the wrong side.
- Fixed issue #10599: Pie chart label formatting callback only accepts callback
functions but neither static nor non static methods.
- Fixed issue #10606: Call to undefined function imagePsLoadFont() in gd tests
when no t1lib is available.
- Fixed issue #10675: Arrow heads on axis too small.
- Fixed issue #10693: ezcGraphChartElementAxis::getSteps returns minor steps
after last major steps.
- Implemented feature #9402: Numeric datasets.
- Implemented feature #9404: Add support for rotated texts on axis.
- Implemented feature #9406: Add support for radar charts.
- Implemented feature #9511: Added helper functions to create image maps an link SVG
images in ezcGraphTools.
- Implemented feature #10017: Plot whole months on date axis respecting their
different length.
- Implemented feature #10375: Manually reduce or increase the label count on
labeled axis.
- Implemented feature #10470: Add support for format callback functions on all
axis.
1.0 - Monday 18 December 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Renamed ezcGraphMingDriver to ezcGraphFlashDriver.
- Renamed pie chart options percentTreshHold to percentThreshold and
absoluteTreshHold to absoluteThreshold.
- Added feature #9647: Added the renderToOutput() method to the drivers.
- Fixed issue #9545: Pie chart treshhold does not work if aggregated data
stays below treshhold.
- Fixed issue #9549: Pie chart slices are not contiguous with the flash driver.
- Fixed issue #9568: Division by zero warning.
- Fixed issue #9583: Data typecasting should only be done in axis.
- Fixed issue #9586: No data rendered with string keys on date axis.
- Fixed issue #9588: Wrong polynoms build from data.
- Fixed issue #9612: Element links for SVG image in the legend require you to
click on exactly the text.
- Fixed issue #9655: pieChartOffset and highlight do not work together in 2D
renderer.
- Fixed issue #9762: Structs don't inherit from ezcBaseStruct.
- Fixed issue #9764: 3D Pie chart segment side polygon in front of circular
arc.
- Fixed issue #9795: Interferring bars, when bars count is higher then major
step count.
- Fixed issue #9823: Failing tests with PHP 5.1, because of different
parameter handling in imagepng, and (string) not calling __toString method.
- Fixed issue #9827: Use majorStep size for min/max estimating on numeric axis
with only one value.
1.0beta2 - Monday 20 November 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added logarithmical scaled numeric axis.
- Added treshhold for pie charts.
- Added custom maximum value for pie charts.
- Added ming driver for flash output.
- Added text shadow, background and border to font options.
- Added gleam to 2D pie charts.
- Added feature #9304: Possibility to format labels via callback.
- Fixed issue #9403: Element references do not work with Gleam in SVG.
1.0beta1 - Monday 25 September 2006
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Initial release of this package.
+1
View File
@@ -0,0 +1 @@
A component for creating pie charts, line graphs and other kinds of diagrams.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

@@ -0,0 +1,143 @@
eZ component: Graph, Design
~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: Kore Nordmann
:Revision: $Revision: 3273 $
:Date: $Date: 2006-08-15 11:42:17 +0200 (Tue, 15 Aug 2006) $
Design Description
==================
Purpose of Graph package
------------------------
The Graph package will be used to generate different chart types from a user
defined set of data. There will be 2D and 3D presentations for each chart
type.
Classes
-------
ezcGraph
Controller for the generated graphs. Offers factory methods for the other
classes, handles and dispatches the configuration and actions to the other
classes.
ezcGraphDataset
Receives the user data, and stores the configuration for the dataset, like
color, label, etc. How the data is stored depends on the kind of the
dataset. The dataset will be extended for algorithms like averaging and
polynomial interpolation in the dataset.
ezcGraphChart
Abstract class, which handles the global charts options like background
colors or images. Aggregates ezcGraphChartElement for configurable sub
elements.
ezcGraphChartPie
Extends ezcGraphChart for pie charts. Offers additional options for pie
charts like tresh hold under which data is combined.
ezcGraphChartLine
Extends ezcGraphChart for line charts. Additionally contains two objects
to represent and configure the axes.
ezcGraphChartElement
Abstract class to define the interface how to access the configuration
directives of different chart elements like axes and legend.
ezcGraphChartElementLegend
Offers configuration options for the charts legend like background color,
position and size.
ezcGraphChartElementAxe
Offers the axes configuration options like scaling, lines within the
graph and labeling. Can do automagic scaling of the axes.
ezcGraphRenderer
Abstract class which transforms the chart elements like pie segments,
bars, texts and lines to image primitives depending on the renderer.
ezcGraphRenderer2D
Creates image primitives for the chart elements considered as two
dimensional.
ezcGraphRenderer3D
Creates image primitives for the chart elements considered as three
dimensional.
ezcGraphDriver
Offers methods to draw image primitives like textboxes, arcs, rectangles,
polygons and lines. Needs to be extended for each output format.
ezcGraphDriverGD
Creates PNG images utilizing the GDlib bundled with PHP.
Implementation
==============
ezcGraphManagager
-----------------
Offers factory methods to build up the wanted graph, containing a chart of a
selected type, a renderer and a driver. Once aggregated the manager offers an
unified interface to configure all parts of the graph.
The manager can aggregate a finite count of datasets and forwards the to the
chart. The chart builds the visual chart elements like pie segments, lines or
bars, which are forwarded to the renderer. They are transformed to image
primitives accoringly to the selected renderer.
The datasets can be configured individually by the user of the package.
API example
-----------
The following example shows how to use the class: ::
<?php
$pie = new ezcGraphPieChart();
$pie->options->backgroundImage = 'background.png';
$pie->options->border->color = '#ff0000';
$pie->title = 'Apple Pie';
$pie->data['humanoids'] = new ezcGraphArrayDataSet(
array( 'monkey' => 54, 'ape' => 37, 'human' => 9 ) // adds a new data set
);
$pie->data['humanoids']->color['monkey'] = 'blueish'; // setting datapoint color
$pie->data['humanoids']->highlight( 'monkey' ); // chart type dependent
$line = new ezcGraphLineChart();
$line->options->backgroundColor = 'pink';
$line->data['income'] = new ezcGraphArrayDataSet(
array( 1990 => 5, 5.1, 5.4, 5.3, 6.9 )
);
$line->data['income']->color = 'blue';
$line->data['income']->symbol = ezcGraph::diamond;
$line->data['incomeWithTax'] = new ezcGraphArrayDataSet(
array( 1990 => 4.9, 5.0, 5.2, 5.1, 6.4 )
);
$line->data['incomeWithTax']->color = 'red';
$line->data['incomeWithTax']->symbol = ezcGraph::squareWithChupi;
// Create a new averaging line
$line->data['averageIncome'] = new ezcGraphAverageDatasSet( $line->data['income'] [, options] );
$line->renderer = new ezcGraphRenderer2D();
$line->driver = new ezcGraphGDDriver();
$line->render( 500, 200, 'file.png' );
?>
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,167 @@
eZ component: Graph: Interactive data points, Design
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: $Author: dr $
:Revision: $Rev: 8393 $
:Date: $Date: 2008-06-16 10:22:05 +0200 (Mon, 16 Jun 2008) $
Introduction
============
Description
-----------
Interactive data points describe a feature in charts, that the viewer of the
chart can interactively get more information about data, when viewing the
chart, or moving his mouse pointer over points of interest in the chart.
Requirements
============
There are two major sets of features to implement
Value indication
----------------
The value indication means, that at the position of the mouse pointer lines
are drawn, depeding on the chart type, to indicate the current data value at
this poistion in the chart. In a line chart this would mean a horizontal and a
vertical line to the axis and some coordinate information at the current
position of the mouse pointer, while in radar chart a line to the center of
the chart and an ellipse, indicating the value on the y axis, needs to be
drawn.
To enable this an option will be added to the driver option classes for the
drivers, which are capeable of drawing this. The value indication will be off
by default and can be enabled like this:
::
$chart->driver->options->valueIndication = true;
This option will be defined in the driver classes for the drivers implementing
the ezcGraphDriverValueIndication interface. We cannot add those options to
ezcGraphDriverOptions, because not all drivers will support this new feature,
and implementing an interface in the driver option class makes no sense, as no
methods, but only properties, will be added. The configure options will be
delegated to an option class ezcGraphDriverValueIndicationOptions to have a
central unique place to maintain those options.
Driver support
^^^^^^^^^^^^^^
The driver itself needs to implement a new interface which defines the methods
required to add the interactive elements to the resulting image. The renderer
will call those methods on the driver if it implements the interface.
::
interface ezcGraphDriverValueIndication
{
/***
* Add value indication for a cartesian coordinate system
*
* The graph data is rendered in the bounding box, the x values to
* indicate start with $xStart up to $xEnd, and the y values start
* with $yStart, up to $yEnd.
*
* http://en.wikipedia.org/wiki/Cartesian_coordinate
*
* @param ezcGraphBoundings $box
* @param float $xStart
* @param float $xEnd
* @param float $yStart
* @param float $yEnd
* return void
*/
public function cartesianValueIndication(
ezcGraphBoundings $box,
$xStart,
$xEnd,
$yStart,
$yEnd
);
/***
* Add value indication for a polar coordinate system
*
* The graph data is rendered in the bounding box, the x values to
* indicate start with $xStart up to $xEnd, and the y values start
* with $yStart, up to $yEnd. The middle point of the polar coordinate
* system is always the center point of the bounding box. The zero
* angle may be rotated, depending on the graph rotation.
*
* http://en.wikipedia.org/wiki/Polar_coordinate
*
* @param ezcGraphBoundings $box
* @param float $xStart
* @param float $xEnd
* @param float $yStart
* @param float $yEnd
* return void
*/
public function polarValueIndication(
ezcGraphBoundings $box,
$xStart,
$xEnd,
$yStart,
$yEnd
);
}
Additional data point information
---------------------------------
When hovering or clicking on a data point or a legenda item, a box with
additional information should be displayed. The box should contain text or
user defined content.
The data will be associated with the data point the same way we now associate
URLs, by an additional option, so that you can optionally add information when
creating your chart. This will consume nearly no memory if this feature is not
used.
::
$chart->data['data'] = new DataSet();
$chart->data['data']->informationBox['key'] = $object;
You may of course set the informationBox property without specifying a special
data set key to set it for all data points of a data set, even it may not make
sense semantically.
The value defined in the informationBox property will be passed to the driver.
The driver classes do not need to implement additional public methods for
this, but may optionally use an extended version of the ezcGraphContext
structure, which is already used to pass semantical context of rendered image
primitives to the driver. This struct will be extended by the additional
optional property $informationBox.
The type of $object cannot be checked before the graph is actually rendered,
or the scripts for the data point information are created, because it
rigorously depends on the driver, which values are accepted here.
- The ming driver accepts SWFMovie, SWFSprite and SWFShape objects.
- The SVG driver accepts XML, which should be valid SVG, which we won't check
for performance reasons.
- The GD driver will use enhanced imagemaps with JavaScript, so it will accept
IDs of HTML elements of the document the image will be embedded in. The
element may contain arbitrary content and will get an absolut poistion and
moved in front of the chart image.
The driver classes do not need to implement additional public methods to make
use of the new informationBox property, but can just check the context struct,
if it is available and render it properly then.
The gd driver can of course not natively support this, because bitmaps may not
contain any active content. An additional method createInteractiveImageMap()
will be added to the ezcGraphTools class. This may be called, or the user can
implement the JavaScript itself, to not infere with his own scripting
mechanisms.
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,97 @@
eZ component: Graph: Multiple axis, Design
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: $Author: kn $
:Revision: $Revision: 5847 $
:Date: $Date: 2007-08-08 12:26:43 +0200 (Wed, 08 Aug 2007) $
Introduction
============
Description
-----------
Multiple axis are used in three different cases.
- In stock chart, for example, they are used to show a different meaning of
the displayed data, for example the value of a single stock option and the
value sum of the complete company.
- Another case multiple axis may be used, is displaying relating data in one
chart which has completely different scalings or units, like the used RAM
and the load on a machine.
- A third case multiple axis could be used for, are named separators to
highlight data borders in your chart. In this case the step labels should be
at least optional.
Requirements
============
From an implementation point of view the feature seperates into two different
APIs we need to define.
Adding additional axis
^^^^^^^^^^^^^^^^^^^^^^
When adding additional axis we want to support a finite number of marker axis,
at every possible position in the chart.
::
$marker = new ezcGraphChartElementLabeledAxis();
$marker->position = ezcGraph::LEFT;
$marker->chartPosition = .4;
$chart->additionalAxis[] = $marker;
The property $position is already used by ezcGraphChartElement to indicate the
overall position and accepts bitmasks of LEFT, RIGHT, BOTTOM and TOP. For Axis
this indicates the base point of the axis and for additional axis it will
define wheather the new axis is an X or Y axis in the cartesian coordinate
system of bar and line charts.
As the property $position is already used the property $chartPosition
indicates the position of the axis in the charts data section. A value of 1
will place the axis at the very end, and a value of 0 at the very beginning of
the data.
In the example above ezcGraph::LEFT means that the axis is drawn from the left
to the right, so it is an additional x axis, and the $chartPosition indicates
the position at 40% of the chart data bounding height.
Adding data for additional axis
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Data may be added explicitely on one of the additional axis to use different
scaling und units for this dataset. The axis values are received from the data
sets when rendering the charts, so that we are able to define the usage of an
additional axis at any point before rendering.
::
$chart->data['foo'] = new ezcGraphArrayDataSet( ... );
$chart->data['foo']->xAxis = $marker; // See last example
$chart->data['foo']->yAxis = $chart->yAxis; // Redundant
The assignement of additional axis is optional and if none was defined the
original common chart axis will be used. You may define custom axis for one or
both axis.
Special consideration
=====================
You may of course define custom scaling, custom axis types and custom axis
label rendering algorithms for each of the used axis.
If no data set has been assigned to a axis it will not render any labels by
using the ezcGraphAxisNoLabelRenderer. Otherwise the assigned data will be
used the common way to calculate some default step sizes.
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,75 @@
eZ component: Graph, Requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: Derick Rethans
:Revision: $Revision: 2547 $
:Date: $Date: 2006-04-12 11:53:25 +0200 (Wed, 12 Apr 2006) $
Introduction
============
Description
-----------
The purpose of this component is to generate different kinds of diagrams from
different kinds of data. The diagrams' appearance needs to be slick and
customizable.
Requirements
============
The first version of the component should cover the following types of
charts:
Piechart
--------
A diagram showing values as elements of a piechart. It should support:
- highlighted parts (shown as a little bit outwards of the pie)
- setting a tresh hold under which values are combined together in an "others"
part
- automatic colours, but they should be able to set manually too
- automatic legenda generation and label placement
- 2D view, like:
http://www.eia.doe.gov/neic/brochure/gas04/images/pie%20chart.gif
- 3D view, like: http://www.chambersfund.org/images/piechart.jpg
- background image and/or colours
Linechart
---------
A diagram with a variable y-axis showing values for a finite set of data
points. The chart should be able to show different data sets, but all measured
only in the same unit.
Line charts should support:
- automatic colours and styles, but each dataset should be able to be styled
manually
- automatic scaling of the x and y-axis
- automatic legenda generation
- automatic label placement for both x and y-axis
- options for setting when to draw vertical and horizontal lines, and in which
style they should be drawn
- 2D view, like: http://www.swiftchart.com/line_ex5.jpg
- 3D view, like: http://www.jspwiki.org/attach/LineChart/Line+Chart+3D.png
- background image and/or colours
Special Considerations
======================
The component should be flexible enough to allow averaging and other analysis
methods to work on datasets and add rendered data to the resulting graph. This
can for example be trend analysis or mean average etc.
Formats
=======
Graphs should be rendered as PNGs in the first version, but it should be
possible to have different renders to render to f.e. SVG or flash in later
versions of the component.
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,81 @@
eZ component: Graph: Interactive data points, Requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: $Author: kn $
:Revision: $Rev: 5711 $
:Date: $Date: 2007-07-10 11:29:28 +0200 (Tue, 10 Jul 2007) $
Introduction
============
Description
-----------
Interactive data points describe a feature in charts, that the viewer of the
chart can interactively get more information about data, when viewing the
chart, or moving his mouse pointer over points of interest in the chart.
Requirements
============
There are two major sets of features to implement
Value indication
----------------
The value indication means, that at the position of the mouse pointer lines
are drawn, depeding on the chart type, to indicate the current data value at
this poistion in the chart. In a line chart this would mean a horizontal and a
vertical line to the axis and some coordinate information at the current
position of the mouse pointer, while in radar chart a line to the center of
the chart and an ellipse, indicating the value on the y axis, needs to be
drawn.
SVG
No real problem.
GD / Cairo / IMagick
Not possible without large effort.
Flash
No really big deal with flash and ext/ming.
Additional data point information
---------------------------------
When hovering or clicking on a data point or a legenda ite, a box with
additional information should be displayed. The box should contain text or
user defined content.
SVG
With only user defined inlined SVGs or Text in a box no big deal.
GD / Cairo / IMagick
With a tool script generating HTML and javascript to use with the image
map, it should be possible to use HTML and text in boxes. This is similar
to the currently used mechanism to create image maps.
Flash
Possible with user provided SWFMovies or shapes.
Special consideration
=====================
It is impossible to implement natively more then simple text in a box for the
additional information in highlighted data points, because this would require
a complete redering model like HTML uses.
Formats
=======
The integration of HTML, Flash or SVG documents should be possible, but would
be a non driver generic mechanism. It seems not easily possible to convert
user defined Flash, HTML and SVG to the respective other format.
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,60 @@
eZ component: Graph: Multiple axis, Requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Author: $Author: kn $
:Revision: $Rev: 5844 $
:Date: $Date: 2007-08-08 11:00:39 +0200 (Wed, 08 Aug 2007) $
Introduction
============
Description
-----------
Multiple axis are used in three different cases.
- In stock chart, for example, they are used to show a different meaning of
the displayed data, for example the value of a single stock option and the
value sum of the complete company.
- Another case multiple axis may be used, is displaying relating data in one
chart which has completely different scalings or units, like the used RAM
and the load on a machine.
- A third case multiple axis could be used for, are named separators to
highlight data borders in your chart. In this case the step labels should be
at least optional.
Requirements
============
To act as additional axis and seperators it is required, that additional axis
can be placed at any position in the chart, especially at the very end and
beginning of the charts data.
It should be possible to associate a data set with a non default axis, to
calculate the position of its data points based on a diffenrent scaling, then
the default one.
It should also be possible to add axis not depending on any data set and
define the scaling manually. Those axis can be placed at any position in the
chart, and if no scaling was explicitely given and no data set is associated,
those axis will omit drawing steps or step labeling and just display a single
line with the (optional) axis label.
Special consideration
=====================
An API for assigning data sets to axis other then the default one will be
defined in the design document. The calculation of the poistion of a data
point in a chart is completely done in the chart classes, so it will be no
problem to use another axis for this. No changes or additions in the renderers
will be required.
..
Local Variables:
mode: rst
fill-column: 79
End:
vim: et syn=rst tw=79
@@ -0,0 +1,82 @@
<?php
/**
* File containing the ezcGraphPaletteEzGreen class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Light green color pallet for ezcGraph based on green eZ colors
*
* @package Graph
*/
class ezcGraphPaletteEzGreen extends ezcGraphPalette
{
/**
* Axiscolor
*
* @var ezcGraphColor
*/
protected $axisColor = '#2E3436';
/**
* Array with colors for datasets
*
* @var array
*/
protected $dataSetColor = array(
'#9CAE86',
'#87B06B',
'#5C9A75',
'#467A6E',
'#4F6C57',
);
/**
* Array with symbols for datasets
*
* @var array
*/
protected $dataSetSymbol = array(
ezcGraph::BULLET,
);
/**
* Name of font to use
*
* @var string
*/
protected $fontName = 'sans-serif';
/**
* Fontcolor
*
* @var ezcGraphColor
*/
protected $fontColor = '#2E3436';
/**
* Backgroundcolor for chart
*
* @var ezcGraphColor
*/
protected $chartBackground = '#FFFFFF';
/**
* Padding in elements
*
* @var integer
*/
protected $padding = 1;
/**
* Margin of elements
*
* @var integer
*/
protected $margin = 0;
}
?>
@@ -0,0 +1,82 @@
<?php
/**
* File containing the ezcGraphPaletteEzRed class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Light red color pallet for ezcGraph based on red eZ colors
*
* @package Graph
*/
class ezcGraphPaletteEzRed extends ezcGraphPalette
{
/**
* Axiscolor
*
* @var ezcGraphColor
*/
protected $axisColor = '#2E3436';
/**
* Array with colors for datasets
*
* @var array
*/
protected $dataSetColor = array(
'#B50D2C',
'#C42926',
'#C34009',
'#CA3C04',
'#D86300',
);
/**
* Array with symbols for datasets
*
* @var array
*/
protected $dataSetSymbol = array(
ezcGraph::BULLET,
);
/**
* Name of font to use
*
* @var string
*/
protected $fontName = 'sans-serif';
/**
* Fontcolor
*
* @var ezcGraphColor
*/
protected $fontColor = '#2E3436';
/**
* Backgroundcolor for chart
*
* @var ezcGraphColor
*/
protected $chartBackground = '#FFFFFF';
/**
* Padding in elements
*
* @var integer
*/
protected $padding = 1;
/**
* Margin of elements
*
* @var integer
*/
protected $margin = 0;
}
?>
@@ -0,0 +1,48 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Create the graph
$graph = new ezcGraphBarChart();
$graph->palette = new ezcGraphPaletteEzBlue();
$graph->xAxis->majorGrid = '#888888';
$graph->yAxis->majorGrid = '#888888';
// Add the data and hilight norwegian data set
$graph->data['Posts'] = new ezcGraphArrayDataSet( array(
'May 2006' => 1164,
'Jun 2006' => 965,
'Jul 2006' => 1014,
'Aug 2006' => 1269,
'Sep 2006' => 1269,
'Oct 2006' => 771,
) );
$graph->data['per day'] = new ezcGraphArrayDataSet( array(
'May 2006' => 38,
'Jun 2006' => 32,
'Jul 2006' => 33,
'Aug 2006' => 41,
'Sep 2006' => 34,
'Oct 2006' => 25,
) );
// Set graph title
$graph->title = 'Forum posts in last months';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->barChartGleam = .5;
$graph->renderer->options->legendSymbolGleam = .5;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render( 500, 200, 'forum_evolution.svg' );
?>
@@ -0,0 +1,47 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Require custom palette
require dirname( __FILE__ ) . '/ez_red.php';
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzRed();
$graph->legend = false;
// Add the data and hilight norwegian data set
$graph->data['week'] = new ezcGraphArrayDataSet( array(
'Claudia Kosny' => 128,
'Kristof Coomans' => 70,
'Xavier Dutoit' => 64,
'David Jones' => 58,
'Lukasz Serwatka' => 45,
'Norman Leutner' => 22,
'Marko Zmak' => 20,
'sangib das' => 20,
'Nabil Alimi' => 19,
) );
// Set graph title
$graph->title = '10 most active users on forum in last month';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = .5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->pieChartOffset = 100;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render( 500, 200, 'forum_month.svg' );
?>
@@ -0,0 +1,45 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzBlue();
$graph->legend = false;
// Add the data and hilight norwegian data set
$graph->data['week'] = new ezcGraphArrayDataSet( array(
'Claudia Kosny' => 45,
'Lukasz Serwatka' => 35,
'Kristof Coomans' => 25,
'David Jones' => 23,
'Xavier Dutoit' => 20,
'sangib das' => 14,
'Mark Marsiglio' => 10,
'mark hayhurst' => 10,
'Paul Borgermans' => 10,
'Nabil Alimi' => 9,
) );
// Set graph title
$graph->title = '10 most active users on forum in last week';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = .5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->pieChartOffset = 100;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render( 500, 200, 'forum_weekly.svg' );
?>
@@ -0,0 +1,45 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Require custom palette
require dirname( __FILE__ ) . '/ez_green.php';
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzGreen();
$graph->legend = false;
// Add the data and hilight norwegian data set
$graph->data['week'] = new ezcGraphArrayDataSet( array(
'Lukasz Serwatka' => 1805,
'Paul Forsyth' => 1491,
'Paul Borgermans' => 1316,
'Kristof Coomans' => 956,
'Alex Jones' => 942 ,
'Bard Farstad' => 941,
'Tony Wood' => 900,
) );
// Set graph title
$graph->title = 'Alltime 10 most active users on forum';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = .5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->pieChartOffset = 100;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render( 500, 200, 'forum_year.svg' );
?>
@@ -0,0 +1,45 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzRed();
// Add the data and hilight norwegian data set
$graph->data['articles'] = new ezcGraphArrayDataSet( array(
'English' => 1300000,
'Germany' => 452000,
'Netherlands' => 217000,
'Norway' => 70000,
) );
$graph->data['articles']->highlight['Germany'] = true;
// Set graph title
$graph->title = 'Wikipedia articles by country';
// Modify pie chart label to only show amount and percent
$graph->options->label = '%2$d (%3$.1f%%)';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = .5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 8;
$graph->renderer->options->pieChartRotation = .8;
$graph->renderer->options->pieChartOffset = 190;
$graph->renderer->options->legendSymbolGleam = .5;
// Output the graph with std SVG driver
$graph->render( 400, 200, 'wikipedia.svg' );
?>
@@ -0,0 +1,39 @@
<?php
require 'Base/src/base.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
}
// Create the graph
$graph = new ezcGraphPieChart();
// Add the data and hilight norwegian data set
$graph->data['articles'] = new ezcGraphArrayDataSet( array(
'English' => 1300000,
'Germany' => 452000,
'Netherlands' => 217000,
'Norway' => 70000,
) );
$graph->data['articles']->highlight['Norway'] = true;
// Set graph title
$graph->title = 'Articles by country';
// Modify pie chart label to only show amount and percent
$graph->options->label = '%2$d (%3$.1f%%)';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = .5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->pieChartOffset = 100;
// Output the graph with std SVG driver
$graph->render( 500, 200, 'wiki_graph.svg' );
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Some files were not shown because too many files have changed in this diff Show More