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()); } }
/** * Load the resource map * * @return $this */ public function loadResourceMap() { $dirIterator = new \RecursiveDirectoryIterator($this->path->getDir('vendor/devvoh/parable/src'), \RecursiveDirectoryIterator::SKIP_DOTS); $iteratorIterator = new \RecursiveIteratorIterator($dirIterator); foreach ($iteratorIterator as $path => $file) { /** @var \SplFileInfo $file */ /* * Specifically exclude all non-php files and Bootstrap, since it will attempt to register everything again * and isn't a class anyway. */ if ($file->getFilename() === 'Bootstrap.php' || $file->getFilename() === 'parable.php' || $file->getExtension() !== 'php' || strpos($file->getRealPath(), '/Cli/') !== false) { continue; } $className = str_replace('.' . $file->getExtension(), '', $file->getFilename()); $fullClassName = str_replace($this->path->getDir('vendor/devvoh/parable/src'), '', $file->getRealPath()); $fullClassName = str_replace('.' . $file->getExtension(), '', $fullClassName); $fullClassName = str_replace('/', '\\', 'Parable' . $fullClassName); $reflectionClass = new \ReflectionClass($fullClassName); if (!$reflectionClass->isInstantiable()) { continue; } $this->resourceMap[$className] = $fullClassName; } return $this; }
/** * Attempt to load the templatePath * * @param string $templatePath * * @return $this */ protected function loadTemplatePath($templatePath) { if (!file_exists($templatePath)) { $templatePath = $this->path->getDir($templatePath); } if (file_exists($templatePath)) { require $templatePath; } return $this; }
/** * @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; }
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); } } }
protected function init() { $this->cli->writeLine('Welcome to Parable. We will now initialize your Parable install.')->br()->writeLine('After completing this process, you will have an environment based on')->writeLine('Parable, complete with folder structure files to start with.')->br()->write('Press a key to continue')->waitForKey(); $this->cli->writeLine('Creating folder structure...'); mkdir($this->path->getDir('app')); mkdir($this->path->getDir('app/Config')); mkdir($this->path->getDir('app/Controller')); mkdir($this->path->getDir('app/Model')); mkdir($this->path->getDir('app/View')); mkdir($this->path->getDir('app/View/Home')); mkdir($this->path->getDir('public')); $this->cli->writeLine('Copying files...'); copy($this->path->getDir('vendor/devvoh/parable/structure/.htaccess'), $this->path->getDir('.htaccess')); copy($this->path->getDir('vendor/devvoh/parable/structure/public/.htaccess'), $this->path->getDir('public/.htaccess')); copy($this->path->getDir('vendor/devvoh/parable/structure/public/index.php'), $this->path->getDir('public/index.php')); copy($this->path->getDir('vendor/devvoh/parable/structure/app/Routes.php'), $this->path->getDir('app/Routes.php')); copy($this->path->getDir('vendor/devvoh/parable/structure/app/Config/App.php'), $this->path->getDir('app/Config/App.php')); copy($this->path->getDir('vendor/devvoh/parable/structure/app/Controller/Home.php'), $this->path->getDir('app/Controller/Home.php')); copy($this->path->getDir('vendor/devvoh/parable/structure/app/Model/User.php'), $this->path->getDir('app/Model/User.php')); copy($this->path->getDir('vendor/devvoh/parable/structure/app/View/Home/index.phtml'), $this->path->getDir('app/View/Home/index.phtml')); }