/** * Get a model. * * Supply the name and the model will be loaded from the supplied directory, * or from one of the modelPaths (which you can add). * * @param string $modelName Name of the model * @param string|null $directory Directory to load the model from, will ignore $modelPaths * @return ModelAbstract The Model object */ public function get($modelName, $directory = null) { if (empty($modelName)) { throw new ModelException("Could not load model. No name provided", 1); } // First get the directories where the model can be located $directories = is_null($directory) ? $this->modelPaths : array($directory); // Fire a model load event $event = Events::fireEvent('modelLoadEvent', $modelName, $directories); $directories = $event->directories; $modelName = $event->modelName; // If the event is cancelled, stop loading if ($event->isCancelled()) { return false; } // And attempt to load the model return $this->loadModel($modelName, $directories); }
/** * Load a helper. * * Supply the name and the helper will be loaded from the supplied directory, * or from one of the helperPaths (which you can add). * * @param string $helperName Name of the helper * @param string|null $directory Directory to load the helper from, will ignore $helperPaths * @return bool Whether the helper was succesfully loaded (true if yes) */ public function load($helperName, $directory = null) { // First determine the name of the helper $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName) . '_helper'); // Determine what directories should be checked $directories = is_null($directory) ? $this->helperPaths : array($directory); // Check it is already loaded if (isset($this->helpers[$helperName])) { Logger::log("Helper '" . $helperName . "' is already loaded. Skipping"); return false; } // First check if there is an 'extension' class $extendedHelper = Config::get('main')->application_prefix . $helperName; $extendedHelperLoaded = false; foreach ($directories as $helperPath) { $file = $helperPath . DS . $extendedHelper . '.php'; if (file_exists($file)) { $extendedHelperLoaded = true; $extendedHelperFile = $file; } } // If an extension is loaded there needs to be a base helper if ($extendedHelperLoaded) { $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName . '.php'; if (!file_exists($baseHelper)) { throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1); } // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once $event->extendedHelperFile; include_once $event->helperFile; $this->helpers[$event->helperName] = true; Logger::log("Loading base helper '" . $event->helperName . "' and extended helper '" . $event->extendedHelperName . "'"); return true; } // If no extension exists, try loading a regular helper foreach ($directories as $helperPath) { $file = $helperPath . DS . $helperName . '.php'; if (file_exists($file)) { // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $file); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once $event->helperFile; $this->helpers[$event->helperName] = true; Logger::log("Loading helper '" . $event->helperName . "'"); return true; } } throw new HelperException("Could not load helper. Helper not found.", 1); }
/** * Output the entire log to the screen. Used for debugging problems with your code. * @codeCoverageIgnore */ public static function logToScreen() { // Send a screenLogEvent, allows for new screen log designs $event = Events::fireEvent('screenLogEvent'); if ($event->isCancelled()) { return false; } $logs = self::$Logs; require dirname(__DIR__) . '/views/view.' . self::$logger_template . '.php'; }
/** * The default callable. * * This callable will do the 'old skool' routing. It will load the controllers from the controller-directory * in the application-directory. */ public function defaultCallable($arguments = array()) { $this->logger->log('Default callable called!'); $controller = $arguments['controller']; $function = $arguments['function']; $parameters = empty($arguments['parameters']) ? null : $arguments['parameters']; // Construct file paths and classes $class = '\\Application\\Controller\\' . ucfirst($controller); $directory = Core::$appDir . DS . 'Controller'; $file = $directory . DS . 'controller.' . $controller . '.php'; $event = Events::fireEvent('routerLoadControllerEvent', $file, $directory, $class, $controller, $function, $parameters); // Cancel if requested to do so if ($event->isCancelled()) { return; } // Check if the file exists if (file_exists($event->file)) { if (!class_exists($event->className)) { $this->logger->log('Loading controller ' . $event->className . ' from file: ' . $event->file); include $event->file; } // Get the path the controller should know about $path = implode('/', $this->uri->rsegments); // And create the controller $this->callable = new $event->className($path); // If the controller does not want a function to be loaded, provide a halt parameter. if (isset($this->callable->halt)) { return; } // Check if method exists or if there is a caller function if (method_exists($this->callable, $event->function) || method_exists($this->callable, '__call')) { // Execute the function on the controller echo $this->callable->{$event->function}($event->parameters); } else { // Function could not be found $this->logger->log('Could not find function ' . $event->function . ' on controller ' . $event->className); $this->logger->http_error(404); } } else { // Controller could not be found $this->logger->log('Could not find controller ' . $event->className); $this->logger->http_error(404); } }
/** * Load the template engines by sending a layoutLoadEngineEvent. */ public static function loadTemplateEngines() { if (!self::$engines_loaded) { Events::fireEvent('layoutLoadEngineEvent'); // Load the engines provided in this file self::registerEngine(new PHPEngine(), 'PHP', array('php')); self::registerEngine(new JsonEngine(), 'JSON', array('json')); self::registerEngine(new SmartyEngine(), 'Smarty', array('tpl')); self::registerEngine(new LatteEngine(), 'Latte', array('latte')); self::$engines_loaded = true; } }
/** * Stop FuzeWorks and run all shutdown functions. * * Afterwards run the Logger shutdown function in order to possibly display the log */ public static function shutdown() { // Fix Apache bug where CWD is changed upon shutdown chdir(self::$cwd); // Fire the Shutdown event $event = Events::fireEvent('coreShutdownEvent'); if ($event->isCancelled() === false) { // If the output should be displayed, send the final render and parse the logger Logger::shutdownError(); Factory::getInstance()->output->_display(); Logger::shutdown(); } }