Example #1
0
 public function load()
 {
     $args = func_get_args();
     foreach ($args as $file) {
         // Prepend config directory if the path doesn't start with . or /
         if ($file[0] != '.' && $file[0] != '/') {
             $file = Epi::getPath('config') . "/{$file}";
         }
         if (!file_exists($file)) {
             EpiException::raise(new EpiConfigException("Config file ({$file}) does not exist"));
             break;
             // need to simulate same behavior if exceptions are turned off
         }
         $parsed_array = parse_ini_file($file, true);
         foreach ($parsed_array as $key => $value) {
             if (!is_array($value)) {
                 $this->config->{$key} = $value;
             } else {
                 if (!isset($this->config->{$key})) {
                     $this->config->{$key} = new stdClass();
                 }
                 foreach ($value as $innerKey => $innerValue) {
                     $this->config->{$key}->{$innerKey} = $innerValue;
                 }
             }
         }
     }
 }
Example #2
0
 private function getFilePath($file)
 {
     // Prepend config directory if the path doesn't start with . or /
     if ($file[0] != '.' && $file[0] != '/') {
         $file = Epi::getPath('config') . "/{$file}";
     }
     return $file;
 }
Example #3
0
 /**
  * EpiRoute::get('/path/to/template.php', $array);
  * @name  get
  * @author  Jaisen Mathai <*****@*****.**>
  * @param string $template
  * @param array $vars
  * @method get
  * @static method
  */
 public function get($template = null, $vars = null)
 {
     $templateInclude = Epi::getPath('view') . '/' . $template;
     if (is_file($templateInclude)) {
         if (is_array($vars)) {
             extract($vars);
         }
         ob_start();
         include $templateInclude;
         $contents = ob_get_contents();
         ob_end_clean();
         return $contents;
     } else {
         EpiException::raise(new EpiException("Could not load template: {$templateInclude}", 404));
     }
 }
Example #4
0
 public function upgradePost()
 {
     getAuthentication()->requireAuthentication();
     getUpgrade()->performUpgrade();
     $configObj = getConfig();
     // Backwards compatibility
     // TODO remove in 2.0
     $basePath = dirname(Epi::getPath('config'));
     $configFile = sprintf('%s/userdata/configs/%s.ini', $basePath, getenv('HTTP_HOST'));
     if (!file_exists($configFile)) {
         $configFile = sprintf('%s/generated/%s.ini', Epi::getPath('config'), getenv('HTTP_HOST'));
     }
     $config = $configObj->getString($configFile);
     $config = preg_replace('/lastCodeVersion *= *"\\d+\\.\\d+\\.\\d+"/', sprintf('lastCodeVersion="%s"', getUpgrade()->getCurrentVersion()), $config);
     $configObj->write($configFile, $config);
     $this->route->redirect('/');
 }
Example #5
0
 /**
  * load('/path/to/file');
  * @name  load
  * @author  Jaisen Mathai <*****@*****.**>
  * @param string $file
  */
 public function load($file)
 {
     $file = Epi::getPath('config') . "/{$file}";
     if (!file_exists($file)) {
         EpiException::raise(new EpiException("Config file ({$file}) does not exist"));
         break;
         // need to simulate same behavior if exceptions are turned off
     }
     $parsed_array = parse_ini_file($file, true);
     foreach ($parsed_array as $route) {
         $method = strtolower($route['method']);
         if (isset($route['class']) && isset($route['function'])) {
             $this->{$method}($route['path'], array($route['class'], $route['function']));
         } elseif (isset($route['function'])) {
             $this->{$method}($route['path'], $route['function']);
         }
     }
 }
Example #6
0
 public function upgradePost()
 {
     getAuthentication()->requireAuthentication();
     getUpgrade()->performUpgrade();
     $configObj = getConfig();
     // Backwards compatibility
     // TODO remove in 2.0
     $basePath = dirname(Epi::getPath('config'));
     $configFile = sprintf('%s/userdata/configs/%s.ini', $basePath, getenv('HTTP_HOST'));
     if (!file_exists($configFile)) {
         $configFile = sprintf('%s/generated/%s.ini', Epi::getPath('config'), getenv('HTTP_HOST'));
     }
     $config = $configObj->getString($configFile);
     // Backwards compatibility
     // TODO remove in 2.0
     if (strstr($config, 'lastCodeVersion="') !== false) {
         $config = preg_replace('/lastCodeVersion="\\d+\\.\\d+\\.\\d+"/', sprintf('lastCodeVersion="%s"', getUpgrade()->getCurrentVersion()), $config);
     } else {
         // Before the upgrade code the lastCodeVersion was not in the config template
         $config = sprintf("[site]\nlastCodeVersion=\"%s\"\n\n", getUpgrade()->getCurrentVersion()) . $config;
     }
     $configObj->write($configFile, $config);
     $this->route->redirect('/');
 }
Example #7
0
 /**
  * load('api_config.ini')
  * @name load
  * @author Steve Mulligan <*****@*****.**>
  * @param string $api_config_ini_filename
  */
 public function load($file)
 {
     $file = Epi::getPath('config') . "/{$file}";
     if (!file_exists($file)) {
         EpiException::raise(new EpiException("Config file ({$file}) does not exist"));
         break;
         // need to simulate same behavior if exceptions are turned off
     }
     $parsed_array = parse_ini_file($file, true);
     foreach ($parsed_array as $route) {
         $method = strtolower($route['method']);
         $vis = strtolower($route['visibility']);
         // default visibiltiy is false.  you MUST explcitly allow external access by adding visibility = external to the ini file
         $visibility = self::internal;
         if ($vis == "external") {
             $visibility = self::external;
         }
         if (isset($route['class']) && isset($route['function'])) {
             $this->{$method}($route['path'], array($route['class'], $route['function']), $visibility);
         }
         if (isset($route['instance']) && isset($route['function'])) {
             $this->{$method}($route['path'], array(new $route['instance'](), $route['function']), $visibility);
         } elseif (isset($route['function'])) {
             $this->{$method}($route['path'], $route['function'], $visibility);
         }
     }
 }