Пример #1
0
 /**
  * Get the full, resolved stream location name to the template resource.
  *
  * @return     string A PHP stream resource identifier.
  *
  * @throws     AgaviException If the template could not be found.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function getResourceStreamIdentifier()
 {
     $retval = null;
     $template = $this->getParameter('template');
     if ($template === null) {
         // no template set, we return null so nothing gets rendered
         return null;
     } elseif (AgaviToolkit::isPathAbsolute($template)) {
         // the template is an absolute path, ignore the dir
         $directory = dirname($template);
         $template = basename($template);
     } else {
         $directory = $this->getParameter('directory');
     }
     // treat the directory as sprintf format string and inject module name
     $directory = AgaviToolkit::expandVariables($directory, array_merge(array_filter($this->getParameters(), 'is_scalar'), array_filter($this->getParameters(), 'is_null')));
     $this->setParameter('directory', $directory);
     $this->setParameter('template', $template);
     if (!$this->hasParameter('extension')) {
         $this->setParameter('extension', $this->renderer->getDefaultExtension());
     }
     // everything set up for the parent
     return parent::getResourceStreamIdentifier();
 }
 /**
  * Replace a relative filesystem path with an absolute one.
  *
  * @param      string A relative filesystem path.
  *
  * @return     string The new path.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public static function replacePath($path)
 {
     if (!AgaviToolkit::isPathAbsolute($path)) {
         // not an absolute path so we'll prepend to it
         $path = AgaviConfig::get('core.app_dir') . '/' . $path;
     }
     return $path;
 }
 /**
  * Validate a given document according to XMLSchema-instance (xsi)
  * declarations.
  *
  * @param      AgaviXmlConfigDomDocument The document to act upon.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @since      1.0.0
  */
 public static function validateXsi(AgaviXmlConfigDomDocument $document)
 {
     // next, find (and validate against) XML schema instance declarations
     $sources = array();
     if ($document->documentElement->hasAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation')) {
         // find locations. for namespaces, they are space separated pairs of a namespace URI and a schema location
         $locations = preg_split('/\\s+/', $document->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation'));
         for ($i = 1; $i < count($locations); $i = $i + 2) {
             $sources[] = $locations[$i];
         }
     }
     // no namespace? then it's only one schema location in this attribute
     if ($document->documentElement->hasAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'noNamespaceSchemaLocation')) {
         $sources[] = $document->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'noNamespaceSchemaLocation');
     }
     if ($sources) {
         // we have instances to validate against...
         $schemas = array();
         foreach ($sources as &$source) {
             // so for each location, we need to grab the file and validate against this grabbed source code, as libxml often has a hard time retrieving stuff over HTTP
             $source = AgaviToolkit::expandDirectives($source);
             if (parse_url($source, PHP_URL_SCHEME) === null && !AgaviToolkit::isPathAbsolute($source)) {
                 // the schema location is relative to the XML file
                 $source = dirname($document->documentURI) . DIRECTORY_SEPARATOR . $source;
             }
             $schema = @file_get_contents($source);
             if ($schema === false) {
                 throw new AgaviUnreadableException(sprintf('XML Schema validation file "%s" for configuration file "%s" does not exist or is unreadable', $source, $document->documentURI));
             }
             $schemas[] = $schema;
         }
         // now validate them all
         self::validateXmlschemaSource($document, $schemas);
     }
 }
Пример #4
0
 /**
  * Initialize a suite from the given instructions and add registered tests.
  *
  * @param      string Name of the suite
  * @param      array  An array containing information about the suite
  *
  * @return     AgaviTestSuite The initialized test suite object.
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0
  * @deprecated 1.1.0 Use AgaviPhpUnitCli
  */
 protected static function createSuite($name, array $suite)
 {
     $base = null == $suite['base'] ? 'tests' : $suite['base'];
     if (!AgaviToolkit::isPathAbsolute($base)) {
         $base = AgaviConfig::get('core.testing_dir') . '/' . $base;
     }
     $s = new $suite['class']($name);
     if (!empty($suite['includes'])) {
         foreach (new RecursiveIteratorIterator(new AgaviRecursiveDirectoryFilterIterator(new RecursiveDirectoryIterator($base), $suite['includes'], $suite['excludes']), RecursiveIteratorIterator::CHILD_FIRST) as $finfo) {
             if ($finfo->isFile()) {
                 $s->addTestFile($finfo->getPathName());
             }
         }
     }
     foreach ($suite['testfiles'] as $file) {
         if (!AgaviToolkit::isPathAbsolute($file)) {
             $file = $base . '/' . $file;
         }
         $s->addTestFile($file);
     }
     return $s;
 }
Пример #5
0
 /**
  * @dataProvider pathData
  */
 public function testIsPathAbsolute($path, $expected)
 {
     if ($expected) {
         $this->assertTrue(AgaviToolkit::isPathAbsolute($path));
     } else {
         $this->assertFalse(AgaviToolkit::isPathAbsolute($path));
     }
 }
 /**
  * Check to see if a configuration file has been modified and if so
  * recompile the cache file associated with it.
  *
  * If the configuration file path is relative, the path itself is relative
  * to the Agavi "core.app_dir" application setting.
  *
  * @param      string A filesystem path to a configuration file.
  * @param      string An optional context name for which the config should be
  *                    read.
  *
  * @return     string An absolute filesystem path to the cache filename
  *                    associated with this specified configuration file.
  *
  * @throws     <b>AgaviUnreadableException</b> If a requested configuration
  *                                             file does not exist.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public static function checkConfig($config, $context = null)
 {
     $config = AgaviToolkit::normalizePath($config);
     // the full filename path to the config, which might not be what we were given.
     $filename = AgaviToolkit::isPathAbsolute($config) ? $config : AgaviToolkit::normalizePath(AgaviConfig::get('core.app_dir')) . '/' . $config;
     if (!is_readable($filename)) {
         throw new AgaviUnreadableException('Configuration file "' . $filename . '" does not exist or is unreadable.');
     }
     // the cache filename we'll be using
     $cache = self::getCacheName($config, $context);
     if (self::isModified($filename, $cache)) {
         // configuration file has changed so we need to reparse it
         self::callHandler($config, $filename, $cache, $context);
     }
     return $cache;
 }
Пример #7
0
 /**
  * Initialize a suite from the given instructions and add registered tests.
  *
  * @param      string Name of the suite
  * @param      array  An array containing information about the suite
  *
  * @return     AgaviTestSuite The initialized test suite object.
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      1.1.0
  */
 protected static function createSuite($name, array $suite)
 {
     $base = null == $suite['base'] ? 'tests' : $suite['base'];
     if (!AgaviToolkit::isPathAbsolute($base)) {
         $base = AgaviConfig::get('core.testing_dir') . '/' . $base;
     }
     $s = new $suite['class']($name);
     if (!empty($suite['includes'])) {
         $files = iterator_to_array(new RecursiveIteratorIterator(new AgaviRecursiveDirectoryFilterIterator(new RecursiveDirectoryIterator($base), $suite['includes'], $suite['excludes']), RecursiveIteratorIterator::CHILD_FIRST));
         // ensure that the execution order of the tests is always in deterministic
         // order and doesn't depend on the filesystem order
         usort($files, function ($a, $b) {
             return strcmp($a->getPathName(), $b->getPathName());
         });
         foreach ($files as $finfo) {
             if ($finfo->isFile()) {
                 $s->addTestFile($finfo->getPathName());
             }
         }
     }
     foreach ($suite['testfiles'] as $file) {
         if (!AgaviToolkit::isPathAbsolute($file)) {
             $file = $base . '/' . $file;
         }
         $s->addTestFile($file);
     }
     return $s;
 }