Ejemplo n.º 1
0
 /**
  * Loads a controller
  *
  * @param string $controllerName
  * @param array $data
  * @param string|boolean $ns
  * @param boolean $createInstance
  *
  * @return controller|boolean
  */
 public static function load($controllerName, $data = [], $ns = false)
 {
     // explode it on @ -> 0 will be the directive + namespace + classname
     // >1 index will be methods
     $at_explode = explode('@', $controllerName);
     $controllerName = $at_explode[0];
     // remove the model name from the array
     array_splice($at_explode, 0, 1);
     // set default namespace
     if ($ns === false) {
         $ns = App::namespace();
     }
     // extract directive
     $dot_pos = strrpos($controllerName, '.');
     $directive = $dot_pos === false ? false : substr($controllerName, 0, $dot_pos) . '.';
     // now only contains the classname and namespace
     if ($dot_pos !== false) {
         $controllerName = substr($controllerName, $dot_pos + 1);
     }
     // register name should be the classname and namespace of the original load
     $registerName = $controllerName;
     // extract namespace and classname
     $back_pos = strrpos($controllerName, '\\');
     // namespace now contains default namespace or specified namespace
     $ns = $back_pos === false ? $ns : substr($controllerName, 0, $back_pos);
     // modelName now contains the classname
     if ($back_pos !== false) {
         $controllerName = substr($controllerName, $back_pos + 1);
     }
     // get file path and start inclusion
     $modelPath = $directive . $controllerName;
     if (self::exists($modelPath)) {
         $className = trim($ns, '\\') . '\\' . $controllerName;
         FileManager::include(App::controllers()->file($modelPath . '.php'));
         self::$_names[] = $registerName;
         self::$_name_bindings[$registerName] = $className;
         //data was passed
         if ($data != null && count($data) > 0) {
             if (method_exists($className, 'set')) {
                 foreach ($data as $key => $value) {
                     call_user_func([$className, 'set'], $key, $value);
                 }
             }
         }
         // execute requested @ functions
         // multiple methods can be called using multiple @ symbols
         $return_data = [];
         $return_data_keys = [];
         foreach ($at_explode as $method) {
             if (method_exists($className, $method)) {
                 $return = call_user_func([$className, $method]);
                 if (is_array($return)) {
                     $return_data[$method] = $return;
                     $return_data_keys[] = $method;
                 }
             }
         }
         // echo array if any data
         $return_data_count = count($return_data);
         if ($return_data_count == 1) {
             echo json_encode($return_data[$return_data_keys[0]]);
         } elseif ($return_data_count > 1) {
             echo json_encode($return_data);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 */
namespace Application;

use Application\Core\App;
use Application\Core\DirectoryHandler;
use Application\Core\FileHandler;
use Application\Core\PackagistHandler;
use Application\Core\FileManager;
//load file map
$autoload = PackagistHandler::autoload();
foreach ($autoload as $package => $loader) {
    $package_name = strtolower(substr($package, 0, strrpos($package, '-')));
    $package_directory = __DIR__ . "/{$package_name}/{$package}/";
    if (isset($loader['files'])) {
        foreach ($loader['files'] as $file) {
            FileManager::include($package_directory . $file);
        }
    }
}
// autoloading
spl_autoload_register(function ($class) {
    $autoload = PackagistHandler::autoload();
    foreach ($autoload as $package => $loader) {
        $package_name = strtolower(substr($package, 0, strrpos($package, '-')));
        $package_directory = __DIR__ . "/{$package_name}/{$package}/";
        if (isset($loader[$class]) && is_file($package_directory . $loader[$class])) {
            FileManager::include($package_directory . $loader[$class]);
        }
    }
    return false;
});
Ejemplo n.º 3
0
 public function execute()
 {
     //this is what happens when a view is executed
     $path = $this->_filePath;
     if ($this->_isWow) {
         $path = Wow::view($this->_filePath, App::layouts(), App::modules());
         if ($this->_version !== false) {
             $dot_pos = strrpos($path, '.', -5);
             $path = substr($path, 0, $dot_pos) . '.v' . $this->_version . '.php';
         }
     }
     FileManager::include($path);
 }
Ejemplo n.º 4
0
 /**
  * Includes library files
  */
 public static function libraries()
 {
     $libsdir = self::libs();
     $files = $libsdir->files(true);
     //check .exclude files
     $excludes = [];
     foreach ($files as $key => $file) {
         if ($file->name() == '.exclude') {
             $excludes[] = $file;
             unset($files[$key]);
         }
     }
     foreach ($excludes as $exclude) {
         $parent = $exclude->parent();
         foreach ($files as $key => $file) {
             if (substr($file->parent(), 0, strlen($parent)) == $parent) {
                 unset($files[$key]);
             }
         }
     }
     //check .ignore files
     $ignores = [];
     foreach ($files as $key => $file) {
         if ($file->name() == '.ignore') {
             $ignores[] = $file;
             unset($files[$key]);
         }
     }
     foreach ($ignores as $ignore) {
         $lines = preg_split("/\\r\\n|\\r|\\n/", $ignore->read());
         $ignore_files = [$ignore];
         foreach ($lines as $line) {
             $ignore_files[] = new File($ignore->parent() . "/{$line}");
         }
         foreach ($files as $key => $file) {
             if (array_search($file, $ignore_files) !== false) {
                 unset($files[$key]);
             }
         }
     }
     //check .order files
     $orders = [];
     foreach ($files as $key => $file) {
         if ($file->name() == '.order') {
             $orders[] = $file;
             unset($files[$key]);
         }
     }
     foreach ($orders as $order) {
         $lines = preg_split("/\\r\\n|\\r|\\n/", $order->read());
         $included_files = [$order];
         foreach ($lines as $line) {
             $order_file = new File($order->parent() . "/{$line}");
             if ($order_file->exists()) {
                 $included_files[] = $order_file;
                 FileManager::include($order_file);
             }
         }
         //filter out the already included ones
         foreach ($files as $key => $file) {
             if (array_search($file, $included_files) !== false) {
                 unset($files[$key]);
             }
         }
     }
     //include remaining files
     foreach ($files as $file) {
         if ($file->extension() == 'php') {
             $file->include();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Includes the file
  */
 public function include()
 {
     if ($this->exists()) {
         return FileManager::include($this->_path);
     }
     return false;
 }