public function load() { $dirIterator = new \RecursiveDirectoryIterator($this->path->getDir('app/Config'), \RecursiveDirectoryIterator::SKIP_DOTS); $iteratorIterator = new \RecursiveIteratorIterator($dirIterator); $configClasses = []; foreach ($iteratorIterator as $file) { /** @var \SplFileInfo $file */ if ($file->getExtension() !== 'php') { continue; } $className = 'Config\\' . str_replace('.php', '', $file->getFilename()); /** @var \Parable\Framework\Interfaces\Config $configClass */ $configClass = \Parable\DI\Container::get($className); if ($configClass instanceof \Parable\Framework\Interfaces\Config) { if ($configClass->getSortOrder() === null) { array_push($configClasses, $configClass); } else { $configClasses[$configClass->getSortOrder()] = $configClass; } } } // Sort the array by key so the sortOrder is reflected in the actual order ksort($configClasses); // Now get all the values from the config classes foreach ($configClasses as $configClass) { $this->config = array_merge($this->config, $configClass->getValues()); } }
/** * @param \Parable\Routing\Route $route * * @return $this */ public function dispatch(\Parable\Routing\Route $route) { $this->hook->trigger('parable_dispatch_before', $route); $controller = null; /* Start output buffering and set $content to null */ $content = null; $this->response->startOutputBuffer(); /* Call the relevant code */ if ($route->controller && $route->action) { $controller = \Parable\DI\Container::get($route->controller); $content = $controller->{$route->action}($route); } elseif ($route->callable) { $call = $route->callable; $content = $call($route); } /* Try to get the relevant view */ $templateFile = null; if ($route->template) { $templateFile = $this->path->getDir($route->template); } else { if ($controller) { $reflection = new \ReflectionClass($controller); $templateFile = $this->path->getDir('app/View/' . $reflection->getShortName() . '/' . $route->action . '.phtml'); } } if ($templateFile && file_exists($templateFile)) { $this->view->setTemplatePath($templateFile); $this->view->render(); } /* Get the output buffer content and check if $content holds anything. If so, append it to the $bufferContent */ $bufferContent = $this->response->returnOutputBuffer(); if ($content) { $bufferContent .= $content; } /* And append the content to the response object */ $this->response->appendContent($bufferContent); $this->hook->trigger('parable_dispatch_after', $route); return $this; }
* @package Parable Framework * @license MIT * @author Robin de Graaf <*****@*****.**> * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment */ /* * Define some global values */ define('DS', DIRECTORY_SEPARATOR); define('BASEDIR', realpath(__DIR__ . DS . '..' . DS . '..' . DS . '..' . DS . '..' . DS . '..')); /* * Set error reporting level */ error_reporting(E_ALL); ini_set('log_errors', '1'); ini_set('display_errors', '1'); /* * Attempt to register composer's autoloader, which will be required for components */ require_once BASEDIR . '/vendor/autoload.php'; /* * And load and register the framework's autoloader */ $autoloader = \Parable\DI\Container::get(\Parable\Framework\Autoloader::class); $autoloader->addLocation(BASEDIR . '/app'); $autoloader->register(); if (PHP_SAPI === 'cli') { return \Parable\DI\Container::get(\Parable\Cli\App::class); } return \Parable\DI\Container::get(\Parable\Framework\App::class); // @codingStandardsIgnoreEnd
/** * Magic get function to pass through all calls to DI-able classes. * * @param string $property * * @return null|object */ public function __get($property) { $mappedProperty = $this->toolkit->getResourceMapping(ucfirst($property)); if ($mappedProperty) { return \Parable\DI\Container::get($mappedProperty); } return null; }
/** * @return Query */ public static function createInstance() { return \Parable\DI\Container::create(static::class); }
/** * Create a repository to work with model of type $modelName (full namespaced name) * * @param string $modelName * * @return \Parable\ORM\Repository */ public function getRepository($modelName) { /** @var \Parable\ORM\Model $model */ $model = \Parable\DI\Container::create($modelName); /** @var \Parable\ORM\Repository $repository */ $repository = \Parable\DI\Container::create(\Parable\ORM\Repository::class); $repository->setModel($model); return $repository; }
protected function loadInits() { $locations = $this->config->get('initLocations'); if (!is_array($locations)) { return; } foreach ($locations as $location) { $directory = $this->path->getDir($location); if (!file_exists($directory)) { continue; } $dirIterator = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS); $iteratorIterator = new \RecursiveIteratorIterator($dirIterator); foreach ($iteratorIterator as $file) { /** @var \SplFileInfo $file */ if ($file->getExtension() !== 'php') { continue; } $className = '\\Init\\' . str_replace('.' . $file->getExtension(), '', $file->getFilename()); \Parable\DI\Container::create($className); } } }