/** * Load configuration file of options. * * Optionally will cache the configuration. * * @param string $file * @throws Zend_Application_Exception When invalid configuration file is provided * @return array */ protected function _loadConfig($file) { $suffix = pathinfo($file, PATHINFO_EXTENSION); $suffix = $suffix === 'dist' ? pathinfo(basename($file, ".{$suffix}"), PATHINFO_EXTENSION) : $suffix; if ($suffix == 'ini') { $config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray(); } else { $config = parent::_loadConfig($file); } return $config; }
/** * Create a Zend_Config instance from database results * @param Zend_Db_Table_Rowset $results * @param Array $config The array that's recursively filled with the right keys * @return Zend_Config */ protected function _createIniFromResults($results, $env) { // Create a parse_ini_string() compatible string. $ini = "[{$env}]\n"; foreach ($results as $result) { $keyValue = "{$result->key} = \"{$result->value}\"\n"; $ini .= $keyValue; } $iniObj = Garp_Config_Ini::fromString($ini); return $iniObj; }
/** * Initialize the ini file. * @param String $file The path to the ini file * @param String $namespace What namespace to use in the ini file * @return Void */ public function init($file, $namespace = null) { $ini = Garp_Config_Ini::getCached($file); if ($namespace) { $namespaces = explode('.', $namespace); do { $namespace = array_shift($namespaces); $ini = $ini->{$namespace}; } while ($namespaces); } $this->_ini = $ini; }
/** * Overwrite cause we want to store the options elsewhere * * @return array */ public function getOptions() { $options = parent::getOptions(); if (!array_key_exists('enabled', $options)) { $options['enabled'] = true; } if ($options['enabled']) { $config = Garp_Config_Ini::getCached(APPLICATION_PATH . '/configs/acl.ini'); $aclOptions = $config->acl->toArray(); $options = array_merge($options, $aclOptions); } return $options; }
/** * After fetch callback * @param Array $args * @return Void */ public function afterFetch(array &$args) { $model = $args[0]; $results = $args[1]; $table = $model->getName(); $chartService = new Garp_Service_Google_Chart(); $ini = Garp_Config_Ini::getCached(APPLICATION_PATH . '/configs/routes.ini'); $routes = $ini->routes->toArray(); $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $routeFound = false; foreach ($routes as $r) { if (array_key_exists('route', $r) && $r['route'] === '/' . $table . '/:slug') { $routeFound = $r; break; } } if (!$routeFound) { throw new Exception('There is no direct route to this object.'); } // provide uniform interface, so we can always loop if (!$results instanceof Garp_Db_Table_Rowset) { $results = array($results); } foreach ($results as $row) { if (isset($row->slug) && $row->slug) { $refUrl = $view->fullUrl('/' . $table . '/' . $row->slug); $row->setVirtual('qrcode', $chartService->fetchQRCodeUrl($refUrl)); } } // return the pointer to 0 if ($results instanceof Garp_Db_Table_Rowset) { $results->rewind(); } else { // also, return results to the original format if it was no Rowset to begin with. $results = $results[0]; } }