コード例 #1
0
 /**
  * Execute this configuration handler.
  *
  * @param string An absolute filesystem path to a configuration file.
  *
  * @return string Data to be written to a cache file.
  *
  * @throws <b>ConfigurationException</b> If a requested configuration file
  *									   does not exist or is not readable.
  * @throws <b>ParseException</b> If a requested configuration file is
  *							   improperly formatted.
  */
 public function &execute($config)
 {
     // parse the ini
     $ini = $this->parseIni($config);
     // determine if we're loading the system config_handlers.ini or a module
     // config_handlers.ini
     $moduleLevel = $this->getParameter('module_level') === true ? true : false;
     if ($moduleLevel) {
         // get the current module name
         $moduleName = $this->getParameter('module_name');
     }
     // init our data and includes arrays
     $data = array();
     $includes = array();
     // let's do our fancy work
     foreach ($ini as $category => &$keys) {
         if ($moduleLevel) {
             // module-level registration, so we must prepend the module
             // root to the category
             $category = 'modules/' . $moduleName . '/' . $category;
         }
         if (!isset($keys['class'])) {
             // missing class key
             $error = 'Configuration file "%s" specifies category ' . '"%s" with missing class key';
             $error = sprintf($error, $config, $category);
             throw new ParseException($error);
         }
         $class =& $keys['class'];
         if (isset($keys['file'])) {
             // we have a file to include
             $file =& $keys['file'];
             $file = $this->replaceConstants($file);
             $file = $this->replacePath($file);
             if (!is_readable($file)) {
                 // handler file doesn't exist
                 $error = 'Configuration file "%s" specifies class "%s" ' . 'with nonexistent or unreadable file "%s"';
                 $error = sprintf($error, $config, $class, $file);
                 throw new ParseException($error);
             }
             // append our data
             $tmp = "require_once('%s');";
             $includes[] = sprintf($tmp, $file);
         }
         // parse parameters
         $parameters =& ParameterParser::parse($keys);
         // append new data
         $tmp = "self::\$handlers['%s'] = new %s();";
         $data[] = sprintf($tmp, $category, $class);
         if ($parameters != 'null') {
             // since we have parameters we will need to init the handler
             $tmp = "self::\$handlers['%s']->initialize(%s);";
             $data[] = sprintf($tmp, $category, $parameters);
         }
     }
     // compile data
     $retval = "<?php\n" . "// auth-generated by RootConfigHandler\n" . "// date: %s\n%s\n%s\n?>";
     $retval = sprintf($retval, date('m/d/Y H:i:s'), implode("\n", $includes), implode("\n", $data));
     return $retval;
 }
コード例 #2
0
 /**
  * Execute this configuration handler.
  *
  * @param string An absolute filesystem path to a configuration file.
  *
  * @return string Data to be written to a cache file.
  *
  * @throws <b>ConfigurationException</b> If a requested configuration file
  *									   does not exist or is not readable.
  * @throws <b>ParseException</b> If a requested configuration file is
  *							   improperly formatted.
  */
 public function &execute($config)
 {
     // parse the ini
     $ini = $this->parseIni($config);
     // init our data and includes arrays
     $data = array();
     $includes = array();
     // let's do our fancy work
     foreach ($ini as $category => &$keys) {
         if (!isset($keys['class'])) {
             // missing class key
             $error = 'Configuration file "%s" specifies category ' . '"%s" with missing class key';
             $error = sprintf($error, $config, $category);
             throw new ParseException($error);
         }
         $class =& $keys['class'];
         if (isset($keys['file'])) {
             // we have a file to include
             $file =& $keys['file'];
             $file = $this->replaceConstants($file);
             $file = $this->replacePath($file);
             if (!is_readable($file)) {
                 // filter file doesn't exist
                 $error = 'Configuration file "%s" specifies class "%s" ' . 'with nonexistent or unreadable file "%s"';
                 $error = sprintf($error, $config, $class, $file);
                 throw new ParseException($error);
             }
             // append our data
             $tmp = "require_once('%s');";
             $includes[] = sprintf($tmp, $file);
         }
         // parse parameters
         $parameters =& ParameterParser::parse($keys);
         // append new data
         $tmp = "\$filter = new %s();\n" . "\$filter->initialize(\$this->context, %s);\n" . "\$filters[] = \$filter;";
         $data[] = sprintf($tmp, $class, $parameters);
     }
     // compile data
     $retval = "<?php\n" . "// auth-generated by FilterConfigHandler\n" . "// date: %s\n%s\n%s\n%s\n%s\n?>";
     $retval = sprintf($retval, date('m/d/Y H:i:s'), implode("\n", $includes), '$filters = array();', implode("\n", $data), '$list[$moduleName] =& $filters;');
     return $retval;
 }
コード例 #3
0
 /**
  * Execute this configuration handler.
  *
  * @param string An absolute filesystem path to a configuration file.
  *
  * @return string Data to be written to a cache file.
  *
  * @throws <b>ConfigurationException</b> If a requested configuration file
  *									   does not exist or is not readable.
  * @throws <b>ParseException</b> If a requested configuration file is
  *							   improperly formatted.
  */
 public function &execute($config)
 {
     // set our required categories list and initialize our handler
     $categories = array('required_categories' => array('databases'));
     $this->initialize($categories);
     // parse the ini
     $ini = $this->parseIni($config);
     // init our data and includes arrays
     $data = array();
     $databases = array();
     $includes = array();
     // get a list of database connections
     foreach ($ini['databases'] as $key => &$value) {
         $value = trim($value);
         // is this category already registered?
         if (in_array($value, $databases)) {
             // this category is already registered
             $error = 'Configuration file "%s" specifies previously ' . 'registered category "%s"';
             $error = sprintf($error, $config, $value);
             throw new ParseException($error);
         }
         // see if we have the category registered for this database
         if (!isset($ini[$value])) {
             // missing required key
             $error = 'Configuration file "%s" specifies nonexistent ' . 'category "%s"';
             $error = sprintf($error, $config, $value);
             throw new ParseException($error);
         }
         // add this database
         $databases[$key] = $value;
     }
     // make sure we have a default database registered
     if (!isset($databases['default'])) {
         // missing default database
         $error = 'Configuration file "%s" must specify a default ' . 'database configuration';
         $error = sprintf($error, $config);
         throw new ParseException($error);
     }
     // let's do our fancy work
     foreach ($ini as $category => &$keys) {
         if (!in_array($category, $databases)) {
             // skip this unspecified category
             continue;
         }
         if (!isset($keys['class'])) {
             // missing class key
             $error = 'Configuration file "%s" specifies category ' . '"%s" with missing class key';
             $error = sprintf($error, $config, $category);
             throw new ParseException($error);
         }
         $class =& $keys['class'];
         if (isset($keys['file'])) {
             // we have a file to include
             $file =& $keys['file'];
             $file = $this->replaceConstants($file);
             $file = $this->replacePath($file);
             if (!is_readable($file)) {
                 // database file doesn't exist
                 $error = 'Configuration file "%s" specifies class "%s" ' . 'with nonexistent or unreadable file "%s"';
                 $error = sprintf($error, $config, $class, $file);
                 throw new ParseException($error);
             }
             // append our data
             $tmp = "require_once('%s');";
             $includes[] = sprintf($tmp, $file);
         }
         // parse parameters
         $parameters =& ParameterParser::parse($keys);
         // append new data
         $tmp = "\$database = new %s();\n" . "\$database->initialize(%s);\n" . "\$this->databases['%s'] = \$database;";
         $data[] = sprintf($tmp, $class, $parameters, array_search($category, $databases));
     }
     // compile data
     $retval = "<?php\n" . "// auth-generated by DatabaseConfigHandler\n" . "// date: %s\n%s\n%s\n?>";
     $retval = sprintf($retval, date('m/d/Y H:i:s'), implode("\n", $includes), implode("\n", $data));
     return $retval;
 }
コード例 #4
0
 /**
  * Load a list of validators.
  *
  * @param string The configuration file name (for exception usage).
  * @param array  An associative array of validator data.
  * @param array  The loaded ini configuration that we'll use for
  *			   verification purposes.
  * @param string A comma delimited list of validator names.
  * @param array  A file/parameter name entry.
  *
  * @return void
  */
 private function loadValidators(&$config, &$validators, &$ini, &$list, &$entry)
 {
     // create our empty entry validator array
     $entry['validators'] = array();
     if (trim($list) == '') {
         // skip the empty list
         return;
     }
     // get our validator array
     $array = explode(',', $list);
     foreach ($array as &$validator) {
         $validator = trim($validator);
         // add this validator name to our entry
         $entry['validators'][] =& $validator;
         // make sure the specified validator exists
         if (!isset($ini[$validator])) {
             // validator hasn't been registered
             $error = 'Configuration file "%s" specifies unregistered ' . 'validator "%s"';
             $error = sprintf($error, $config, $validator);
             throw new ParseException($error);
         }
         // has it already been registered?
         if (isset($validators[$validator])) {
             continue;
         }
         if (!isset($ini[$validator]['class'])) {
             // missing class key
             $error = 'Configuration file "%s" specifies category ' . '"%s" with missing class key';
             $error = sprintf($error, $config, $validator);
             throw new ParseException($error);
         }
         // create our validator
         $validators[$validator] = array();
         $validators[$validator]['class'] = $ini[$validator]['class'];
         $validators[$validator]['file'] = null;
         $validators[$validator]['parameters'] = null;
         if (isset($ini[$validator]['file'])) {
             // we have a file for this validator
             $file = $ini[$validator]['file'];
             // keyword replacement
             $file = $this->replaceConstants($file);
             $file = $this->replacePath($file);
             if (!is_readable($file)) {
                 // file doesn't exist
                 $error = 'Configuration file "%s" specifies ' . 'category "%s" with nonexistent or unreadable ' . 'file "%s"';
                 $error = sprintf($error, $config, $validator, $file);
                 throw new ParseException($error);
             }
             $validators[$validator]['file'] = $file;
         }
         // parse parameters
         $parameters = ParameterParser::parse($ini[$validator]);
         $validators[$validator]['parameters'] = $parameters;
     }
 }
コード例 #5
0
 /**
  * Execute this configuration handler.
  *
  * @param string An absolute filesystem path to a configuration file.
  *
  * @return string Data to be written to a cache file.
  *
  * @throws <b>ConfigurationException</b> If a requested configuration file
  *									   does not exist or is not readable.
  * @throws <b>ParseException</b> If a requested configuration file is
  *							   improperly formatted.
  */
 public function &execute($config)
 {
     // available list of factories
     $factories = array('request', 'storage', 'user', 'security_filter');
     // set our required categories list and initialize our handler
     $categories = array('required_categories' => $factories);
     $this->initialize($categories);
     // parse the ini
     $ini = $this->parseIni($config);
     // init our data and includes arrays
     $includes = array();
     $inits = array();
     $instances = array();
     // let's do our fancy work
     foreach ($factories as $factory) {
         // see if the factory exists
         if (!isset($ini[$factory])) {
             // factory hasn't been registered
             $error = 'Configuration file "%s" must register "%s" factory';
             $error = sprintf($config, $factory);
             throw new ParseException($error);
         }
         // get factory keys
         $keys = $ini[$factory];
         if (!isset($keys['class'])) {
             // missing class key
             $error = 'Configuration file "%s" specifies category ' . '"%s" with missing class key';
             $error = sprintf($error, $config, $factory);
             throw new ParseException($error);
         }
         $class = $keys['class'];
         if (isset($keys['file'])) {
             // we have a file to include
             $file =& $keys['file'];
             $file = $this->replaceConstants($file);
             $file = $this->replacePath($file);
             if (!is_readable($file)) {
                 // factory file doesn't exist
                 $error = 'Configuration file "%s" specifies class ' . '"%s" with nonexistent or unreadablefile ' . '"%s"';
                 $error = sprintf($error, $config, $class, $file);
                 throw new ParseException($error);
             }
             // append our data
             $tmp = "require_once('%s');";
             $includes[] = sprintf($tmp, $file);
         }
         // parse parameters
         $parameters = ParameterParser::parse($keys);
         // append new data
         switch ($factory) {
             case 'request':
                 // append instance creation
                 $tmp = "\$this->request = " . "\\Mojavi\\Request\\Request::newInstance('%s');";
                 $instances[] = sprintf($tmp, $class);
                 // append instance initialization
                 $tmp = "\$this->request->initialize(\$this->context, " . "%s);";
                 $inits[] = sprintf($tmp, $parameters);
                 break;
             case 'security_filter':
                 // append creation/initialization in one swipe
                 $tmp = "\nif (MO_USE_SECURITY)\n{\n" . "\t\$this->securityFilter = " . "\\Mojavi\\Filter\\SecurityFilter::newInstance('%s');\n" . "\t\$this->securityFilter->initialize(" . "\$this->context, %s);\n}\n";
                 $inits[] = sprintf($tmp, $class, $parameters);
                 break;
             case 'storage':
                 // append instance creation
                 $tmp = "\$this->storage = " . "\\Mojavi\\Storage\\Storage::newInstance('%s');";
                 $instances[] = sprintf($tmp, $class);
                 // append instance initialization
                 $tmp = "\$this->storage->initialize(\$this->context, " . "%s);";
                 $inits[] = sprintf($tmp, $parameters);
                 break;
             case 'user':
                 // append instance creation
                 $tmp = "\$this->user = \\Mojavi\\User\\User::newInstance('%s');";
                 $instances[] = sprintf($tmp, $class);
                 // append instance initialization
                 $tmp = "\$this->user->initialize(\$this->context, %s);";
                 $inits[] = sprintf($tmp, $parameters);
         }
     }
     // context creation
     $context = "\$this->context = new \\Mojavi\\Core\\Context(%s, %s, %s, %s, %s);";
     $context = sprintf($context, '$this', '$this->request', '$this->user', '$this->storage', '$this->databaseManager');
     if (defined('MO_USE_LOGGING') && MO_USE_LOGGING) {
         LoggerManager::initialize();
     }
     // compile data
     $retval = "<?php\n" . "// auth-generated by FactoryConfigHandler\n" . "// date: %s\n%s\n%s\n%s\n%s\n?>";
     $retval = sprintf($retval, date('m/d/Y H:i:s'), implode("\n", $includes), implode("\n", $instances), $context, implode("\n", $inits));
     return $retval;
 }
コード例 #6
0
 /**
  * Load all request methods and the file/parameter names that will be
  * validated from the [methods] category.
  *
  * @param string The configuration file name (for exception usage).
  * @param string A Logger "instance" name.
  * @param array  An associative array of request method data.
  * @param array  An associative array of file/parameter appenders in which to
  *			   store loaded information.
  * @param array  The loaded ini configuration that we'll use for
  *			   verification purposes.
  *
  * @return void
  */
 private function loadLogger(&$config, &$logger, &$loggers, &$appenders, &$ini, &$category)
 {
     if (!isset($ini[$category]['class']) || trim($ini[$category]['class']) == '') {
         // missing/empty class key
         $error = 'Configuration file "%s" specifies logger ' . '"%s", with missing/empty class key';
         $error = sprintf($error, $config, $category);
         throw new ParseException($error);
     }
     if (!isset($ini[$category]['appenders']) || trim($ini[$category]['appenders']) == '') {
         // missing/empty appenders key
         $error = 'Configuration file "%s" specifies logger ' . '"%s", with missing/empty appenders key';
         $error = sprintf($error, $config, $category);
         throw new ParseException($error);
     }
     $loggers[$logger]['class'] = $ini[$category]['class'];
     // explode the list of names
     $array = explode(',', $ini[$category]['appenders']);
     // loop through the names
     foreach ($array as $name) {
         $name = trim($name);
         // make sure we have the required status of this file or parameter
         if (!isset($ini[$name])) {
             // missing section
             $error = 'Configuration file "%s" specifies appender ' . '"%s", but it has no section';
             $error = sprintf($error, $config, $name);
             throw new ParseException($error);
         }
         if (!isset($appenders[$name])) {
             $appenders[$name] = array();
         }
         // add this appender to the current request method
         $loggers[$logger]['appenders'][] = $name;
     }
     if (isset($ini[$category]['priority'])) {
         $loggers[$logger]['priority'] = $ini[$category]['priority'];
     }
     $loggers[$logger]['params'] =& ParameterParser::parse($ini[$category]);
 }