/** * The RebuildFrameworkCache event handler deletes the events and routes * cache and executes the activation method on all modules. * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\CliRequest $request * @param \Zepi\Turbo\Response\Response $response */ public function execute(Framework $framework, CliRequest $request, Response $response) { $framework->getRuntimeManager()->clearCache(false); $framework->getRouteManager()->clearCache(false); $framework->getModuleManager()->reactivateModules(); $response->setOutputPart('cacheCleared', 'The cache was successfully cleared and rebuilt!'); }
/** * Validates the value. Returns true if everything is okey or an Error * object if there was an error. * * @access public * @param \Zepi\Turbo\Framework $framework * @return boolean|\Zepi\Web\UserInterface\Form\Error */ public function validate(Framework $framework) { $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager'); if (!filter_var($this->value, FILTER_VALIDATE_EMAIL)) { return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is not an valid email address.', '\\Zepi\\Web\\UserInterface', array('field' => $this->label))); } return true; }
/** * This event handler lists all activated modules with the description * of each module. * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\CliRequest $request * @param \Zepi\Turbo\Response\Response $response */ public function execute(Framework $framework, CliRequest $request, Response $response) { $output = 'Activated modules:' . PHP_EOL; $output .= '==================' . PHP_EOL . PHP_EOL; $moduleManager = $framework->getModuleManager(); foreach ($moduleManager->getModules() as $namespace => $module) { $properties = $moduleManager->getModuleProperties($module->getDirectory()); $info = $properties->module; $output .= '- ' . $info->name . ' ' . $info->version . ' (' . $namespace . '):' . PHP_EOL; $output .= ' ' . $info->description . PHP_EOL . PHP_EOL; } $response->setOutputPart('modules', $output); }
/** * Send the api result to the client * * @param array $result */ public function sendResponse($result) { if (!$this->framework->getRequest() instanceof WebRequest) { return; } return $this->restHelper->sendResponse($this->framework->getRequest(), $this->framework->getResponse(), $result); }
/** * Returns the framework manager for the given class name * * @param string $className * @return object * * @throws \Zepi\Turbo\Exception Cannot find framework manager "{className}". */ protected function getFrameworkManager($className) { switch ($className) { case 'Zepi\\Turbo\\Manager\\DataSourceManager': return $this->framework->getDataSourceManager(); break; case 'Zepi\\Turbo\\Manager\\DependencyInjectionManager': return $this->framework->getDependencyInjectionManager(); break; case 'Zepi\\Turbo\\Manager\\ModuleManager': return $this->framework->getModuleManager(); break; case 'Zepi\\Turbo\\Manager\\RequestManager': return $this->framework->getRequestManager(); break; case 'Zepi\\Turbo\\Manager\\RouteManager': return $this->framework->getRouteManager(); break; case 'Zepi\\Turbo\\Manager\\RuntimeManager': return $this->framework->getRuntimeManager(); break; default: throw new Exception('Cannot find framework manager "' . $className . '".'); break; } }
/** * Clears the handlers cache and reactivates the modules * to rebuild the cache. * * @access public * @param boolean $reactivateModules */ public function clearCache($reactivateModules = true) { $this->handlers = array(); if ($reactivateModules) { $this->framework->getModuleManager()->reactivateModules(); } }
/** * Returns all access levels * * @access public * @return array */ public function getAccessLevels() { // Give the modules the opportunity to add additional access levels $runtimeManager = $this->framework->getRuntimeManager(); $accessLevels = $runtimeManager->executeFilter('\\Zepi\\Core\\AccessControl\\Filter\\AccessLevelManager\\RegisterAccessLevels', $this->accessLevels); return $accessLevels; }
/** * Returns a instance of the Framework * * @static * @access public * @param string $rootDirectory * @return Framework */ public static function getFrameworkInstance($rootDirectory) { if (self::$instance === null) { self::$instance = new Framework($rootDirectory); self::$instance->initializeFramework(); } return self::$instance; }
/** * Renders a overview page for the given MenuEntry object * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Web\General\Entity\MenuEntry $menuEntry * @return string */ public function render(Framework $framework, MenuEntry $menuEntry) { // If the MenuEntry hasn't any children we return an empty string. if (!$menuEntry->hasChildren()) { return ''; } $templatesManager = $framework->getInstance('\\Zepi\\Web\\General\\Manager\\TemplatesManager'); $htmlString = ''; $emptyChilds = array(); foreach ($menuEntry->getChildren() as $child) { if (!$child->hasChildren()) { $emptyChilds[] = $child; } else { $htmlString .= $templatesManager->renderTemplate('\\Zepi\\Web\\UserInterface\\Templates\\OverviewPageSection', array('menuEntry' => $child)); } } $htmlString = $templatesManager->renderTemplate('\\Zepi\\Web\\UserInterface\\Templates\\OverviewPageItems', array('children' => $emptyChilds)) . $htmlString; return $htmlString; }
/** * Returns the directory for the given module namespace * * @access protected * @param string $namespace * @return false|string */ protected function buildPathFromNamespace($namespace) { // Prepare the namespace $namespace = Framework::prepareNamespace($namespace); // Load the module $moduleManager = $this->framework->getModuleManager(); $module = $moduleManager->getModule($namespace); if ($module === false) { return false; } return $module->getDirectory(); }
/** * Execute the installation of Turbo * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\CliRequest $request * @param \Zepi\Turbo\Response\Response $response */ public function execute(Framework $framework, CliRequest $request, Response $response) { // Configure turbo $this->configure(); // Save the settings $this->configurationManager->saveConfigurationFile(); // Execute the DataSource setups $dataSourceManager = $framework->getDataSourceManager(); foreach ($dataSourceManager->getDataSourceTypeClasses() as $type) { $dataSource = $dataSourceManager->getDataSource($type); $dataSource->setup(); } }
/** * Returns the data source for the given type class. * * @access public * @param string $typeClass * @return mixed * * @throws \Zepi\Turbo\Exception Cannot find a driver for the given type class. * @throws \Zepi\Turbo\Exception Cannot find a data source for the given type class. */ public function getDataSource($typeClass) { $driver = $this->getDriver($typeClass); // If there is no driver for the given type class throw an exception if ($driver === false) { throw new Exception('Cannot find a driver for the given type class "' . $typeClass . '".'); } $dataSourceClass = $this->searchDataSourceClass($typeClass, $driver); // If there is no data source class for the given type class throw an exception if ($dataSourceClass === false) { throw new Exception('Cannot find a data source for the given type class "' . $typeClass . '" (selected driver: "' . $driver . '").'); } return $this->framework->getInstance($dataSourceClass); }
/** * Searches a renderer for the given template file and renders the * file. * * @access protected * @param string $templateFile * @param array $additionalData * @return string */ protected function searchRendererAndRenderTemplate($templateFile, $additionalData = array()) { // Get the file information for the template file $fileInfo = pathinfo($templateFile); $extension = $fileInfo['extension']; // If we haven't a renderer for this extension we return an // empty string to prevent everything from failing. if (!isset($this->renderer[$extension])) { return ''; } // Take the renderer... $renderer = $this->renderer[$extension]; // ...and render the template file. return $renderer->renderTemplateFile($templateFile, $this->framework, $this->framework->getRequest(), $this->framework->getResponse(), $additionalData); }
/** * Iterates trough an array and searches the needed menu entry. * If found, return the menu entry, otherwise return false. * * @access protected * @param array $menuEntries * @return false|\Zepi\Web\General\Entity\MenuEntry */ protected function searchCorrectMenuEntryInArray($menuEntries) { foreach ($menuEntries as $key => $menuEntry) { if (trim($menuEntry->getTarget(), '/') === trim($this->framework->getRequest()->getRoute(), '/')) { return $menuEntry; } if ($menuEntry->hasChildren()) { $menuEntry = $this->searchCorrectMenuEntryInArray($menuEntry->getChildren()); if ($menuEntry !== false) { return $menuEntry; } } } return false; }
<?php // Load the autoloader require 'vendor/autoload.php'; // Start the framework $framework = \Zepi\Turbo\Framework::getFrameworkInstance(__DIR__); // Register the framework modules $framework->getModuleManager()->registerModuleDirectory(__DIR__ . '/vendor/'); $framework->getModuleManager()->registerModuleDirectory(__DIR__ . '/modules/'); // Activate the framework core module $framework->getModuleManager()->activateModule('Zepi\\Core\\Defaults'); $framework->getModuleManager()->activateModule('Zepi\\Core\\AccessControl', true); $framework->getModuleManager()->activateModule('Zepi\\Core\\Management', true); $framework->getModuleManager()->activateModule('Zepi\\Web\\AccessControl', true); // Activate project modules $framework->getModuleManager()->activateModule('Zepi\\Starter', true); // Execute the main work if (!defined('EXECUTION_DISABLED') || !EXECUTION_DISABLED) { $framework->execute(); }
/** * Validates the value. Returns true if everything is okey or an Error * object if there was an error. * * @access public * @param \Zepi\Turbo\Framework $framework * @return boolean|\Zepi\Web\UserInterface\Form\Error */ public function validate(Framework $framework) { $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager'); try { $ipObject = $this->createIpObject($this->value); } catch (ParseException $e) { $ipObject = false; } if ($ipObject === false) { return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is not valid.', '\\Zepi\\Web\\UserInterface', array('field' => $this->label))); } return true; }
/** * Returns the full url to the asset manager to load the * given file. * * @access public * @param string $file * @return string */ public function getUrlToTheAssetLoader($file) { return $this->framework->getRequest()->getFullRoute('/assets/' . $file); }
/** * Validates the form data and returns an array with errors. * If the array is empty there was no error. * * @access public * @param \Zepi\Turbo\Framework $framework * @return array */ public function validateFormData(Framework $framework) { $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager'); $errors = array(); foreach ($this->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Field\\FieldAbstract') as $field) { // Validate mandatory fields if ($field->isMandatory() && !$field->hasValue()) { $errors[] = new Error(Error::MANDATORY_FIELD, sprintf($translationManager->translate('%s is a mandatory field. Please fill out the field.', '\\Zepi\\Web\\UserInterface'), $field->getLabel()), $field); } $result = $field->validate($framework); if ($result !== true) { $errors[] = $result; } } return $errors; }
public function testFrameworkExecuteRouteNotFound() { $framework = \Zepi\Turbo\Framework::getFrameworkInstance(TESTS_ROOT_DIR . '/'); $framework->getModuleManager()->registerModuleDirectory(TESTS_ROOT_DIR . '/modules-working/', false); $framework->getModuleManager()->activateModule('TestModule'); $framework->getRequest()->setRoute('executionTest2'); $events = array('\\Zepi\\Turbo\\Event\\BeforeExecution' => 1, '\\Zepi\\Turbo\\Event\\AfterExecution' => 1, '\\Zepi\\Turbo\\Event\\FinalizeOutput' => 1, '\\Zepi\\Turbo\\Event\\BeforeOutput' => 1, '\\Zepi\\Turbo\\Event\\AfterOutput' => 1, '\\Zepi\\Turbo\\Event\\RouteNotFound' => 1); foreach ($events as $key => $number) { $framework->getRuntimeManager()->addEventHandler($key, '\\TestModule\\TestEventHandler'); } $framework->execute(); $this->assertEquals($events, \TestModule\TestEventHandler::$executedEvents); \TestModule\TestEventHandler::$executedEvents = array(); }
/** * Initializes and return an instance of the given class name. * * @access public * @param string $className * @return mixed */ public function getInstance($className) { return $this->framework->initiateObject($className); }
/** * Handles all required dependencies. * * @access public * @param string $moduleNamespace * @param array $dependencies * @param boolean $activateDependencies * * @throws Zepi\Turbo\Exception Can not activate the module "$moduleNamespace". The module requires the module "$dependencyModuleNamespace" which isn't activated. */ protected function handleRequiredDependencies($moduleNamespace, $dependencies, $activateDependencies) { foreach ($dependencies as $dependencyModuleNamespace => $version) { $dependencyModuleNamespace = Framework::prepareNamespace($dependencyModuleNamespace); $module = $this->getModule($dependencyModuleNamespace); if ($module === false) { if ($activateDependencies) { $this->activateModule($dependencyModuleNamespace, $activateDependencies); } else { throw new Exception('Can not activate the module "' . $moduleNamespace . '". The module requires the module "' . $dependencyModuleNamespace . '" which isn\'t activated.'); } } } }
/** * Validates the value. Returns true if everything is okey or an Error * object if there was an error. * * @access public * @param \Zepi\Turbo\Framework $framework * @return boolean|\Zepi\Web\UserInterface\Form\Error */ public function validate(Framework $framework) { $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager'); if ($this->minValue !== null && $this->value < $this->minValue) { return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is lower than the allowed minimum (%min%).', '\\Zepi\\Web\\UserInterface', array('field' => $this->label, 'min' => $this->minValue))); } if ($this->maxValue !== null && $this->value > $this->maxValue) { return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is higher than the allowed maximum (%max%).', '\\Zepi\\Web\\UserInterface', array('field' => $this->label, 'max' => $this->maxValue))); } return true; }
/** * Homepage * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\WebRequest $request * @param \Zepi\Turbo\Response\Response $response */ public function execute(Framework $framework, WebRequest $request, Response $response) { $templatesManager = $framework->getInstance('\\Zepi\\Web\\General\\Manager\\TemplatesManager'); $response->setOutput($templatesManager->renderTemplate('\\Zepi\\Starter\\Templates\\Homepage', $framework, $request, $response)); }