コード例 #1
0
 public static function tearDownAfterClass()
 {
     // restore previous configuration provider to not disturb other tests
     ConfigurationManager::registerProvider('ini', self::$originalProvider);
     // remove static configuration class loader used for test purposes only
     RootClassLoader::removeLoader(RootClassLoader::getLoaderByVendor(self::TEST_VENDOR));
 }
コード例 #2
0
 public static function tearDownAfterClass()
 {
     // remove configuration provider to not disturb other tests
     ConfigurationManager::removeProvider('php');
     // remove static configuration class loader used for test purposes only
     RootClassLoader::removeLoader(RootClassLoader::getLoaderByVendor(self::TEST_VENDOR));
 }
コード例 #3
0
ファイル: SMSXMLMapper.php プロジェクト: GeneralCrime/code
 /**
  * @throws SMSConfigurationException
  * @version :  v0.1
  */
 public function setup()
 {
     $fileNamespace = $this->getXMLFileNamespace();
     $vendor = RootClassLoader::getVendor($fileNamespace);
     $libPath = RootClassLoader::getLoaderByVendor($vendor)->getRootPath();
     $basePath = str_replace('\\', '/', RootClassLoader::getNamespaceWithoutVendor($fileNamespace));
     $filename = $this->getXMLFilename();
     $fullPath = $libPath . (empty($basePath) ? '' : '/' . $basePath) . '/' . $filename;
     if (!file_exists($fullPath)) {
         throw new SMSConfigurationException('[SMSXMLMapper::setup()] XML file "' . $filename . '" in namespace "' . $fileNamespace . '" could not be found. (Full path: "' . $fullPath . '").', E_USER_ERROR);
     }
     $this->XML_DOMDocument = new \DOMDocument();
     $this->XML_DOMDocument->load($fullPath);
     // we need to validate the document, to let the DTD be parsed and the id attribute be recognized as id by DOMDocument::getElementById().
     // do not care about failures this time
     $this->XML_DOMDocument->validate();
 }
コード例 #4
0
 public function run()
 {
     // Bug 782: read params and sanitize them to avoid security issues
     $namespace = $this->getSanitizedNamespace();
     $fileBody = $this->getSanitizedFileBody();
     $extension = $this->getSanitizedExtension();
     $fileName = $fileBody . '.' . $extension;
     // Bug 782: check for allowed extension to avoid access to configuration files.
     $allowedExtensions = $this->getAllowedExtensions();
     if ($this->isAllowedExtension($allowedExtensions, $extension)) {
         // ID#107: get specific vendor and map to root path instead of APF-only
         $vendor = RootClassLoader::getVendor($namespace);
         $rootPath = RootClassLoader::getLoaderByVendor($vendor)->getRootPath();
         // Re-map namespace since as of 2.0 it contains the vendor that
         // refers to the root path. Keeping the vendor would cause the
         // sub-path to map to the wrong folder.
         $namespace = str_replace($vendor . '\\', '', $namespace);
         $filePath = $rootPath . '/' . str_replace('\\', '/', $namespace) . '/' . $fileName;
         if (file_exists($filePath)) {
             // map extension to known mime type
             $contentType = $this->getMimeType($allowedExtensions, $extension);
             // send desired header
             $response = $this->getResponse();
             $response->setHeader(new HeaderImpl('Content-Type', $contentType));
             // send headers to allow caching
             $delta = 7 * 24 * 60 * 60;
             // caching for 7 days
             $response->setHeader(new HeaderImpl('Cache-Control', 'public; max-age=' . $delta));
             $modifiedDate = date('D, d M Y H:i:s \\G\\M\\T', time());
             $response->setHeader(new HeaderImpl('Last-Modified', '' . $modifiedDate));
             $expiresDate = date('D, d M Y H:i:s \\G\\M\\T', time() + $delta);
             $response->setHeader(new HeaderImpl('Expires', '' . $expiresDate));
             $response->send(false);
             @readfile($filePath);
             exit;
         } else {
             throw new Exception('File with name "' . $fileName . '" cannot be found under sub-path "' . $namespace . '"!');
         }
     }
     throw new Exception('You are not allowed to request "' . $fileName . '" under sub-path "' . $namespace . '"!');
 }
コード例 #5
0
 /**
  * @param string $namespace The namespace of the desired config.
  * @param string $context The current application's context.
  * @param string $language The current application's language.
  * @param string $environment The current environment.
  * @param string $name The name of the desired config.
  *
  * @return string The appropriate file path.
  * @throws ConfigurationException In case the root path cannot be determined using the applied namespace.
  */
 protected function getFilePath($namespace, $context, $language, $environment, $name)
 {
     // assemble the context
     $contextPath = $this->omitContext || $context === null ? '' : '/' . str_replace('\\', '/', $context);
     // assemble file name
     $fileName = $this->omitEnvironment || $environment === null ? '/' . $name : '/' . $environment . '_' . $name;
     // gather namespace and full(!) config name and use class loader to determine root path
     try {
         // ID#164: check whether we have a vendor-only namespace declaration to support
         // $this->getFilePath('APF', ...) calls.
         $vendorOnly = RootClassLoader::isVendorOnlyNamespace($namespace);
         if ($vendorOnly === true) {
             $classLoader = RootClassLoader::getLoaderByVendor($namespace);
         } else {
             $classLoader = RootClassLoader::getLoaderByNamespace($namespace);
         }
         $rootPath = $classLoader->getConfigurationRootPath();
         // Add config sub folder only if desired. Allows you to set up a separate
         // vendor-based config folder without another /config sub-folder (e.g.
         // /src/VENDOR/foo/bar/Baz.php and /config/VENDOR/foo/bar/DEFAULT_config.ini).
         if ($this->omitConfigSubFolder === false) {
             $rootPath .= '/config';
         }
         if ($vendorOnly === true) {
             $fqNamespace = '';
         } else {
             $vendor = $classLoader->getVendorName();
             $fqNamespace = '/' . str_replace('\\', '/', str_replace($vendor . '\\', '', $namespace));
         }
         return $rootPath . $fqNamespace . $contextPath . $fileName;
     } catch (Exception $e) {
         // in order to ease debugging, we are wrapping the class loader exception to a more obvious exception message
         throw new ConfigurationException('Class loader root path for namespace "' . $namespace . '" cannot be determined.' . ' Please double-check your configuration!', E_USER_ERROR, $e);
     }
 }
コード例 #6
0
 /**
  * Parses a dedicated language file defined by it's namespace and language file name.
  *
  * @param string $namespace the namespace of the language file
  * @param string $filename the name of the language file
  *
  * @throws InvalidArgumentException In case the translation file cannot be found.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 19.11.2008<br />
  */
 protected function parseLanguageFile($namespace, $filename)
 {
     // create file name
     $rootPath = RootClassLoader::getLoaderByVendor('APF')->getRootPath();
     $fileName = $rootPath . '/' . str_replace('\\', '/', $namespace) . '/' . $filename . '.' . $this->language . '.xml';
     if (file_exists($fileName)) {
         // create a DOM document from the xml string
         $domDoc = @simplexml_load_string(file_get_contents($fileName));
         // translate tokens or throw error
         if ($domDoc instanceof \SimpleXMLElement) {
             $this->content = $this->parseLanguageTokens($this->content, $domDoc);
         } else {
             throw new InvalidArgumentException('[LanguageDependentImportTemplateTag::__parseLanguageFile()] The translation file ("' . $filename . '.xml") in namespace "' . $namespace . '" does not contain a valid XML document! The content is returned without translation.');
         }
     } else {
         throw new InvalidArgumentException('[LanguageDependentImportTemplateTag::__parseLanguageFile()] The desired translation file ("' . $filename . '.xml") does not exist in namespace "' . $namespace . '". Please check your tag definition or your configurarion! The content is returned without translation.');
     }
 }
コード例 #7
0
 private function getRootPath()
 {
     return RootClassLoader::getLoaderByVendor('APF')->getRootPath();
 }
コード例 #8
0
ファイル: Document.php プロジェクト: GeneralCrime/code
 /**
  * Generates the file path of the desired template.
  * <p/>
  * Overwriting this method allows you to use a different algorithm of creating the
  * path within your custom tag implementations.
  *
  * @param string $namespace The namespace of the template.
  * @param string $name The (file) name of the template.
  *
  * @return string The template file path of the referred APF template.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 31.10.2012<br />
  */
 protected function getTemplateFilePath($namespace, $name)
 {
     // gather namespace and full(!) template name and use class loader to determine root path
     // ID#152: check whether we have a vendor-only namespace declaration to support
     // Document::getTemplateFileName('APF', 'foo') calls
     $vendorOnly = RootClassLoader::isVendorOnlyNamespace($namespace);
     if ($vendorOnly === true) {
         $classLoader = RootClassLoader::getLoaderByVendor($namespace);
     } else {
         $classLoader = RootClassLoader::getLoaderByNamespace($namespace);
     }
     $rootPath = $classLoader->getRootPath();
     if ($vendorOnly === true) {
         return $rootPath . '/' . $name . '.html';
     } else {
         $vendor = $classLoader->getVendorName();
         return $rootPath . '/' . str_replace('\\', '/', str_replace($vendor . '\\', '', $namespace)) . '/' . $name . '.html';
     }
 }
コード例 #9
0
 /**
  * Helper method to get the XML string.<br />
  *
  * @return string Content of the XML stream of the source or null.
  * @throws InvalidArgumentException In case of XSLT errors.
  *
  * @author Tobias Lückel
  * @version
  * Version 0.1, 17.08.2010<br />
  */
 protected function getXML()
 {
     // fetch RSS source
     $xmlSource = $this->getXMLSource();
     if ($xmlSource != null) {
         $plainXml = file_get_contents($xmlSource);
         if ($plainXml !== false) {
             $xsltNamespace = $this->getDocument()->getAttribute('xslt_namespace');
             $xsltFile = $this->getDocument()->getAttribute('xslt_file');
             if ($xsltNamespace != null && $xsltFile != null) {
                 // create XML source
                 $xml = new \DOMDocument();
                 $xml->loadXML($plainXml);
                 $xsl = new \DOMDocument();
                 $rootPath = RootClassLoader::getLoaderByVendor('APF')->getRootPath();
                 $xsl->load($rootPath . '/' . str_replace('\\', '/', $xsltNamespace) . '/' . $xsltFile . '.xsl');
                 // configure transformer
                 $proc = new \XSLTProcessor();
                 $proc->importStyleSheet($xsl);
                 // import XSL document
                 $result = $proc->transformToXML($xml);
                 if ($result) {
                     return $result;
                 } else {
                     throw new InvalidArgumentException('[Weather2Controller::getXML()] XSLT Error!');
                 }
             } else {
                 return $plainXml;
             }
         } else {
             return null;
         }
     } else {
         throw new InvalidArgumentException('[Weather2Controller::getXML()] Attribute "xml_source" not present in "core:importdesign" tag for weather module!');
     }
 }
コード例 #10
0
 public function transform()
 {
     $rootPath = RootClassLoader::getLoaderByVendor('APF')->getRootPath();
     return '<style type="text/css">' . PHP_EOL . file_get_contents($rootPath . '/modules/usermanagement/pres/css/umgt.css') . PHP_EOL . '</style>';
 }
コード例 #11
0
 public function testIllegalVendor()
 {
     $this->setExpectedException('InvalidArgumentException');
     RootClassLoader::getLoaderByVendor('FOO');
 }