Exemplo n.º 1
1
 /**
  * Executes this task.
  */
 public function main()
 {
     if ($this->path === null) {
         throw new BuildException('The path attribute must be specified');
     }
     $check = new AgaviModuleFilesystemCheck();
     $check->setConfigDirectory($this->project->getProperty('module.config.directory'));
     $check->setPath($this->path->getAbsolutePath());
     if (!$check->check()) {
         throw new BuildException('The path attribute must be a valid module base directory');
     }
     /* We don't know whether the module is configured or not here, so load the
      * values we want properly. */
     $this->tryLoadAgavi();
     $this->tryBootstrapAgavi();
     require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory')));
     $actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName()));
     $pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#';
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath()));
     for (; $iterator->valid(); $iterator->next()) {
         $rdi = $iterator->getInnerIterator();
         if ($rdi->isDot() || !$rdi->isFile()) {
             continue;
         }
         $file = $rdi->getPathname();
         if (preg_match($pattern, $file, $matches)) {
             $this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name']));
         }
     }
 }
 private function importModuleXML($accessLocation)
 {
     $config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives($accessLocation)));
     $this->instances = array_merge_recursive($this->instances, $config["instances"]);
     $this->defaults = array_merge_recursive($this->defaults, $config["defaults"]);
     $this->hosts = array_merge_recursive($this->hosts, $config["hosts"]);
 }
 public static function dispatch($arguments = array())
 {
     $GLOBALS['__PHPUNIT_BOOTSTRAP'] = dirname(__FILE__) . '/templates/AgaviBootstrap.tpl.php';
     $suites = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.testing_dir') . '/config/suites.xml'));
     $master_suite = new AgaviTestSuite('Master');
     if (!empty($arguments['include-suite'])) {
         $names = explode(',', $arguments['include-suite']);
         unset($arguments['include-suite']);
         foreach ($names as $name) {
             if (empty($suites[$name])) {
                 throw new InvalidArgumentException(sprintf('Invalid suite name %1$s.', $name));
             }
             $master_suite->addTest(self::createSuite($name, $suites[$name]));
         }
     } else {
         $excludes = array();
         if (!empty($arguments['exclude-suite'])) {
             $excludes = explode(',', $arguments['exclude-suite']);
             unset($arguments['exclude-suite']);
         }
         foreach ($suites as $name => $suite) {
             if (!in_array($name, $excludes)) {
                 $master_suite->addTest(self::createSuite($name, $suite));
             }
         }
     }
     $runner = new PHPUnit_TextUI_TestRunner();
     $runner->doRun($master_suite, $arguments);
 }
 public function initialize(AgaviContext $ctx, array $parameters = array())
 {
     parent::initialize($ctx, $parameters);
     $this->dqlViews = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/views.xml')));
     $this->view = $parameters["view"];
     $this->viewParameters = isset($parameters["parameters"]) ? $parameters["parameters"] : array();
     $this->validateTarget();
     $connection = $this->defaultConnection;
     if (isset($parameters["connection"])) {
         $connection = $parameters["connection"];
     }
     if ($this->view["connection"]) {
         $connection = $this->view["connection"];
     }
     AppKitLogger::verbose("Switching to connection %s", $connection);
     $db = $this->getContext()->getDatabaseManager()->getDatabase($connection);
     $this->useRetained = $db->useRetained();
     $this->connection = $ctx->getDatabaseConnection($connection);
     if ($this->connection != "icinga") {
         $ctx->getModel("DBALMetaManager", "Api")->switchIcingaDatabase($connection);
     }
     $this->user = $this->getContext()->getUser()->getNsmUser();
     $this->parseBaseDQL();
     $this->parseCustomVariables();
     $this->parseDQLExtensions();
     $this->parseDependencies();
 }
 public static function loadConfig()
 {
     if (self::$configLoaded) {
         return;
     }
     self::$config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/access.xml')));
     self::$configLoaded = true;
 }
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     parent::initialize($context, $parameters);
     $this->config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/icingaCommands.xml')));
     $this->user = $context->getUser();
     if ($this->user->getNsmUser()->hasTarget('IcingaCommandRestrictions')) {
         $this->filterCommandsByUser($this->config);
     }
 }
 /**
  * (non-PHPdoc)
  * @see CronksBaseModel::initialize()
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     parent::initialize($context, $parameters);
     // Init cronk categgory configurtion
     $tmp = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/cronks.xml'));
     self::$xml_categories = (array) $tmp[1];
     // Init user objects
     $this->refreshUser();
 }
 /**
  * Initialize this AgaviLoggingManager.
  *
  * @param      AgaviContext An AgaviContext instance.
  * @param      array        An array of initialization parameters.
  *
  * @throws     <b>AgaviInitializationException</b> If an error occurs while
  *                                                 initializing this instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     $this->context = $context;
     if (isset($parameters['default_message_class'])) {
         $this->defaultMessageClass = $parameters['default_message_class'];
     }
     // load logging configuration
     require AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/logging.xml', $context->getName());
 }
 /**
  * Initialize this model.
  *
  * @param      AgaviContext The current application context.
  *
  * @author     Luis Merino <*****@*****.**>
  * @since      0.1.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     $this->context = $context;
     try {
         $cfg = AgaviConfig::get('core.config_dir') . '/static_files.xml';
         $this->cacheName = AgaviConfigCache::checkConfig($cfg, $this->context->getName());
         require $this->cacheName;
     } catch (AgaviUnreadableException $e) {
         throw new AgaviConfigurationException($e->getMessage());
     }
 }
Exemplo n.º 10
0
 /**
  * Execute this configuration handler.
  *
  * @param      string An absolute filesystem path to a configuration file.
  * @param      string An optional context in which we are currently running.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviUnreadableException</b> If a requested configuration
  *                                             file does not exist or is not
  *                                             readable.
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function execute($config, $context = null)
 {
     $pathParts = pathinfo($config);
     // unlike basename, filename does not contain the extension, which is what we need there
     $lookupPaths = AgaviLocale::getLookupPath($pathParts['filename']);
     $lookupPaths[] = 'root';
     $data = array('layout' => array('orientation' => array('lines' => 'top-to-bottom', 'characters' => 'left-to-right')));
     foreach (array_reverse($lookupPaths) as $basename) {
         $filePath = $pathParts['dirname'] . '/' . $basename . '.' . $pathParts['extension'];
         if (is_readable($filePath)) {
             $ldmlTree = AgaviConfigCache::parseConfig($filePath, false, $this->getValidationFile(), $this->parser);
             $this->prepareParentInformation($ldmlTree);
             $this->parseLdmlTree($ldmlTree->ldml, $data);
         }
     }
     $dayMap = array('sun' => AgaviDateDefinitions::SUNDAY, 'mon' => AgaviDateDefinitions::MONDAY, 'tue' => AgaviDateDefinitions::TUESDAY, 'wed' => AgaviDateDefinitions::WEDNESDAY, 'thu' => AgaviDateDefinitions::THURSDAY, 'fri' => AgaviDateDefinitions::FRIDAY, 'sat' => AgaviDateDefinitions::SATURDAY);
     // fix the day indices for all day fields
     foreach ($data['calendars'] as $calKey => &$calValue) {
         // skip the 'default' => '' key => value pair
         if (is_array($calValue)) {
             if (isset($calValue['days']['format'])) {
                 foreach ($calValue['days']['format'] as $formatKey => &$formatValue) {
                     if (is_array($formatValue)) {
                         $newData = array();
                         foreach ($formatValue as $day => $value) {
                             $newData[$dayMap[$day]] = $value;
                         }
                         $formatValue = $newData;
                     }
                 }
             }
             if (isset($calValue['days']['stand-alone'])) {
                 foreach ($calValue['days']['stand-alone'] as $formatKey => &$formatValue) {
                     if (is_array($formatValue)) {
                         $newData = array();
                         foreach ($formatValue as $day => $value) {
                             $newData[$dayMap[$day]] = $value;
                         }
                         $formatValue = $newData;
                     }
                 }
             }
         }
     }
     $code = array();
     $code[] = 'return ' . var_export($data, true) . ';';
     return $this->generate($code, $config);
 }
 /**
  * @see        AgaviIniConfigHandler::execute()
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.10.0
  */
 public function execute($config, $context = null)
 {
     $parsed = AgaviConfigCache::parseConfig($config, false, $this->getValidationFile(), $this->parser);
     if (!isset($parsed->configurations)) {
         $error = 'Configuration file "%s" is not in the Agavi 0.11 legacy namespace (http://agavi.org/agavi/1.0/config) and/or does not contain a <configurations> element as root node.';
         $error = sprintf($error, $config);
         throw new AgaviConfigurationException($error);
     }
     $configurations = $this->orderConfigurations($parsed->configurations, AgaviConfig::get('core.environment'), $context);
     $data = array();
     foreach ($configurations as $cfg) {
         $data = array_merge($data, $this->convertToArray($cfg, true));
     }
     // compile data
     $code = 'return ' . var_export($data, true) . ';';
     return $this->generate($code, $config);
 }
Exemplo n.º 12
0
 /**
  * Dispatch the test run.
  *
  * @param      array An array of arguments configuring PHPUnit behavior.
  * @param      bool  Whether exit() should be called with an appropriate shell
  *                   exit status to indicate success or failures/errors.
  *
  * @return     PHPUnit_Framework_TestResult The PHPUnit result object.
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.0
  * @deprecated 1.1.0 Use AgaviPhpUnitCli
  */
 public static function dispatch($arguments = array(), $exit = true)
 {
     $suites = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.testing_dir') . '/config/suites.xml'));
     $master_suite = new AgaviTestSuite('Master');
     if (!empty($arguments['include-suite'])) {
         $names = explode(',', $arguments['include-suite']);
         unset($arguments['include-suite']);
         foreach ($names as $name) {
             if (empty($suites[$name])) {
                 throw new InvalidArgumentException(sprintf('Invalid suite name %1$s.', $name));
             }
             $master_suite->addTest(self::createSuite($name, $suites[$name]));
         }
     } else {
         $excludes = array();
         if (!empty($arguments['exclude-suite'])) {
             $excludes = explode(',', $arguments['exclude-suite']);
             unset($arguments['exclude-suite']);
         }
         foreach ($suites as $name => $suite) {
             if (!in_array($name, $excludes)) {
                 $master_suite->addTest(self::createSuite($name, $suite));
             }
         }
     }
     if (version_compare(PHPUnit_Runner_Version::id(), '3.6', '<')) {
         // PHP_CodeCoverage_Filter is a singleton
         $runner = new PHPUnit_TextUI_TestRunner();
     } else {
         // PHP_CodeCoverage_Filter instance must be passed to the test runner
         $runner = new PHPUnit_TextUI_TestRunner(null, self::$codeCoverageFilter);
     }
     $result = $runner->doRun($master_suite, $arguments);
     if ($exit) {
         // bai
         exit(self::getExitStatus($result));
     } else {
         // return result so calling code can use it
         return $result;
     }
 }
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     $this->context = $context;
     include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/translation.xml');
     $this->loadSupplementalData();
     $this->loadTimeZoneData();
     $this->loadAvailableLocales();
     if ($this->defaultLocaleIdentifier === null) {
         throw new AgaviException('Tried to use the translation system without a default locale and without a locale set');
     }
     $this->setLocale($this->defaultLocaleIdentifier);
     if ($this->defaultTimeZone === null) {
         $this->defaultTimeZone = date_default_timezone_get();
     } else {
         date_default_timezone_set($this->defaultTimeZone);
     }
     if ($this->defaultTimeZone === 'System/Localtime') {
         // http://trac.agavi.org/ticket/1008
         throw new AgaviException("Your default timezone is 'System/Localtime', which will causes problems with icinga-web date function." . "Please set  date.timezone in your php.ini or set a default timezone in the app/config/translations.xml file of icinga-web.");
     }
 }
Exemplo n.º 14
0
 /**
  * Executes the task.
  */
 public function main()
 {
     if ($this->name === null) {
         throw new BuildException('The name attribute must be specified');
     }
     $this->tryLoadAgavi();
     $this->tryBootstrapAgavi();
     /* Oookay. This is interesting. */
     $moduleName = $this->name;
     require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/%s/%s/module.xml', (string) $this->project->getProperty('project.directory'), (string) $this->project->getProperty('project.directory.app.modules'), $this->name, (string) $this->project->getProperty('module.config.directory')));
     /* Set up us the values.
      *
      * XXX: With regards to the defaults:
      *
      * You might expect to use the <property>.default properties defined in
      * build.xml. But this is not so; consider that someone might have decided
      * to upgrade their project properties but still have some legacy modules
      * lying around. We need to use the actual Agavi defaults to ensure
      * consistency.
      *
      * If you change this, you're f*****g asking for it. */
     $values = array();
     $lowerModuleName = strtolower($moduleName);
     $values['action.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.action.path', $lowerModuleName), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php');
     $values['action.path'] = AgaviToolkit::expandVariables($values['action.path'], array('moduleName' => $moduleName));
     $values['cache.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.cache.path', $lowerModuleName), '%core.module_dir%/${moduleName}/cache/${actionName}.xml');
     $values['cache.path'] = AgaviToolkit::expandVariables($values['cache.path'], array('moduleName' => $moduleName));
     $values['templates.directory'] = AgaviConfig::get(sprintf('modules.%s.agavi.template.directory', $lowerModuleName), '%core.module_dir%/${module}/templates');
     $values['templates.directory'] = AgaviToolkit::expandVariables($values['templates.directory'], array('module' => $moduleName));
     $values['validate.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.validate.path', $lowerModuleName), '%core.module_dir%/${moduleName}/validate/${actionName}.xml');
     $values['validate.path'] = AgaviToolkit::expandVariables($values['validate.path'], array('moduleName' => $moduleName));
     $values['view.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.view.path', $lowerModuleName), '%core.module_dir%/${moduleName}/views/${viewName}View.class.php');
     $values['view.path'] = AgaviToolkit::expandVariables($values['view.path'], array('moduleName' => $moduleName));
     $values['view.name'] = AgaviConfig::get(sprintf('modules.%s.agavi.view.name', $lowerModuleName), '${actionName}${viewName}');
     /* Main screen turn on. */
     foreach ($values as $name => $value) {
         $this->project->setUserProperty(sprintf('%s.%s', $this->prefix, $name), $value);
     }
 }
Exemplo n.º 15
0
 /**
  * Startup the Agavi core
  *
  * @param      string environment the environment to use for this session.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public static function bootstrap($environment = null)
 {
     // set up our __autoload
     spl_autoload_register(array('AgaviAutoloader', 'loadClass'));
     try {
         if ($environment === null) {
             // no env given? let's read one from core.environment
             $environment = AgaviConfig::get('core.environment');
         } elseif (AgaviConfig::has('core.environment') && AgaviConfig::isReadonly('core.environment')) {
             // env given, but core.environment is read-only? then we must use that instead and ignore the given setting
             $environment = AgaviConfig::get('core.environment');
         }
         if ($environment === null) {
             // still no env? oh man...
             throw new AgaviException('You must supply an environment name to Agavi::bootstrap() or set the name of the default environment to be used in the configuration directive "core.environment".');
         }
         // finally set the env to what we're really using now.
         AgaviConfig::set('core.environment', $environment, true, true);
         AgaviConfig::set('core.debug', false, false);
         if (!AgaviConfig::has('core.app_dir')) {
             throw new AgaviException('Configuration directive "core.app_dir" not defined, terminating...');
         }
         // define a few filesystem paths
         AgaviConfig::set('core.cache_dir', AgaviConfig::get('core.app_dir') . '/cache', false, true);
         AgaviConfig::set('core.config_dir', AgaviConfig::get('core.app_dir') . '/config', false, true);
         AgaviConfig::set('core.system_config_dir', AgaviConfig::get('core.agavi_dir') . '/config/defaults', false, true);
         AgaviConfig::set('core.lib_dir', AgaviConfig::get('core.app_dir') . '/lib', false, true);
         AgaviConfig::set('core.model_dir', AgaviConfig::get('core.app_dir') . '/models', false, true);
         AgaviConfig::set('core.module_dir', AgaviConfig::get('core.app_dir') . '/modules', false, true);
         AgaviConfig::set('core.template_dir', AgaviConfig::get('core.app_dir') . '/templates', false, true);
         AgaviConfig::set('core.cldr_dir', AgaviConfig::get('core.agavi_dir') . '/translation/data', false, true);
         // autoloads first (will trigger the compilation of config_handlers.xml)
         $autoload = AgaviConfig::get('core.config_dir') . '/autoload.xml';
         if (!is_readable($autoload)) {
             $autoload = AgaviConfig::get('core.system_config_dir') . '/autoload.xml';
         }
         AgaviConfigCache::load($autoload);
         // load base settings
         AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml');
         // clear our cache if the conditions are right
         if (AgaviConfig::get('core.debug')) {
             AgaviToolkit::clearCache();
             // load base settings
             AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml');
         }
         $compile = AgaviConfig::get('core.config_dir') . '/compile.xml';
         if (!is_readable($compile)) {
             $compile = AgaviConfig::get('core.system_config_dir') . '/compile.xml';
         }
         // required classes for the framework
         AgaviConfigCache::load($compile);
     } catch (Exception $e) {
         AgaviException::render($e);
     }
 }
 /**
  * Returns a properly ordered array of AgaviConfigValueHolder configuration
  * elements for given env and context.
  *
  * @param      AgaviConfigValueHolder The root config element
  * @param      string                 An environment name.
  * @param      string                 A context name.
  * @param      bool                   Whether the parser class should be
  *                                    autoloaded or not.
  *
  * @return     array An array of ConfigValueHolder configuration elements.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function orderConfigurations(AgaviConfigValueHolder $configurations, $environment = null, $context = null, $autoloadParser = true)
 {
     $configs = array();
     if ($configurations->hasAttribute('parent')) {
         $parent = AgaviToolkit::literalize($configurations->getAttribute('parent'));
         $parentConfigs = $this->orderConfigurations(AgaviConfigCache::parseConfig($parent, $autoloadParser, $this->getValidationFile(), $this->parser)->configurations, $environment, $context, $autoloadParser);
         $configs = array_merge($configs, $parentConfigs);
     }
     foreach ($configurations as $cfg) {
         if (!$cfg->hasAttribute('environment') && !$cfg->hasAttribute('context')) {
             $configs[] = $cfg;
         }
     }
     foreach ($configurations as $cfg) {
         if ($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && !$cfg->hasAttribute('context')) {
             $configs[] = $cfg;
         }
     }
     foreach ($configurations as $cfg) {
         if (!$cfg->hasAttribute('environment') && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) {
             $configs[] = $cfg;
         }
     }
     foreach ($configurations as $cfg) {
         if ($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) {
             $configs[] = $cfg;
         }
     }
     return $configs;
 }
Exemplo n.º 17
0
 /**
  * Returns a new AgaviLocale object from the given identifier.
  *
  * @param      string The locale identifier
  * @param      bool   Force a new instance even if an identical one exists.
  *
  * @return     AgaviLocale The locale instance which matches the available
  *                         locales most.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function getLocale($identifier, $forceNew = false)
 {
     // enable shortcut notation to only set options to the current locale
     if ($identifier[0] == '@' && $this->currentLocaleIdentifier) {
         $idData = AgaviLocale::parseLocaleIdentifier($this->currentLocaleIdentifier);
         $identifier = $idData['locale_str'] . $identifier;
         $newIdData = AgaviLocale::parseLocaleIdentifier($identifier);
         $idData['options'] = array_merge($idData['options'], $newIdData['options']);
     } else {
         $idData = AgaviLocale::parseLocaleIdentifier($identifier);
     }
     // this doesn't care about the options
     $availableLocale = $this->availableLocales[$this->getLocaleIdentifier($identifier)];
     // if the user wants all options reset he supplies an 'empty' option set (identifier ends with @)
     if (substr($identifier, -1) == '@') {
         $idData['options'] = array();
     } else {
         $idData['options'] = array_merge($availableLocale['identifierData']['options'], $idData['options']);
     }
     if (($atPos = strpos($identifier, '@')) !== false) {
         $identifier = $availableLocale['identifierData']['locale_str'] . substr($identifier, $atPos);
     } else {
         $identifier = $availableLocale['identifier'];
     }
     if (!$forceNew && isset($this->localeCache[$identifier])) {
         return $this->localeCache[$identifier];
     }
     if (!isset($this->localeDataCache[$idData['locale_str']])) {
         $lookupPath = AgaviLocale::getLookupPath($availableLocale['identifierData']);
         $cldrDir = AgaviConfig::get('core.cldr_dir');
         $data = null;
         foreach ($lookupPath as $localeName) {
             $fileName = $cldrDir . '/locales/' . $localeName . '.xml';
             if (is_readable($fileName)) {
                 $data = (include AgaviConfigCache::checkConfig($fileName));
                 break;
             }
         }
         if ($data === null) {
             throw new AgaviException('No data available for locale ' . $identifier);
         }
         if ($availableLocale['identifierData']['territory']) {
             $territory = $availableLocale['identifierData']['territory'];
             if (isset($this->supplementalData['territories'][$territory]['currencies'])) {
                 $slice = array_slice($this->supplementalData['territories'][$territory]['currencies'], 0, 1);
                 $currency = current($slice);
                 $data['locale']['currency'] = $currency['currency'];
             }
         }
         $this->localeDataCache[$idData['locale_str']] = $data;
     }
     $data = $this->localeDataCache[$idData['locale_str']];
     if (isset($idData['options']['calendar'])) {
         $data['locale']['calendar'] = $idData['options']['calendar'];
     }
     if (isset($idData['options']['currency'])) {
         $data['locale']['currency'] = $idData['options']['currency'];
     }
     if (isset($idData['options']['timezone'])) {
         $data['locale']['timezone'] = $idData['options']['timezone'];
     }
     $locale = new AgaviLocale();
     $locale->initialize($this->context, $availableLocale['parameters'], $identifier, $data);
     if (!$forceNew) {
         $this->localeCache[$identifier] = $locale;
     }
     return $locale;
 }
 /**
  * Initialize this DatabaseManager.
  *
  * @param      AgaviContext An AgaviContext instance.
  * @param      array        An array of initialization parameters.
  *
  * @throws     <b>AgaviInitializationException</b> If an error occurs while
  *                                                 initializing this 
  *                                                 DatabaseManager.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     $this->context = $context;
     // load database configuration
     require AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/databases.xml');
 }
 protected function loadMigrationConfig()
 {
     return include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . MigrationServiceProvisioner::MIGRATION_CONFIG_NAME);
 }
Exemplo n.º 20
0
 /**
  * Do any necessary startup work after initialization.
  *
  * This method is not called directly after initialize().
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function startup()
 {
     parent::startup();
     // user-supplied "wsdl" and "options" parameters
     $wsdl = $this->getParameter('wsdl');
     if (!$wsdl) {
         // no wsdl was specified, that means we generate one from the annotations in routing.xml
         $wsdl = $this->context->getRouting()->getWsdlPath();
     }
     $this->setParameter('wsdl', $wsdl);
     // get the name of the class to use for the client, defaults to PHP's own "SoapClient"
     $soapClientClass = $this->getParameter('soap_client_class', 'SoapClient');
     $soapClientOptions = $this->getParameter('soap_client_options', array());
     // get the name of the class to use for the server, defaults to PHP's own "SoapServer"
     $soapServerClass = $this->getParameter('soap_server_class', 'SoapServer');
     $soapServerOptions = $this->getParameter('soap_server_options', array());
     // get the name of the class to use for handling soap calls, defaults to Agavi's "AgaviSoapControllerCallHandler"
     $soapHandlerClass = $this->getParameter('soap_handler_class', 'AgaviSoapControllerCallHandler');
     // force client's soap version to be the same as the server's
     if (isset($soapServerOptions['soap_version'])) {
         $soapClientOptions['soap_version'] = $soapServerOptions['soap_version'];
     }
     // force client's cache_wsdl setting to be the same as the server's
     if (isset($soapServerOptions['cache_wsdl'])) {
         // and cast it to an int
         $soapServerOptions['cache_wsdl'] = (int) $soapServerOptions['cache_wsdl'];
         $soapClientOptions['cache_wsdl'] = $soapServerOptions['cache_wsdl'];
     }
     if (isset($soapServerOptions['features'])) {
         // cast this to an int
         $soapServerOptions['features'] = (int) $soapServerOptions['features'];
     }
     // create a client, so we can grab the functions and types defined in the wsdl (not possible from the server, duh)
     $this->soapClient = new $soapClientClass($wsdl, $soapClientOptions);
     if ($this->getParameter('auto_classmap')) {
         // we have to create a classmap automatically.
         // to do that, we read the defined types, and set identical values for type and class name.
         $classmap = array();
         // with an optional prefix, of course.
         $prefix = $this->getParameter('auto_classmap_prefix', '');
         foreach ($this->soapClient->__getTypes() as $definition) {
             if (preg_match('/^struct (\\S+) \\{$/m', $definition, $matches)) {
                 $classmap[$matches[1]] = $prefix . $matches[1];
             }
         }
         if (isset($soapServerOptions['classmap'])) {
             $classmap = array_merge((array) $classmap, $soapServerOptions['classmap']);
         }
         $soapServerOptions['classmap'] = $classmap;
     }
     // create a server
     $this->soapServer = new $soapServerClass($wsdl, $soapServerOptions);
     $newSoapHandlerClass = $soapHandlerClass . 'WithAutoHeaders';
     // build the special extension class to the handler that contains methods for each of the headers
     if ($this->getParameter('auto_headers', true)) {
         // the cache filename we'll be using
         $cache = AgaviConfigCache::getCacheName($soapHandlerClass, $this->context->getName());
         if (AgaviConfigCache::isModified($wsdl, $cache)) {
             $doc = new DOMDocument();
             $doc->load($wsdl);
             $xpath = new DOMXPath($doc);
             $xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/wsdl/soap/');
             $code = array();
             $code[] = '<?php';
             $code[] = sprintf('class %s extends %s {', $newSoapHandlerClass, $soapHandlerClass);
             $code[] = '  protected $rd;';
             $code[] = '  public function __construct(AgaviContext $context) {';
             $code[] = '    parent::__construct($context);';
             $code[] = '    $this->rd = $this->context->getRequest()->getRequestData();';
             $code[] = '  }';
             $headers = array();
             foreach ($xpath->query('//soap:header') as $header) {
                 $name = $header->getAttribute('part');
                 if (in_array($name, $headers)) {
                     continue;
                 }
                 $headers[] = $name;
                 $code[] = sprintf('  public function %s($value) {', $name);
                 $code[] = sprintf('    $this->rd->setHeader(%s, $value);', var_export($name, true));
                 $code[] = '  }';
             }
             $code[] = '}';
             $code[] = '?>';
             $code = implode("\n", $code);
             AgaviConfigCache::writeCacheFile($soapHandlerClass, $cache, $code);
         }
         include $cache;
     }
     // give it a class that handles method calls
     // that class uses __call
     // the class ctor gets the context as the first argument
     $this->soapServer->setClass($newSoapHandlerClass, $this->context);
 }
Exemplo n.º 21
0
 public static function callHandler($name, $config, $cache, $context, array $handlerInfo = null)
 {
     parent::callHandler($name, $config, $cache, $context, $handlerInfo);
 }
 /**
  * (non-PHPdoc)
  * @see AppKitBaseModel::initialize()
  */
 public function initialize(AgaviContext $ctx, array $parameters = array())
 {
     parent::initialize($ctx, $parameters);
     include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/javascript.xml');
     include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/css.xml');
 }
Exemplo n.º 23
0
 /**
  * (re)Initialize the AgaviContext instance.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @author     Mike Vincent <*****@*****.**>
  * @since      0.10.0
  */
 public function initialize()
 {
     try {
         include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/factories.xml', $this->name);
     } catch (Exception $e) {
         AgaviException::render($e, $this);
     }
     register_shutdown_function(array($this, 'shutdown'));
 }
 public function removeRestrictedCommands()
 {
     $data = $this->data;
     if (!isset($data["option"])) {
         return;
     }
     if (!isset($data["option"]["commands"])) {
         return;
     }
     if (!isset($data["option"]["commands"]["items"])) {
         return;
     }
     $items = $data["option"]["commands"]["items"];
     if (!is_array($items)) {
         return;
     }
     $config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/icingaCommands.xml')));
     $toRemove = array();
     foreach ($items as $cmd_name => $cmd_def) {
         if (!isset($config[$cmd_name])) {
             $toRemove[] = $cmd_name;
             continue;
         }
         if (!$config[$cmd_name]["isSimple"]) {
             $toRemove[] = $cmd_name;
         }
     }
     foreach ($toRemove as $removeItem) {
         unset($data["option"]["commands"]["items"][$removeItem]);
     }
     $this->data = $data;
 }
Exemplo n.º 25
0
 /**
  * Load the routing.xml configuration file.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 protected function loadConfig()
 {
     $cfg = AgaviConfig::get('core.config_dir') . '/routing.xml';
     // allow missing routing.xml when routing is not enabled
     if ($this->isEnabled() || is_readable($cfg)) {
         $this->importRoutes(unserialize(file_get_contents(AgaviConfigCache::checkConfig($cfg, $this->context->getName()))));
     }
 }
 private function initializeAutosettings()
 {
     // Try to set the web path to correct urls within the frontend
     if (AgaviConfig::get('core.default_context') == 'web') {
         // Try to set the web path to correct urls within the frontend
         if (AgaviConfig::get('org.icinga.appkit.web_path', null) == null) {
             AgaviConfig::set('org.icinga.appkit.web_path', AppKitStringUtil::extractWebPath(), true, true);
         }
     }
     include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.config_dir%/schedules.xml'));
     // Global temp directory
     AgaviConfig::set('core.tmp_dir', AgaviConfig::get('core.data_dir') . '/tmp');
 }
 /**
  * Execute this filter.
  *
  * @param      AgaviFilterChain        The filter chain.
  * @param      AgaviExecutionContainer The current execution container.
  *
  * @throws     <b>AgaviInitializationException</b> If an error occurs during
  *                                                 View initialization.
  * @throws     <b>AgaviViewException</b>           If an error occurs while
  *                                                 executing the View.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Felix Gilcher <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviFilterChain $filterChain, AgaviExecutionContainer $container)
 {
     // $lm = $this->context->getLoggerManager();
     // get the context, controller and validator manager
     $controller = $this->context->getController();
     // get the current action information
     $actionName = $container->getActionName();
     $moduleName = $container->getModuleName();
     // the action instance
     $actionInstance = $container->getActionInstance();
     $request = $this->context->getRequest();
     $isCacheable = false;
     $cachingDotXml = AgaviToolkit::evaluateModuleDirective($moduleName, 'agavi.cache.path', array('moduleName' => $moduleName, 'actionName' => $actionName));
     if ($this->getParameter('enable_caching', true) && is_readable($cachingDotXml)) {
         // $lm->log('Caching enabled, configuration file found, loading...');
         // no _once please!
         include AgaviConfigCache::checkConfig($cachingDotXml, $this->context->getName());
     }
     $isActionCached = false;
     if ($isCacheable) {
         try {
             $groups = $this->determineGroups($config['groups'], $container);
             $actionGroups = array_merge($groups, array(self::ACTION_CACHE_ID));
         } catch (AgaviUncacheableException $e) {
             // a group callback threw an exception. that means we're not allowed t cache
             $isCacheable = false;
         }
         if ($isCacheable) {
             // this is not wrapped in the try/catch block above as it might throw an exception itself
             $isActionCached = $this->checkCache(array_merge($groups, array(self::ACTION_CACHE_ID)), $config['lifetime']);
             if (!$isActionCached) {
                 // cacheable, but action is not cached. notify our callback so it can prevent the stampede that follows
                 $this->startedCacheCreationCallback(self::CACHE_CALLBACK_ACTION_NOT_CACHED, $actionGroups, $config, $container);
             }
         }
     } else {
         // $lm->log('Action is not cacheable!');
     }
     if ($isActionCached) {
         // $lm->log('Action is cached, loading...');
         // cache/dir/4-8-15-16-23-42 contains the action cache
         try {
             $actionCache = $this->readCache($actionGroups);
             // and restore action attributes
             $actionInstance->setAttributes($actionCache['action_attributes']);
         } catch (AgaviException $e) {
             // cacheable, but action is not cached. notify our callback so it can prevent the stampede that follows
             $this->startedCacheCreationCallback(self::CACHE_CALLBACK_ACTION_CACHE_GONE, $actionGroups, $config, $container);
             $isActionCached = false;
         }
     }
     $isViewCached = false;
     $rememberTheView = null;
     while (true) {
         if (!$isActionCached) {
             $actionCache = array();
             // $lm->log('Action not cached, executing...');
             // execute the Action and get the View to execute
             list($actionCache['view_module'], $actionCache['view_name']) = $container->runAction();
             // check if we've just run the action again after a previous cache read revealed that the view is not cached for this output type and we need to go back to square one due to the lack of action attribute caching configuration...
             // if yes: is the view module/name that we got just now different from what was in the cache?
             if (isset($rememberTheView) && $actionCache != $rememberTheView) {
                 // yup. clear it!
                 $ourClass = get_class($this);
                 call_user_func(array($ourClass, 'clearCache'), $groups);
             }
             // check if the returned view is cacheable
             if ($isCacheable && is_array($config['views']) && !in_array(array('module' => $actionCache['view_module'], 'name' => $actionCache['view_name']), $config['views'], true)) {
                 $isCacheable = false;
                 $this->abortedCacheCreationCallback(self::CACHE_CALLBACK_VIEW_NOT_CACHEABLE, $actionGroups, $config, $container);
                 // so that view is not cacheable? okay then:
                 // check if we've just run the action again after a previous cache read revealed that the view is not cached for this output type and we need to go back to square one due to the lack of action attribute caching configuration...
                 // 'cause then we need to flush all those existing caches - obviously, that data is stale now, as we learned, since we are not allowed to cache anymore for the view that was returned now
                 if (isset($rememberTheView)) {
                     // yup. clear it!
                     $ourClass = get_class($this);
                     call_user_func(array($ourClass, 'clearCache'), $groups);
                 }
                 // $lm->log('Returned View is not cleared for caching, setting cacheable status to false.');
             } else {
                 // $lm->log('Returned View is cleared for caching, proceeding...');
             }
             $actionAttributes = $actionInstance->getAttributes();
         }
         // clear the response
         $response = $container->getResponse();
         $response->clear();
         // clear any forward set, it's ze view's job
         $container->clearNext();
         if ($actionCache['view_name'] !== AgaviView::NONE) {
             $container->setViewModuleName($actionCache['view_module']);
             $container->setViewName($actionCache['view_name']);
             $key = $request->toggleLock();
             try {
                 // get the view instance
                 $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['view_name']);
                 // initialize the view
                 $viewInstance->initialize($container);
             } catch (Exception $e) {
                 // we caught an exception... unlock the request and rethrow!
                 $request->toggleLock($key);
                 throw $e;
             }
             $request->toggleLock($key);
             // Set the View Instance in the container
             $container->setViewInstance($viewInstance);
             $outputType = $container->getOutputType()->getName();
             if ($isCacheable) {
                 if (isset($config['output_types'][$otConfig = $outputType]) || isset($config['output_types'][$otConfig = '*'])) {
                     $otConfig = $config['output_types'][$otConfig];
                     $viewGroups = array_merge($groups, array($outputType));
                     if ($isActionCached) {
                         $isViewCached = $this->checkCache($viewGroups, $config['lifetime']);
                         if (!$isViewCached) {
                             // cacheable, but view is not cached. notify our callback so it can prevent the stampede that follows
                             $this->startedCacheCreationCallback(self::CACHE_CALLBACK_VIEW_NOT_CACHED, $viewGroups, $config, $container);
                         }
                     }
                 } else {
                     $this->abortedCacheCreationCallback(self::CACHE_CALLBACK_OUTPUT_TYPE_NOT_CACHEABLE, $actionGroups, $config, $container);
                     $isCacheable = false;
                 }
             }
             if ($isViewCached) {
                 // $lm->log('View is cached, loading...');
                 try {
                     $viewCache = $this->readCache($viewGroups);
                 } catch (AgaviException $e) {
                     $this->startedCacheCreationCallback(self::CACHE_CALLBACK_VIEW_CACHE_GONE, $viewGroups, $config, $container);
                     $isViewCached = false;
                 }
             }
             if (!$isViewCached) {
                 // view not cached
                 // has the cache config a list of action attributes?
                 if ($isActionCached && !$config['action_attributes']) {
                     // no. that means we must run the action again!
                     $isActionCached = false;
                     if ($isCacheable) {
                         // notify our callback so it can remove the lock that's on the view
                         // but only if we're still marked as cacheable (if not, then that means the OT is not cacheable, so there wouldn't be a $viewGroups)
                         $this->abortedCacheCreationCallback(self::CACHE_CALLBACK_ACTION_CACHE_USELESS, $viewGroups, $config, $container);
                     }
                     // notify our callback so it can prevent the stampede that follows
                     $this->startedCacheCreationCallback(self::CACHE_CALLBACK_ACTION_CACHE_USELESS, $actionGroups, $config, $container);
                     // but remember the view info, just in case it differs if we run the action again now
                     $rememberTheView = array('view_module' => $actionCache['view_module'], 'view_name' => $actionCache['view_name']);
                     continue;
                 }
                 $viewCache = array();
                 $viewCache['next'] = $this->executeView($container);
             }
             if ($viewCache['next'] instanceof AgaviExecutionContainer) {
                 // $lm->log('Forwarding request, skipping rendering...');
                 $container->setNext($viewCache['next']);
             } else {
                 $output = array();
                 $nextOutput = null;
                 if ($isViewCached) {
                     $layers = $viewCache['layers'];
                     $response = $viewCache['response'];
                     $container->setResponse($response);
                     foreach ($viewCache['template_variables'] as $name => $value) {
                         $viewInstance->setAttribute($name, $value);
                     }
                     foreach ($viewCache['request_attributes'] as $requestAttribute) {
                         $request->setAttribute($requestAttribute['name'], $requestAttribute['value'], $requestAttribute['namespace']);
                     }
                     foreach ($viewCache['request_attribute_namespaces'] as $ranName => $ranValues) {
                         $request->setAttributes($ranValues, $ranName);
                     }
                     $nextOutput = $response->getContent();
                 } else {
                     if ($viewCache['next'] !== null) {
                         // response content was returned from view execute()
                         $response->setContent($nextOutput = $viewCache['next']);
                         $viewCache['next'] = null;
                     }
                     $layers = $viewInstance->getLayers();
                     if ($isCacheable) {
                         $viewCache['template_variables'] = array();
                         foreach ($otConfig['template_variables'] as $varName) {
                             $viewCache['template_variables'][$varName] = $viewInstance->getAttribute($varName);
                         }
                         $viewCache['response'] = clone $response;
                         $viewCache['layers'] = array();
                         $viewCache['slots'] = array();
                         $lastCacheableLayer = -1;
                         if (is_array($otConfig['layers'])) {
                             if (count($otConfig['layers'])) {
                                 for ($i = count($layers) - 1; $i >= 0; $i--) {
                                     $layer = $layers[$i];
                                     $layerName = $layer->getName();
                                     if (isset($otConfig['layers'][$layerName])) {
                                         if (is_array($otConfig['layers'][$layerName])) {
                                             $lastCacheableLayer = $i - 1;
                                         } else {
                                             $lastCacheableLayer = $i;
                                         }
                                     }
                                 }
                             }
                         } else {
                             $lastCacheableLayer = count($layers) - 1;
                         }
                         for ($i = $lastCacheableLayer + 1; $i < count($layers); $i++) {
                             // $lm->log('Adding non-cacheable layer "' . $layers[$i]->getName() . '" to list');
                             $viewCache['layers'][] = clone $layers[$i];
                         }
                     }
                 }
                 $attributes =& $viewInstance->getAttributes();
                 // whether or not we should assign the previous' layer's output to the $slots array
                 $assignInnerToSlots = $this->getParameter('assign_inner_to_slots', false);
                 // $lm->log('Starting rendering...');
                 for ($i = 0; $i < count($layers); $i++) {
                     $layer = $layers[$i];
                     $layerName = $layer->getName();
                     // $lm->log('Running layer "' . $layerName . '"...');
                     foreach ($layer->getSlots() as $slotName => $slotContainer) {
                         if ($isViewCached && isset($viewCache['slots'][$layerName][$slotName])) {
                             // $lm->log('Loading cached slot "' . $slotName . '"...');
                             $slotResponse = $viewCache['slots'][$layerName][$slotName];
                         } else {
                             // $lm->log('Running slot "' . $slotName . '"...');
                             $slotResponse = $slotContainer->execute();
                             if ($isCacheable && !$isViewCached && isset($otConfig['layers'][$layerName]) && is_array($otConfig['layers'][$layerName]) && in_array($slotName, $otConfig['layers'][$layerName])) {
                                 // $lm->log('Adding response of slot "' . $slotName . '" to cache...');
                                 $viewCache['slots'][$layerName][$slotName] = $slotResponse;
                             }
                         }
                         // set the presentation data as a template attribute
                         $output[$slotName] = $slotResponse->getContent();
                         // and merge the other slot's response (this used to be conditional and done only when the content was not null)
                         // $lm->log('Merging in response from slot "' . $slotName . '"...');
                         $response->merge($slotResponse);
                     }
                     $moreAssigns = array('container' => $container, 'inner' => $nextOutput, 'request_data' => $container->getRequestData(), 'validation_manager' => $container->getValidationManager(), 'view' => $viewInstance);
                     // lock the request. can't be done outside the loop for the whole run, see #628
                     $key = $request->toggleLock();
                     try {
                         $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output, $moreAssigns);
                     } catch (Exception $e) {
                         // we caught an exception... unlock the request and rethrow!
                         $request->toggleLock($key);
                         throw $e;
                     }
                     // and unlock the request again
                     $request->toggleLock($key);
                     $response->setContent($nextOutput);
                     if ($isCacheable && !$isViewCached && $i === $lastCacheableLayer) {
                         $viewCache['response'] = clone $response;
                     }
                     $output = array();
                     if ($assignInnerToSlots) {
                         $output[$layer->getName()] = $nextOutput;
                     }
                 }
             }
             if ($isCacheable && !$isViewCached) {
                 // we're writing the view cache first. this is just in case we get into a situation with really bad timing on the leap of a second
                 $viewCache['request_attributes'] = array();
                 foreach ($otConfig['request_attributes'] as $requestAttribute) {
                     $viewCache['request_attributes'][] = $requestAttribute + array('value' => $request->getAttribute($requestAttribute['name'], $requestAttribute['namespace']));
                 }
                 $viewCache['request_attribute_namespaces'] = array();
                 foreach ($otConfig['request_attribute_namespaces'] as $requestAttributeNamespace) {
                     $viewCache['request_attribute_namespaces'][$requestAttributeNamespace] = $request->getAttributes($requestAttributeNamespace);
                 }
                 $this->writeCache($viewGroups, $viewCache, $config['lifetime']);
                 // notify callback that the execution has finished and caches have been written
                 $this->finishedCacheCreationCallback(self::CACHE_CALLBACK_VIEW_CACHE_WRITTEN, $viewGroups, $config, $container);
                 // $lm->log('Writing View cache...');
             }
         }
         // action cache writing must occur here, so actions that return AgaviView::NONE also get their cache written
         if ($isCacheable && !$isActionCached) {
             $actionCache['action_attributes'] = array();
             foreach ($config['action_attributes'] as $attributeName) {
                 $actionCache['action_attributes'][$attributeName] = $actionAttributes[$attributeName];
             }
             // $lm->log('Writing Action cache...');
             $this->writeCache($actionGroups, $actionCache, $config['lifetime']);
             // notify callback that the execution has finished and caches have been written
             $this->finishedCacheCreationCallback(self::CACHE_CALLBACK_ACTION_CACHE_WRITTEN, $actionGroups, $config, $container);
         }
         // we're done here. bai.
         break;
     }
 }
 /**
  * Get validation information from agavi for the given action and module
  * name for the request method 'read'.
  *
  * @author Jan Schütze <*****@*****.**>
  *
  * @param string $action name of action
  * @param string $module name of module
  *
  * @return array of parameters for all registered validators
  */
 protected function getParametersForActionAndModule($action, $module, $method = 'read')
 {
     /*
      * Agavi uses different coding standard, so we ignore the following...
      *
      * @codingStandardsIgnoreStart
      */
     $parameters = array();
     $this->getContext()->getController()->initializeModule($module);
     $validationManager = $this->getContext()->createInstanceFor('validation_manager');
     $validationConfig = \AgaviToolkit::evaluateModuleDirective($module, 'agavi.validate.path', array('moduleName' => $module, 'actionName' => \AgaviToolkit::canonicalName($action)));
     if (is_readable($validationConfig)) {
         require \AgaviConfigCache::checkConfig($validationConfig, $this->getContext()->getName());
     }
     foreach ($validationManager->getChilds() as $validator) {
         $property = new \ReflectionProperty(get_class($validator), 'arguments');
         $property->setAccessible(true);
         $arguments = $property->getValue($validator);
         $parameters[] = array('name' => implode(', ', $arguments), 'class' => $validator->getParameter('class'), 'required' => $validator->getParameter('required', 'true'), 'description' => $validator->getParameter('description', null), 'base' => $validator->getParameter('base', null));
     }
     /*
      * @codingStandardsIgnoreEnd
      */
     return $parameters;
 }
Exemplo n.º 29
0
 public function testTicket941()
 {
     if (!extension_loaded('xdebug')) {
         $this->markTestSkipped('This test check for an infinite loop, you need xdebug as protection.');
     }
     $config = AgaviConfig::get('core.module_dir') . '/Default/config/config_handlers.xml';
     AgaviTestingConfigCache::addConfigHandlersFile($config);
     AgaviConfigCache::checkConfig(AgaviConfig::get('core.module_dir') . '/Default/config/autoload.xml');
 }
 /**
  * Return a list of cronks defined in xml
  * @param boolean $all
  * @return array
  */
 private function getXmlCronks($all = false)
 {
     // pull cronk xml data from the cache
     $cached = $this->user->getStorage()->read("icinga.cronks.cache.xml");
     // get me a timestamp for our xml disk cache for cronks
     $configcache_ts = filemtime(AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/cronks.xml'));
     // do we have any cache?
     if (isset($cached) and isset($cached["data"])) {
         // is the cached data newer than that in the xml cache on disk?
         if (isset($cached["timestamp"]) and $cached["timestamp"] > $configcache_ts) {
             // return cache
             return $cached["data"];
         }
     }
     $out = array();
     foreach (self::$xml_cronk_data as $uid => $cronk) {
         /*
          * Database credentials overwrite xml credentials
          */
         $this->getSecurityModel()->setCronkUid($uid);
         if ($this->getSecurityModel()->hasDatabaseRoles()) {
             $cronk['groupsonly'] = $this->getSecurityModel()->getRoleNamesAsString();
         }
         if (isset($cronk['groupsonly']) && $this->checkGroups($cronk['groupsonly']) !== true && $this->agaviUser->hasCredential('icinga.cronk.admin') === false) {
             continue;
         } elseif (isset($cronk['principalsonly']) && $this->checkPrincipals($cronk['principalsonly']) !== true) {
             continue;
         } elseif (isset($cronk['disabled']) && $cronk['disabled'] == true) {
             continue;
         } elseif (!isset($cronk['action']) || !isset($cronk['module'])) {
             $this->getContext()->getLoggerManager()->log('No action or module for cronk: ' . $uid, AgaviLogger::ERROR);
             continue;
         }
         $out[$uid] = array('cronkid' => $uid, 'module' => $cronk['module'], 'action' => $cronk['action'], 'hide' => isset($cronk['hide']) ? (bool) $cronk['hide'] : false, 'description' => isset($cronk['description']) ? $cronk['description'] : null, 'name' => isset($cronk['name']) ? $cronk['name'] : null, 'categories' => isset($cronk['categories']) ? $cronk['categories'] : null, 'image' => isset($cronk['image']) ? $cronk['image'] : self::DEFAULT_CRONK_IMAGE, 'disabled' => isset($cronk['disabled']) ? (bool) $cronk['disabled'] : false, 'groupsonly' => isset($cronk['groupsonly']) ? $cronk['groupsonly'] : null, 'state' => isset($cronk['state']) ? $cronk['state'] : null, 'ae:parameter' => isset($cronk['ae:parameter']) ? $cronk['ae:parameter'] : null, 'system' => true, 'owner' => false, 'position' => isset($cronk['position']) ? $cronk['position'] : 0, 'owner_name' => self::DEFAULT_CRONK_OWNER, 'owner_id' => self::DEFAULT_CRONK_OWNERID);
     }
     // write data to the cache, with a timestamp
     $this->user->getStorage()->write("icinga.cronks.cache.xml", array("timestamp" => time(), "data" => $out));
     return $out;
 }