Ejemplo n.º 1
0
 /**
  * Autoloader function that will attempt to load the correct class library
  * based on the name given.
  *
  * It will also automagcailly include an 'Exceptions.php' file if it is found.
  *
  * @param string $class
  */
 public static function autoloadClass($class)
 {
     if (stripos($class, '_controller_') !== false) {
         $modDir = realpath(self::$_instance->getDir('modules'));
         $classSplit = explode('_', strtolower($class));
         $cntrlrIndex = array_search('controller', $classSplit);
         // Store cntrlr file and exception file paths
         $modDir = $modDir . '/' . implode('_', array_slice($classSplit, 0, $cntrlrIndex));
         $classFile = $modDir . '/controllers/' . implode('_', array_slice($classSplit, $cntrlrIndex + 1)) . '.php';
         $exceptions = $modDir . '/Exceptions.php';
     } else {
         // Load internal Zula lib
         $libDir = realpath(self::$_instance->getDir('libs'));
         $classSplit = array_map('ucfirst', explode('_', strtolower($class)));
         $classFile = $libDir . '/' . implode('/', $classSplit) . '.php';
         $exceptions = $libDir . '/' . $classSplit[0] . '/Exceptions.php';
     }
     if (isset($exceptions) && is_readable($exceptions)) {
         include_once $exceptions;
     }
     if (is_readable($classFile)) {
         include $classFile;
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns dirname(value).
  *
  * @param  mixed $key
  * @return mixed
  */
 public function getDir($key)
 {
     return $this->_filter->getDir($this->_source[$key]);
 }
Ejemplo n.º 3
0
Archivo: Alias.php Proyecto: pmvc/pmvc
 /**
  * Get alias function.
  *
  * @param object $self   Same with object $this
  * @param string $method Call which funciton
  * @param object $caller Caller
  *
  * @return mixed
  */
 public function get($self, $method, $caller)
 {
     if (!is_callable([$self, 'getDir'])) {
         return false;
     }
     $path = $self->getDir() . 'src/_' . $method . '.php';
     if (!realpath($path)) {
         return false;
     }
     $r = l($path, _INIT_CONFIG);
     if (!isset($r->var[_INIT_CONFIG][_CLASS])) {
         return !trigger_error('Not defined default Class');
     } else {
         $class = $r->var[_INIT_CONFIG][_CLASS];
         if (!class_exists($class)) {
             return !trigger_error('Default Class not exits. [' . $class . ']');
         }
         $func = new $class($caller);
         $func->caller = $caller;
     }
     if (!is_callable($func)) {
         return !trigger_error('Not implement __invoke function');
     }
     if (isArray($self) && !isset($self[$method])) {
         $self[$method] = $func;
     } elseif (!isset($self->{$method})) {
         $self->{$method} = $func;
     }
     return $func;
 }