/**
  * Fills $this->files with all the .request files found in the regression
  * directory, recursively.
  */
 public function __construct()
 {
     $siteaccess = strtolower(__CLASS__);
     if (ezcBaseFeatures::classExists('eZSiteAccessHelper', true)) {
         require_once 'siteaccesscreator.php';
         // - ./siteaccess/site.ini.append.php.replace is copied over site.ini.append.php,
         //   with certain values replaced dynamically (@ezc_siteaccess@ and
         //   @ezc_webdav_database@)
         // - the extension ezsiteaccesshelper is called to create the siteaccess with
         //   the same name as this class (in lowercase), and it will copy the site.ini.append.php
         //   file to the ezp/siteaccess/@ezc_siteaccess@ folder
         // - the extension ezsiteaccesshelper is called to enable the created siteaccess
         //   in ezp/siteaccess/override/site.ini.append.php
         $replace = array();
         $replace['@ezc_siteaccess@'] = $siteaccess;
         $replace['@ezc_webdav_database@'] = ezpTestRunner::dsn()->database;
         $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'siteaccess';
         try {
             // replace @ezc_siteaccess@ and @ezc_webdav_database@ in site.ini.append.php
             // with respective values
             $contents = file_get_contents($templateDir . DIRECTORY_SEPARATOR . 'site.ini.append.php.replace');
             if (count($replace) > 0) {
                 foreach ($replace as $key => $replacement) {
                     $contents = str_replace($key, $replacement, $contents);
                 }
             }
             file_put_contents($templateDir . DIRECTORY_SEPARATOR . 'site.ini.append.php', $contents);
             ezpSiteAccessCreator::$docRoot = eZSys::rootDir() . DIRECTORY_SEPARATOR;
             ezpSiteAccessCreator::createSiteAccess($siteaccess, $templateDir);
         } catch (Exception $e) {
             // eZSiteAccessHelper::createSiteAccess throws an exception
             // if the siteaccess exists already
             // var_dump( $e->getMessage() );
         }
     } else {
         die("The WebDAV test suite requires the extension eZSiteAccessHelper in order to create a siteaccess.\n");
     }
     $basePath = dirname(__FILE__) . '/regression';
     $this->readDirRecursively($basePath, $this->files, 'request');
     parent::__construct();
 }
 /**
  * Parses a required type.
  *
  * @param mixed $type
  * @param ezcTemplateCursor $startCursor
  * @param bool $mergeElements
  * @return bool
  */
 protected function parseRequiredType($type, ezcTemplateCursor $startCursor = null, $mergeElements = true)
 {
     if (is_string($type)) {
         $className = 'ezcTemplate' . $type . 'SourceToTstParser';
         if (!ezcBaseFeatures::classExists($className)) {
             throw new ezcTemplateInternalException("Could instantiate sub-parser for type <{$type}>, the class <{$className}> does not exist");
         }
         $this->subParser = new $className($this->parser, $this, $startCursor);
     } else {
         if (is_object($type) && $type instanceof ezcTemplateSourceToTstParser) {
             $this->subParser = $type;
         } else {
             throw new ezcTemplateInternalException("Cannot use <" . gettype($type) . "> as parser in ezcTemplateSourceToTstParser::parseRequiredType()");
         }
     }
     $this->lastParser = $this->subParser;
     $this->subParser->parse();
     if ($this->subParser->status == self::PARSE_SUCCESS) {
         $this->currentCursor->copy($this->subParser->endCursor);
         $this->lastCursor->copy($this->currentCursor);
         if ($mergeElements) {
             $this->mergeElements($this->subParser);
         }
         $this->subParser = null;
         return true;
     } elseif ($this->subParser->status === self::PARSE_PARTIAL_SUCCESS) {
         $this->status = $this->subParser->status;
         return false;
     }
     return false;
 }
Ejemplo n.º 3
0
 public function testClassExistsNotFoundAutoload()
 {
     $this->assertEquals(false, ezcBaseFeatures::classExists('ezcBaseNonExistingClass'));
 }
Ejemplo n.º 4
0
 /**
  * Creates a new cache in the manager.
  * This method is used to create a new cache inside the manager.
  * Each cache has a unique ID to access it during the application
  * runtime. Each location may only be used by 1 cache.
  *
  * The $storageClass parameter must be a subclass of
  * {@link ezcCacheStorage} and tells the manager which object
  * will be used for the cache.
  *
  * The $location parameter depends on the kind of {@link ezcCacheStorage}
  * used for the cache you create. Usually this is a directory on your
  * file system, but may also be e.g. a data source name, if you cache in
  * a database or similar. For memory-based storage ({@link ezcCacheStorageApcPlain}
  * or {@link ezcCacheStorageMemcachePlain}) it is null, but for
  * memory/file hybrid storage ({@link ezcCacheStorageFileApcArray}) it should
  * be an existing writeable path.
  *
  * The $options array consists of several standard attributes and can
  * additionally contain options defined by the {@link ezcCacheStorage}
  * class. Standard options are:
  *
  * <code>
  * array(
  *      'ttl'   => 60*60*24,    // Time-to-life, default: 1 day
  * );
  * </code>
  *
  * @param string $id                     ID of the cache to create.
  * @param string $location               Location to create the cache in. Null for
  *                                       memory-based storage and an existing
  *                                       writeable path for file or memory/file
  *                                       storage.
  * @param string $storageClass           Subclass of {@link ezcCacheStorage}.
  * @param array(string=>string) $options Options for the cache.
  * @return void
  *
  * @throws ezcBaseFileNotFoundException
  *         If the given location does not exist or is not a
  *         directory (thrown by sanity checks performed when storing the
  *         configuration of a cache to ensure the latter calls to
  *         {@link ezcCacheManager::getCache()} do not fail).
  * @throws ezcBaseFilePermissionException
  *         If the given location is not read/writeable (thrown by sanity
  *         checks performed when storing the configuration of a cache to
  *         ensure the latter calls to {@link ezcCacheManager::getCache()}
  *         do not fail).
  * @throws ezcCacheUsedLocationException
  *         If the given location is already in use by another cache.
  * @throws ezcCacheInvalidStorageClassException
  *         If the given storage class does not exist or is no subclass of
  *         ezcCacheStorage.
  */
 public static function createCache($id, $location = null, $storageClass, $options = array())
 {
     // BC for missing location. The location should not be missing.
     if ($location !== null) {
         // Unifiy file system locations
         if (substr($location, 0, 1) === '/') {
             // If non-existent
             if (($realLocation = realpath($location)) === false) {
                 throw new ezcBaseFileNotFoundException($location, 'cache location', 'Does not exist or is no directory.');
             }
             $location = $realLocation;
         }
         // Sanity check double taken locations.
         foreach (self::$configurations as $confId => $config) {
             if ($config['location'] === $location) {
                 throw new ezcCacheUsedLocationException($location, $confId);
             }
         }
     }
     // Sanity check storage class.
     if (!ezcBaseFeatures::classExists($storageClass) || !is_subclass_of($storageClass, 'ezcCacheStorage')) {
         throw new ezcCacheInvalidStorageClassException($storageClass);
     }
     self::$configurations[$id] = array('location' => $location, 'class' => $storageClass, 'options' => $options);
 }
 /**
  * Initializes the manager.
  *
  * Initializes the manager with the values which will be used by the configuration
  * reader. It sets the default location and reader options and which reader to
  * use by specifying the class name.
  *
  * @throws ezcConfigurationInvalidReaderClassException if the $readerClass
  *         does not exist or does not implement the ezcConfigurationReader
  *         interface.
  *
  * @param string $readerClass The name of the class to use as a
  *               configuration reader. This class must implement the
  *               ezcConfigurationReader interface.
  * @param string $location The main placement for the configuration. It is
  *               up to the specific reader to interpret this value.  This
  *               can for instance be used to determine the directory
  *               location for an INI file.
  * @param array  $options Options for the configuration reader, this is
  *               passed on the reader specified in $readerClass when it is
  *               created. Check the documentation for the specific reader
  *               to see which options it supports.
  * @return void
  */
 public function init($readerClass, $location, array $options = array())
 {
     // Check if the passed classname actually exists
     if (!ezcBaseFeatures::classExists($readerClass, true)) {
         throw new ezcConfigurationInvalidReaderClassException($readerClass);
     }
     // Check if the passed classname actually implements the interface.
     if (!in_array('ezcConfigurationReader', class_parents($readerClass))) {
         throw new ezcConfigurationInvalidReaderClassException($readerClass);
     }
     $this->readerClass = $readerClass;
     $this->location = $location;
     $this->options = $options;
 }
Ejemplo n.º 6
0
 /**
  * Check all known handlers for availability.
  *
  * This method checks all registered handler classes for if the they are
  * available (using {@link ezcImageAnalyzerHandler::isAvailable()}).
  * 
  * @throws ezcImageAnalyzerInvalidHandlerException
  *         If a registered handler class does not exist
  *         or does not inherit from {@link ezcImageAnalyzerHandler}.
  */
 protected function checkHandlers()
 {
     if (isset(ezcImageAnalyzer::$availableHandlers) && is_array(ezcImageAnalyzer::$availableHandlers)) {
         return;
     }
     ezcImageAnalyzer::$availableHandlers = array();
     foreach (ezcImageAnalyzer::$knownHandlers as $handlerClass => $options) {
         if (!ezcBaseFeatures::classExists($handlerClass) || !is_subclass_of($handlerClass, 'ezcImageAnalyzerHandler')) {
             throw new ezcImageAnalyzerInvalidHandlerException($handlerClass);
         }
         $handler = new $handlerClass($options);
         if ($handler->isAvailable()) {
             ezcImageAnalyzer::$availableHandlers[] = clone $handler;
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Initialize converter with settings object.
  * The ezcImageConverter can be directly instantiated, but it's
  * highly recommended to use a manual singleton implementation
  * to have just 1 instance of a ezcImageConverter per Request.
  *
  * ATTENTION: The ezcImageConverter does not support animated
  * GIFs. Animated GIFs will simply be ignored by all filters and
  * conversions.
  *
  * @param ezcImageConverterSettings $settings Settings for the converter.
  *
  * @throws ezcImageHandlerSettingsInvalidException
  *         If handler settings are invalid.
  * @throws ezcImageMimeTypeUnsupportedException
  *         If a given MIME type is not supported.
  */
 public function __construct(ezcImageConverterSettings $settings)
 {
     // Initialize handlers
     foreach ($settings->handlers as $i => $handlerSettings) {
         if (!$handlerSettings instanceof ezcImageHandlerSettings) {
             throw new ezcImageHandlerSettingsInvalidException();
         }
         $handlerClass = $handlerSettings->className;
         if (!ezcBaseFeatures::classExists($handlerClass)) {
             throw new ezcImageHandlerNotAvailableException($handlerClass);
         }
         $handler = new $handlerClass($handlerSettings);
         $this->handlers[$handlerSettings->referenceName] = $handler;
     }
     // Check implicit conversions
     foreach ($settings->conversions as $mimeIn => $mimeOut) {
         if (!$this->allowsInput($mimeIn)) {
             throw new ezcImageMimeTypeUnsupportedException($mimeIn, 'input');
         }
         if (!$this->allowsOutput($mimeOut)) {
             throw new ezcImageMimeTypeUnsupportedException($mimeOut, 'output');
         }
     }
     $this->settings = $settings;
 }
Ejemplo n.º 8
0
 /**
  * Adds the difference write handler class $writerClass to the manager for $type
  *
  * @throws ezcDbSchemaInvalidWriterClassException if the $writerClass
  *         doesn't exist or doesn't extend the abstract class
  *         ezcDbSchemaDiffWriter.
  * @param string $type
  * @param string $writerClass
  */
 public static function addDiffWriter($type, $writerClass)
 {
     // Check if the passed classname actually exists
     if (!ezcBaseFeatures::classExists($writerClass, true)) {
         throw new ezcDbSchemaInvalidDiffWriterClassException($writerClass);
     }
     // Check if the passed classname actually implements the interface.
     if (!in_array('ezcDbSchemaDiffWriter', class_implements($writerClass))) {
         throw new ezcDbSchemaInvalidDiffWriterClassException($writerClass);
     }
     self::$diffWriteHandlers[$type] = $writerClass;
 }
Ejemplo n.º 9
0
 /**
  * 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;
     }
 }
Ejemplo n.º 10
0
 /**
  * Parses the statements, foreach, while, if, elseif, etc. 
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     // Check if any control structure names are used.
     // Note: The code inside the (?:) brace ensures that the next character
     // is not an alphabetical character ie. a word boundary
     $matches = $cursor->pregMatchComplete("#^(tr|tr_context|foreach|while|if|elseif|else|switch|case|default|include|return|break|continue|skip|delimiter|increment|decrement|reset|charset|capture)(?:[^a-zA-Z0-9_])#");
     if ($matches === false) {
         return false;
     }
     $name = $matches[1][0];
     $cursor->advance(strlen($matches[1][0]));
     // control structure map
     $csMap = array();
     $csMap['foreach'] = 'ForeachLoop';
     $csMap['for'] = 'ForLoop';
     $csMap['while'] = 'WhileLoop';
     $csMap['if'] = 'IfCondition';
     $csMap['elseif'] = 'IfCondition';
     $csMap['else'] = 'IfCondition';
     $csMap['switch'] = 'SwitchCondition';
     $csMap['case'] = 'SwitchCondition';
     $csMap['default'] = 'SwitchCondition';
     $csMap['include'] = 'Include';
     $csMap['return'] = 'Include';
     $csMap['break'] = 'Loop';
     $csMap['continue'] = 'Loop';
     $csMap['skip'] = 'Delimiter';
     $csMap['delimiter'] = 'Delimiter';
     $csMap['increment'] = 'Cycle';
     $csMap['decrement'] = 'Cycle';
     $csMap['reset'] = 'Cycle';
     $csMap['charset'] = 'Charset';
     $csMap['capture'] = 'Capture';
     $csMap['tr'] = 'Translation';
     $csMap['tr_context'] = 'TranslationContext';
     // tmp
     if (!isset($csMap[$name])) {
         return false;
     }
     $parser = 'ezcTemplate' . $csMap[$name] . 'SourceToTstParser';
     // tmp
     if (!ezcBaseFeatures::classExists($parser)) {
         return false;
     }
     if (!ezcBaseFeatures::classExists($parser)) {
         throw new ezcTemplateInternalException("Requested parser class <{$parser}> does not exist");
     }
     $controlStructureParser = new $parser($this->parser, $this, null);
     $this->block->name = $name;
     $controlStructureParser->block = $this->block;
     if (!$this->parseRequiredType($controlStructureParser)) {
         return false;
     }
     return true;
 }
 public function testReader5()
 {
     if (!ezcBaseFeatures::classExists('SimpleXMLIterator')) {
         $this->markTestSkipped("This test is supposed to run only when the SimpleXML extension is available.");
     }
     $currentDir = dirname(__FILE__);
     $backend = new ezcTranslationTsBackend("{$currentDir}/files/translations");
     $backend->setOptions(array('format' => '[LOCALE].xml'));
     $backend->initReader('nb-no');
     $contexts = array();
     foreach ($backend as $contextName => $context) {
         $contexts[] = $contextName;
     }
     $backend->deinitReader();
     $expected = array('contentstructuremenu/show_content_structure', 'design/admin/class/classlist', 'design/admin/class/datatype/browse_objectrelationlist_placement');
     self::assertEquals($expected, $contexts);
 }
Ejemplo n.º 12
0
 /**
  * Adds custom tags or functions to the customBlock or customFunction
  * property and indirectly adds the custom extension to the template
  * language. 
  *
  * The parameter $customBlockClass expects a class that implements either 
  * the interface ezcTemplateCustomBlock, ezcTemplateCustomFunction, or both.
  *
  * New custom blocks are added to the
  * {@link ezcTemplateConfiguration::customBlocks $customBlocks} property while
  * custom functions are added to the
  * {@link ezcTemplateConfiguration::customFunctions $customFunctions} property.
  *
  * @param string $customClass
  * @throws ezcBaseValueException if the $customClass parameter is not a
  *         string, or when the classname that it represents does not
  *         implement either the ezcTemplateCustomBlock or
  *         ezcTemplateCustomFunction interface.
  */
 public function addExtension($customClass)
 {
     if (!is_string($customClass) || !ezcBaseFeatures::classExists($customClass, true)) {
         throw new ezcBaseValueException('customClass', $customClass, 'string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface', 'argument');
     }
     $implements = class_implements($customClass);
     $added = false;
     if (in_array("ezcTemplateCustomBlock", $implements)) {
         $this->properties["customBlocks"][$customClass] = $customClass;
         $added = true;
     }
     if (in_array("ezcTemplateCustomFunction", $implements)) {
         $this->properties["customFunctions"][$customClass] = $customClass;
         $added = true;
     }
     if (!$added) {
         throw new ezcBaseValueException('customClass', $customClass, 'string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface', 'argument');
     }
 }
Ejemplo n.º 13
0
 /**
  * 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. We
         // have to do that with reflection here unfortunately
         $interfaceClass = new ReflectionClass('ezcBaseConfigurationInitializer');
         $handlerClass = new ReflectionClass($callbackClassname);
         if (!$handlerClass->isSubclassOf($interfaceClass)) {
             throw new ezcBaseInitInvalidCallbackClassException($callbackClassname);
         }
         self::$callbackMap[$identifier] = $callbackClassname;
     }
 }
Ejemplo n.º 14
0
 /**
  * Initializes the ezcExecution environment.
  *
  * With this method you initialize the ezcExecution environment. You need
  * to specify a class name $callBackClassName that will be used to call the
  * onError() method on in case of an error. The class name that you
  * pass should implement the ezcExecutionErrorHandler interface. This
  * method takes care of registering the uncaught exception and shutdown
  * handlers. 
  *
  * @throws ezcExecutionInvalidCallbackException if an unknown callback
  *         class was passed.
  * @throws ezcExecutionWrongClassException if an invalid callback class was
  *         passed.
  * @throws ezcExecutionAlreadyInitializedException if the environment was
  *         already initialized.
  *
  * @param string $callbackClassName 
  * @return void
  */
 public static function init($callbackClassName)
 {
     // Check if the passed classname actually exists
     if (!ezcBaseFeatures::classExists($callbackClassName, true)) {
         throw new ezcExecutionInvalidCallbackException($callbackClassName);
     }
     // Check if the passed classname actually implements the interface. We
     // have to do that with reflection here unfortunately since we only
     // have the classname and not an object.
     $interfaceClass = new ReflectionClass('ezcExecutionErrorHandler');
     $handlerClass = new ReflectionClass($callbackClassName);
     if (!$handlerClass->isSubclassOf($interfaceClass)) {
         throw new ezcExecutionWrongClassException($callbackClassName);
     }
     // Check if it was already initialized once
     if (self::$isInitialized == true) {
         throw new ezcExecutionAlreadyInitializedException();
     }
     // Install shutdown handler and exception handler
     set_exception_handler(array('ezcExecution', 'exceptionCallbackHandler'));
     if (!self::$shutdownHandlerRegistered) {
         register_shutdown_function(array('ezcExecution', 'shutdownCallbackHandler'));
     }
     self::$callbackClassName = $callbackClassName;
     self::$isInitialized = true;
     self::$cleanExit = false;
     self::$shutdownHandlerRegistered = true;
 }
Ejemplo n.º 15
0
 /**
  * Initializes the ezcExecution environment.
  *
  * With this method you initialize the ezcExecution environment. You need
  * to specify a class name $callBackClassName that will be used to call the
  * onError() method on in case of an error. The class name that you
  * pass should implement the ezcExecutionErrorHandler interface. This
  * method takes care of registering the uncaught exception and shutdown
  * handlers. 
  *
  * @throws ezcExecutionInvalidCallbackException if an unknown callback
  *         class was passed.
  * @throws ezcExecutionWrongClassException if an invalid callback class was
  *         passed.
  * @throws ezcExecutionAlreadyInitializedException if the environment was
  *         already initialized.
  *
  * @param string $callbackClassName 
  * @return void
  */
 public static function init($callbackClassName)
 {
     // Check if the passed classname actually exists
     if (!ezcBaseFeatures::classExists($callbackClassName, true)) {
         throw new ezcExecutionInvalidCallbackException($callbackClassName);
     }
     // Check if the passed classname actually implements the interface.
     if (!in_array('ezcExecutionErrorHandler', class_implements($callbackClassName))) {
         throw new ezcExecutionWrongClassException($callbackClassName);
     }
     // Check if it was already initialized once
     if (self::$isInitialized == true) {
         throw new ezcExecutionAlreadyInitializedException();
     }
     // Install shutdown handler and exception handler
     set_exception_handler(array('ezcExecution', 'exceptionCallbackHandler'));
     if (!self::$shutdownHandlerRegistered) {
         register_shutdown_function(array('ezcExecution', 'shutdownCallbackHandler'));
     }
     self::$callbackClassName = $callbackClassName;
     self::$isInitialized = true;
     self::$cleanExit = false;
     self::$shutdownHandlerRegistered = true;
 }