示例#1
0
 /**
  * Constructor
  *
  * @param	object	&$db
  * @return	void
  */
 public function __construct(&$db)
 {
     $this->db =& $db;
     $this->factory = Factory::getInstance();
     $this->factory->helpers->load('file');
     $this->check_path();
 }
示例#2
0
 /**
  * Initialize file-based cache
  *
  * @return	void
  */
 public function __construct()
 {
     // Load the factory
     $this->factory = Factory::getInstance();
     // Load the required helpers
     $this->factory->helpers->load('file');
     $this->_cache_path = Core::$tempDir . DS . 'CacheLibrary' . DS;
 }
示例#3
0
文件: Driver.php 项目: fuzeworks/core
 /**
  * Load driver
  *
  * Separate load_driver call to support explicit driver load by library or user
  *
  * @param	string	Driver name (w/o parent prefix)
  * @return	object	Child class
  */
 public function load_driver($child)
 {
     // Get the subclass prefix
     $prefix = Config::get('main')->application_prefix;
     if (!isset($this->lib_name)) {
         // Get library name without any prefix
         $this->lib_name = str_replace(array('FW_', $prefix), '{prefix}', get_class($this));
     }
     // Sanitize the library name
     $clean_class = str_replace(array('Application\\Library\\', 'FuzeWorks\\Library\\', '{prefix}'), '', $this->lib_name);
     // The child will be prefixed with the parent lib
     $child_name = $this->lib_name . '_' . $child;
     // See if requested child is a valid driver
     if (!in_array($child, $this->valid_drivers)) {
         // The requested driver isn't valid!
         $msg = 'Invalid driver requested: ' . $child_name;
         throw new LibraryException($msg, 1);
     }
     // Get package paths and filename case variations to search
     $paths = Factory::getInstance()->libraries->getLibraryPaths();
     // Is there an extension?
     $class_name = str_replace('{prefix}', $prefix, $child_name);
     $found = class_exists($class_name, FALSE);
     if (!$found) {
         // Check for subclass file
         foreach ($paths as $path) {
             // Does the file exist?
             $file = $path . DS . $clean_class . DS . 'drivers' . DS . $prefix . $clean_class . '_' . $child . '.php';
             if (file_exists($file)) {
                 // Yes - require base class from BASEPATH
                 $basepath = Core::$coreDir . DS . 'Libraries' . DS . $clean_class . DS . 'drivers' . DS . $clean_class . '_' . $child . '.php';
                 if (!file_exists($basepath)) {
                     $msg = 'Unable to load the requested class: FW_' . $child_name;
                     throw new LibraryException($msg, 1);
                 }
                 // Include both sources and mark found
                 include_once $basepath;
                 include_once $file;
                 $found = TRUE;
                 break;
             }
         }
     }
     // Do we need to search for the class?
     if (!$found) {
         // Use standard class name
         $class_name = str_replace('{prefix}', 'FW_', $child_name);
         if (!class_exists($class_name, FALSE)) {
             // Check package paths
             foreach ($paths as $path) {
                 // Does the file exist?
                 $file = $path . DS . $clean_class . DS . 'drivers' . DS . $clean_class . '_' . $child . '.php';
                 if (file_exists($file)) {
                     // Include source
                     include_once $file;
                     break;
                 }
             }
         }
     }
     // Did we finally find the class?
     if (!class_exists($class_name, FALSE)) {
         if (class_exists($child_name, FALSE)) {
             $class_name = $child_name;
         } else {
             $msg = 'Unable to load the requested driver: ' . $class_name;
             throw new LibraryException($msg, 1);
         }
     }
     // Instantiate, decorate and add child
     $obj = new $class_name();
     $obj->decorate($this);
     $this->{$child} = $obj;
     return $this->{$child};
 }
示例#4
0
文件: Logger.php 项目: fuzeworks/core
 /**
  * Calls an HTTP error, sends it as a header, and loads a template if required to do so.
  *
  * @param int  $errno HTTP error code
  * @param bool $view  true to view error on website
  */
 public static function http_error($errno = 500, $view = true)
 {
     $http_codes = array(400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended', 511 => 'Network Authentication Required');
     self::logError('HTTP-error ' . $errno . ' called');
     self::log('Sending header HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
     header('HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
     // Do we want the error-view with it?
     if ($view == false) {
         return;
     }
     // Load the view
     $view = 'errors/' . $errno;
     self::log('Loading view ' . $view);
     // Try and load the view, if impossible, load HTTP code instead.
     try {
         Layout::reset();
         Layout::view($view);
     } catch (LayoutException $exception) {
         // No error page could be found, just echo the result
         Factory::getInstance()->output->set_output("<h1>{$errno}</h1><h3>" . $http_codes[$errno] . '</h3>');
     }
 }
示例#5
0
文件: Router.php 项目: fuzeworks/core
 /**
  * Constructor of the Router
  * 
  * Loads all required classes and adds all the routes to the routingTable
  * 
  * @return void
  */
 public function __construct()
 {
     // Load related classes
     $factory = Factory::getInstance();
     $this->config = $factory->config;
     $this->uri = $factory->uri;
     $this->logger = $factory->logger;
     $this->events = $factory->events;
     $this->output = $factory->output;
     // Start parsing the routing
     $this->parseRouting();
 }
示例#6
0
 /**
  * Class constructor
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     if (is_array($params)) {
         foreach ($params as $key => $val) {
             $this->{$key} = $val;
         }
     }
     $this->factory = Factory::getInstance();
     Logger::log('Database Driver ' . get_class($this) . ' Initialized');
 }
示例#7
0
文件: Layout.php 项目: fuzeworks/core
 /**
  * Retrieve a template file using a string and a directory and immediatly parse it to the output class.
  *
  * What template file gets loaded depends on the template engine that is being used.
  * PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file.
  * You can also provide no particular engine, and the manager will decide what template to load.
  * Remember that doing so will result in a LayoutException when multiple compatible files are found.
  *
  * @param string $file         File to load
  * @param string $directory    Directory to load it from
  * @param bool   $directOutput Whether to directly output the result with an echo or send it to the output class. True if echo
  *
  * @throws LayoutException On error
  */
 public static function view($file, $directory = null, $directOutput = false)
 {
     $output = Factory::getInstance()->output;
     $directory = is_null($directory) ? self::$directory : $directory;
     if ($directOutput === true) {
         echo self::get($file, $directory);
     } else {
         $output->append_output(self::get($file, $directory));
     }
     return;
 }
示例#8
0
文件: Zip.php 项目: fuzeworks/core
 /**
  * Initialize zip compression class
  *
  * @return	void
  */
 public function __construct()
 {
     $this->now = time();
     $this->factory = Factory::getInstance();
     $this->factory->logger->log('Zip Compression Class Initialized');
 }
 public function tearDown()
 {
     Layout::reset();
     Factory::getInstance()->output->set_output('');
 }
示例#10
0
文件: Config.php 项目: fuzeworks/core
 /**
  * Load a config file in a static environment.
  * 
  * @deprecated
  * @param string $configName  Name of the config file. Eg. 'main'
  * @return FuzeWorks\ConfigORM\ConfigORM ORM of the config file. Allows for easy reading and editing of the file
  * @throws  ConfigException
  */
 public static function get($configName)
 {
     if (!is_object(self::$factory)) {
         // @codeCoverageIgnoreStart
         self::$factory = Factory::getInstance();
     }
     // @codeCoverageIgnoreEnd
     $config = self::$factory->config;
     return $config->getConfig($configName);
 }
示例#11
0
 /**
  * Create a register with all the module headers from all the existing modules.
  *
  * Used to correctly load all modules
  * @param   bool    $cache          true if loading from cache
  * @param   string  $cachingMethod  the driver used in the caching library
  * @param   int     $cachingTime    The time the registers are cached
  */
 public static function buildRegister($cache = false, $cachingMethod = 'file', $cachingTime = 300)
 {
     // First check if the caching engine can be used
     if ($cache) {
         // Retrieve the cache if possible
         $cache = Factory::getInstance()->libraries->getDriver('cache');
         $cacheData = $cache->{$cachingMethod}->get('moduleRegisters');
         if (!is_bool($cacheData)) {
             // Separate the data
             $moduleRegister = $cacheData['moduleRegister'];
             $eventRegister = $cacheData['eventRegister'];
             $routeRegister = $cacheData['routeRegister'];
             $advertiseRegister = $cacheData['advertiseRegister'];
             // And register it all
             Logger::newLevel("Loadig Module Headers from Cache");
             self::$register = $moduleRegister;
             Events::$register = $eventRegister;
             self::$advertiseRegister = $advertiseRegister;
             self::$module_routes = $routeRegister;
             foreach ($routeRegister as $route => $name) {
                 Factory::getInstance()->router->addRoute($route, array('callable' => array('\\FuzeWorks\\Modules', 'moduleCallable')), true);
             }
             Logger::stopLevel();
             return true;
         }
     }
     Logger::newLevel('Loading Module Headers', 'Core');
     // Get all the module directories
     $dir = Core::$appDir . DS . 'Modules/';
     $mod_dirs = array();
     $mod_dirs = array_values(array_diff(scandir($dir), array('..', '.')));
     // Build the module and event register
     $register = array();
     $event_register = array();
     // Cycle through all module directories
     for ($i = 0; $i < count($mod_dirs); ++$i) {
         $mod_dir = $dir . $mod_dirs[$i] . '/';
         // If a moduleInfo.php exists, load it
         if (file_exists($mod_dir . '/moduleInfo.php')) {
             // Load the configuration file
             $cfg = (object) (include $mod_dir . '/moduleInfo.php');
             // Set enabled for now
             $enabled = true;
             // Define the module name
             $name = '';
             $name .= !empty($cfg->author) ? strtolower($cfg->author) . '/' : '';
             $name .= strtolower($cfg->module_name);
             // Get the module directory
             $cfg->directory = $mod_dir;
             // Check whether the module is disabled
             if (isset($cfg->enabled)) {
                 if (!$cfg->enabled) {
                     // If disabled, set the variable
                     $enabled = false;
                     // If disabled, a holder will be placed so it might be enabled in the future
                     $mock = new StdClass();
                     $mock->module_name = $cfg->module_name;
                     $mock->directory = $cfg->directory;
                     $mock->meta = $cfg;
                     $mock->aliases = $cfg->aliases;
                     // Important, change the configuration to the mock, so we can duplicate it afterwards
                     $cfg = $mock;
                 }
             }
             // Copy all the data into the register and enable
             $register[$name] = (array) $cfg;
             // Log the name for enabled and disabled
             if (!$enabled) {
                 Logger::newLevel("[OFF] '" . $name . "'");
             } else {
                 Logger::newLevel("[ON]  '" . $name . "'");
             }
             // And possibly some aliases
             if (isset($cfg->aliases)) {
                 foreach ($cfg->aliases as $alias) {
                     $register[$alias] = (array) $cfg;
                     unset($register[$alias]['events']);
                     Logger::log("&nbsp;&nbsp;&nbsp;'" . $alias . "' (alias of '" . $name . "')");
                 }
             }
             // If not enabled, log it, wrap it and off to the next one
             if (!$enabled) {
                 Logger::stopLevel();
                 continue;
             }
             // Otherwise continue and add routing paths
             if (isset($cfg->routes)) {
                 // Get routes and add them
                 foreach ($cfg->routes as $route) {
                     // Create the route and callable and parse them
                     $callable = array('\\FuzeWorks\\Modules', 'moduleCallable');
                     Factory::getInstance()->router->addRoute($route, array('callable' => $callable), true);
                     self::$module_routes[$route] = $name;
                 }
             }
             // And for the events
             if (isset($cfg->events)) {
                 // Get the events and add them
                 foreach ($cfg->events as $event) {
                     // First check if the event already exists, if so, append it
                     if (isset($event_register[$event])) {
                         $event_register[$event][] = $name;
                     } else {
                         $event_register[$event] = array($name);
                     }
                     // Log the event
                     Logger::Log('Event added: \'' . $event . '\'');
                 }
             }
             // And check for an advertisement tag
             if (isset($cfg->advertise)) {
                 // Cycle through advertisements
                 foreach ($cfg->advertise as $advertiseName => $advertiseData) {
                     // Log advertisement
                     Logger::log('Advertisement added: \'' . $advertiseName . '\'');
                     // Add to advertiseRegister
                     self::$advertiseRegister[$advertiseName][$name] = $advertiseData;
                 }
             }
             Logger::stopLevel();
         } else {
             // If no details are specified, create a basic mock module
             $name = $mod_dirs[$i];
             // Build a default mock module config
             $mock = new stdClass();
             $mock->module_class = ucfirst($name);
             $mock->module_file = 'class.' . strtolower($name) . '.php';
             $mock->module_name = $name;
             $mock->dependencies = array();
             $mock->versions = array();
             $mock->directory = $mod_dir;
             // Apply it
             $register[$name] = (array) $mock;
             Logger::newLevel("[ON]  '" . $name . "'");
             Logger::stopLevel();
         }
     }
     if ($cache) {
         Logger::log("Saving registry to cache");
         $cacheData = array('moduleRegister' => $register, 'eventRegister' => $event_register, 'routeRegister' => self::$module_routes, 'advertiseRegister' => self::$advertiseRegister);
         $cache->{$cachingMethod}->save('moduleRegisters', $cacheData, $cachingTime);
     }
     // And apply the registers to their dedicate location
     self::$register = $register;
     Events::$register = $event_register;
     Logger::stopLevel();
 }
示例#12
0
 /**
  * Attach the Factory to this class
  */
 public function __construct()
 {
     $this->factory = Factory::getInstance();
     $this->libraryPaths[] = Core::$coreDir . DS . 'Libraries';
     $this->libraryPaths[] = Core::$appDir . DS . 'Libraries';
 }
示例#13
0
文件: Core.php 项目: fuzeworks/core
 /**
  * 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();
     }
 }