Ejemplo n.º 1
0
 public function testGetLoaderByNamespace()
 {
     try {
         $loader = RootClassLoader::getLoaderByNamespace(self::VENDOR . '\\foo\\bar');
         $this->assertEquals(self::SOURCE_PATH, $loader->getRootPath());
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
     try {
         $loader = RootClassLoader::getLoaderByNamespace(self::VENDOR . '\\foo');
         $this->assertEquals(self::SOURCE_PATH, $loader->getRootPath());
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 4
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!');
 }
Ejemplo n.º 5
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';
     }
 }