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));
 }
 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));
 }
Beispiel #3
0
 /**
  * @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();
 }
 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 . '"!');
 }
Beispiel #5
0
 private function getRootPath($namespace)
 {
     return RootClassLoader::getLoaderByNamespace($namespace)->getRootPath();
 }
 /**
  * @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);
     }
 }
Beispiel #7
0
 /**
  * Loads the email template regarding the configuration.
  *
  * @param string $namespace The namespace of the template.
  * @param string $template The name of the template.
  *
  * @return string The mail template content.
  * @throws IncludeException In case the template file cannot be loaded.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 19.10.2011<br />
  */
 private function getEmailTemplateContent($namespace, $template)
 {
     $loader = RootClassLoader::getLoaderByNamespace($namespace);
     $rootPath = $loader->getRootPath();
     $vendor = $loader->getVendorName();
     $fqNamespace = str_replace('\\', '/', str_replace($vendor . '\\', '', $namespace));
     $file = $rootPath . '/' . $fqNamespace . '/' . $template . '.html';
     if (file_exists($file)) {
         return file_get_contents($file);
     }
     throw new IncludeException('Email template file "' . $file . '" cannot be loaded. ' . 'Please review your contact module configuration!');
 }
 public function setUp()
 {
     // register config-only class loader
     $this->configRootPath = dirname(__FILE__) . '/config';
     RootClassLoader::addLoader(new StandardClassLoader(self::VENDOR_NAME, null, $this->configRootPath));
 }
 /**
  * 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.');
     }
 }
 private function getRootPath()
 {
     return RootClassLoader::getLoaderByVendor('APF')->getRootPath();
 }
 /**
  * Generates the code for the object, which extends the base object.
  *
  * @param string $name The object's name.
  *
  * @return string The PHP code.
  *
  * @author Ralf Schubert
  * @version 0.1,  15.01.2011<br />
  */
 protected function generateObjectCode($name)
 {
     $class = $this->domainObjectsTable[$name]['Class'];
     $className = RootClassLoader::getClassName($class);
     return '/**' . PHP_EOL . ' * This class represents the "' . $class . '" domain object.' . PHP_EOL . ' * <p/>' . PHP_EOL . ' * Please use this class to add your own functionality.' . PHP_EOL . ' */' . PHP_EOL . 'class ' . $className . ' extends ' . $className . 'Base {' . PHP_EOL . PHP_EOL . '   /**' . PHP_EOL . '    * Call the parent\'s constructor because the object name needs to be set.' . PHP_EOL . '    * <p/>' . PHP_EOL . '    * To create an instance of this object, just call' . PHP_EOL . '    * <code>' . PHP_EOL . '    * use ' . $class . ';' . PHP_EOL . '    * $object = new ' . $className . '();' . PHP_EOL . '    * </code>' . PHP_EOL . '    *' . PHP_EOL . '    * @param string $objectName The internal object name of the domain object.' . PHP_EOL . '    */' . PHP_EOL . '   public function __construct($objectName = null) {' . PHP_EOL . '      parent::__construct();' . PHP_EOL . '   }' . PHP_EOL . PHP_EOL . '}';
 }
 /**
  * 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!');
     }
 }
Beispiel #13
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>';
 }
Beispiel #14
0
 protected function setUp()
 {
     RootClassLoader::addLoader(new StandardClassLoader(self::VENDOR, self::SOURCE_PATH));
 }
Beispiel #15
0
// In case of symlink usage or multi-project installation, you can define it manually.         //
/////////////////////////////////////////////////////////////////////////////////////////////////
if (!isset($apfClassLoaderRootPath)) {
    $apfClassLoaderRootPath = str_replace('/core', '', str_replace('\\', '/', dirname(__FILE__)));
}
// Manual definition of the configuration root path allows separation of APF source and configuration
// files. By default, configuration files reside under the same root folder.
if (!isset($apfClassLoaderConfigurationRootPath)) {
    $apfClassLoaderConfigurationRootPath = $apfClassLoaderRootPath;
}
// include the class loader
include_once dirname(__FILE__) . '/loader/ClassLoader.php';
include_once dirname(__FILE__) . '/loader/StandardClassLoader.php';
include_once dirname(__FILE__) . '/loader/RootClassLoader.php';
// register class loader before including/configuring further elements
\APF\core\loader\RootClassLoader::addLoader(new \APF\core\loader\StandardClassLoader('APF', $apfClassLoaderRootPath, $apfClassLoaderConfigurationRootPath));
spl_autoload_register(['\\APF\\core\\loader\\RootClassLoader', 'load']);
// register the APF error handler to be able to easily configure the error handling mechanism
GlobalExceptionHandler::registerExceptionHandler(new DefaultExceptionHandler());
GlobalExceptionHandler::enable();
// let PHP raise and display all errors to be able to handle them suitable by the APF error handler.
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('html_errors', 'off');
// register the APF error handler to be able to easily configure the error handling mechanism
GlobalErrorHandler::registerErrorHandler(new DefaultErrorHandler());
GlobalErrorHandler::enable();
// Define base parameters of the framework's core and tools layer
Registry::register('APF\\core', 'Environment', 'DEFAULT');
Registry::register('APF\\core', 'InternalLogTarget', 'apf');
Registry::register('APF\\core', 'Charset', 'UTF-8');
Beispiel #16
0
 /**
  * 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';
     }
 }
 public function testGetVendor()
 {
     $this->assertEquals('APF', RootClassLoader::getVendor('APF\\StandardClassLoader'));
     $this->assertEquals('APF', RootClassLoader::getVendor('APF\\core\\loader\\StandardClassLoader'));
 }