getNamespacePrefix() публичный Метод

Get the applicable namespace prefix for a component section. Possible sections: auto Auto-detect which is the current component section inverse The inverse area than auto site Frontend admin Backend
public getNamespacePrefix ( string $section = 'auto' ) : string
$section string The section you want to get information for
Результат string The namespace prefix for the component's classes, e.g. \Foobar\Example\Site\
Пример #1
0
 /**
  * Load a helper file
  *
  * @param   string $helperClass    The last part of the name of the helper
  *                                 class.
  *
  * @return  void
  *
  * @deprecated  3.0  Just use the class in your code. That's what the autoloader is for.
  */
 public function loadHelper($helperClass = null)
 {
     // Get the helper class name
     $className = '\\' . $this->container->getNamespacePrefix() . 'Helper\\' . ucfirst($helperClass);
     // This trick autoloads the helper class. We can't instantiate it as
     // helpers are (supposed to be) abstract classes with static method
     // interfaces.
     class_exists($className);
 }
Пример #2
0
 /**
  * Load a class for one of the form's entities of a particular type.
  * Currently, it makes sense to use this method for the "field" and "rule" entities
  * (but you can support more entities in your subclass).
  *
  * @param   string $entity One of the form entities (field, header or rule).
  * @param   string $type   Type of an entity.
  *
  * @return  mixed  Class name on success or false otherwise.
  *
  * @since   2.0
  */
 public function loadClass($entity, $type)
 {
     // Get the prefixes for namespaced classes (FOF3 way)
     $namespacedPrefixes = array($this->container->getNamespacePrefix(), 'FOF30\\');
     // Get the prefixes for non-namespaced classes (FOF2 and Joomla! way)
     $plainPrefixes = array('J');
     // If the type is given as prefix.type add the custom type into the two prefix arrays
     if (strpos($type, '.')) {
         list($prefix, $type) = explode('.', $type);
         array_unshift($plainPrefixes, $prefix);
         array_unshift($namespacedPrefixes, $prefix);
     }
     // First try to find the namespaced class
     foreach ($namespacedPrefixes as $prefix) {
         $class = rtrim($prefix, '\\') . '\\Form\\' . ucfirst($entity) . '\\' . ucfirst($type);
         if (class_exists($class, true)) {
             return $class;
         }
     }
     // TODO The rest of the code is legacy and will be removed in a future version
     // Then try to find the non-namespaced class
     $classes = array();
     foreach ($plainPrefixes as $prefix) {
         $class = \JString::ucfirst($prefix, '_') . 'Form' . \JString::ucfirst($entity, '_') . \JString::ucfirst($type, '_');
         if (class_exists($class, true)) {
             return $class;
         }
         $classes[] = $class;
     }
     // Get the field search path array.
     $reflector = new \ReflectionClass('\\JFormHelper');
     $addPathMethod = $reflector->getMethod('addPath');
     $addPathMethod->setAccessible(true);
     $paths = $addPathMethod->invoke(null, $entity);
     // If the type is complex, add the base type to the paths.
     if ($pos = strpos($type, '_')) {
         // Add the complex type prefix to the paths.
         for ($i = 0, $n = count($paths); $i < $n; $i++) {
             // Derive the new path.
             $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos));
             // If the path does not exist, add it.
             if (!in_array($path, $paths)) {
                 $paths[] = $path;
             }
         }
         // Break off the end of the complex type.
         $type = substr($type, $pos + 1);
     }
     // Try to find the class file.
     $type = strtolower($type) . '.php';
     foreach ($paths as $path) {
         if ($file = \JPath::find($path, $type)) {
             require_once $file;
             foreach ($classes as $class) {
                 if (class_exists($class, false)) {
                     return $class;
                 }
             }
         }
     }
     return false;
 }