本文整理汇总了PHP中AgaviToolkit::literalize方法的典型用法代码示例。如果您正苦于以下问题:PHP AgaviToolkit::literalize方法的具体用法?PHP AgaviToolkit::literalize怎么用?PHP AgaviToolkit::literalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AgaviToolkit
的用法示例。
在下文中一共展示了AgaviToolkit::literalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates the input.
*
* @return bool The value is a valid boolean
*
* @author Felix Gilcher <felix.gilcher@bitextender.com>
* @since 1.0.4
*/
protected function validate()
{
$value =& $this->getData($this->getArgument());
$origValue = $value;
if (is_bool($value)) {
// noop
} elseif (1 === $value || '1' === $value) {
$value = true;
} elseif (0 === $value || '0' === $value) {
$value = false;
} elseif (is_string($value)) {
$value = AgaviToolkit::literalize($value);
}
if (is_bool($value)) {
// we don't cast if the value is exported.
// caution, AgaviValidator::export does the test for empty
// strings, null and false values, so we can't use
// hasParameter here
if ($this->getParameter('export')) {
$value = $origValue;
} else {
$this->export($value);
}
return true;
}
$value = $origValue;
$this->throwError('type');
return false;
}
示例2: execute
public function execute(AgaviXmlConfigDomDocument $document)
{
$data = array();
$prefix = "org.icinga.";
$document->setDefaultNamespace(self::XML_NAMESPACE, 'settings');
foreach ($document->getConfigurationElements() as $cfg) {
foreach ($cfg->get('settings') as $setting) {
$localPrefix = $prefix;
// let's see if this buddy has a <settings> parent with valuable information
if ($setting->parentNode->localName == 'settings') {
if ($setting->parentNode->hasAttribute('prefix')) {
$localPrefix = $setting->parentNode->getAttribute('prefix');
}
}
$settingName = $localPrefix . $setting->getAttribute('name');
if ($setting->hasAgaviParameters()) {
$data[$settingName] = $setting->getAgaviParameters();
} else {
$data[$settingName] = AgaviToolkit::literalize($setting->getValue());
}
}
}
$code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');';
return $this->generate($code, $document->documentURI);
}
示例3: loadModuleFiles
private function loadModuleFiles($tm, &$files)
{
$default = $tm->getDefaultDomain();
$translator = $tm->getDomainTranslator($default, AgaviTranslationManager::MESSAGE);
$locale = $tm->getCurrentLocale();
$domains = array();
if ($translator instanceof AppKitGettextTranslator) {
$basePath = $translator->getDomainPathPattern();
$modules = scandir(AgaviToolkit::literalize("%core.module_dir%"));
foreach ($modules as $m) {
if ($m != '.' && $m != '..') {
$domains[] = $m;
}
}
foreach ($domains as $domain) {
$path = AgaviToolkit::expandVariables($basePath, array('domain' => $domain));
foreach (AgaviLocale::getLookupPath($tm->getCurrentLocale()->getIdentifier()) as $prefix) {
$result = $this->loadFile($path, $prefix, $files);
if ($result) {
$files[$domain] = $result;
}
}
}
}
}
示例4: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @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 David Zülke <dz@bitxtender.com>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author Sean Kerr <skerr@mojavi.org>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'settings');
// init our data array
$data = array();
$prefix = 'core.';
foreach ($document->getConfigurationElements() as $cfg) {
// let's do our fancy work
if ($cfg->has('system_actions')) {
foreach ($cfg->get('system_actions') as $action) {
$name = $action->getAttribute('name');
$data[sprintf('actions.%s_module', $name)] = $action->getChild('module')->getValue();
$data[sprintf('actions.%s_action', $name)] = $action->getChild('action')->getValue();
}
}
// loop over <setting> elements; there can be many of them
foreach ($cfg->get('settings') as $setting) {
$localPrefix = $prefix;
// let's see if this buddy has a <settings> parent with valuable information
if ($setting->parentNode->localName == 'settings') {
if ($setting->parentNode->hasAttribute('prefix')) {
$localPrefix = $setting->parentNode->getAttribute('prefix');
}
}
$settingName = $localPrefix . $setting->getAttribute('name');
if ($setting->hasAgaviParameters()) {
$data[$settingName] = $setting->getAgaviParameters();
} else {
$data[$settingName] = AgaviToolkit::literalize($setting->getValue());
}
}
if ($cfg->has('exception_templates')) {
foreach ($cfg->get('exception_templates') as $exception_template) {
$tpl = AgaviToolkit::expandDirectives($exception_template->getValue());
if (!is_readable($tpl)) {
throw new AgaviConfigurationException('Exception template "' . $tpl . '" does not exist or is unreadable');
}
if ($exception_template->hasAttribute('context')) {
foreach (array_map('trim', explode(' ', $exception_template->getAttribute('context'))) as $ctx) {
$data['exception.templates.' . $ctx] = $tpl;
}
} else {
$data['exception.default_template'] = AgaviToolkit::expandDirectives($tpl);
}
}
}
}
$code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');';
return $this->generate($code, $document->documentURI);
}
示例5: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'module');
// remember the config file path
$config = $document->documentURI;
$enabled = false;
$prefix = 'modules.${moduleName}.';
$data = array();
// loop over <configuration> elements
foreach ($document->getConfigurationElements() as $configuration) {
$module = $configuration->getChild('module');
if (!$module) {
continue;
}
// enabled flag is treated separately
$enabled = (bool) AgaviToolkit::literalize($module->getAttribute('enabled'));
// loop over <setting> elements; there can be many of them
foreach ($module->get('settings') as $setting) {
$localPrefix = $prefix;
// let's see if this buddy has a <settings> parent with valuable information
if ($setting->parentNode->localName == 'settings') {
if ($setting->parentNode->hasAttribute('prefix')) {
$localPrefix = $setting->parentNode->getAttribute('prefix');
}
}
$settingName = $localPrefix . $setting->getAttribute('name');
if ($setting->hasAgaviParameters()) {
$data[$settingName] = $setting->getAgaviParameters();
} else {
$data[$settingName] = AgaviToolkit::literalize($setting->getValue());
}
}
}
$code = array();
$code[] = '$lcModuleName = strtolower($moduleName);';
$code[] = 'AgaviConfig::set(AgaviToolkit::expandVariables(' . var_export($prefix . 'enabled', true) . ', array(\'moduleName\' => $lcModuleName)), ' . var_export($enabled, true) . ', true, true);';
if (count($data)) {
$code[] = '$moduleConfig = ' . var_export($data, true) . ';';
$code[] = '$moduleConfigKeys = array_keys($moduleConfig);';
$code[] = 'foreach($moduleConfigKeys as &$value) $value = AgaviToolkit::expandVariables($value, array(\'moduleName\' => $lcModuleName));';
$code[] = '$moduleConfig = array_combine($moduleConfigKeys, $moduleConfig);';
$code[] = 'AgaviConfig::fromArray($moduleConfig);';
}
return $this->generate($code, $config);
}
示例6: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to handle.
*
* @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 <ddb@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.11.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'config_handlers');
// init our data arrays
$handlers = array();
foreach ($document->getConfigurationElements() as $configuration) {
if (!$configuration->has('handlers')) {
continue;
}
// let's do our fancy work
foreach ($configuration->get('handlers') as $handler) {
$pattern = $handler->getAttribute('pattern');
$category = AgaviToolkit::normalizePath(AgaviToolkit::expandDirectives($pattern));
$class = $handler->getAttribute('class');
$transformations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(), AgaviXmlConfigParser::STAGE_COMPILATION => array());
if ($handler->has('transformations')) {
foreach ($handler->get('transformations') as $transformation) {
$path = AgaviToolkit::literalize($transformation->getValue());
$for = $transformation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
$transformations[$for][] = $path;
}
}
$validations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())), AgaviXmlConfigParser::STAGE_COMPILATION => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())));
if ($handler->has('validations')) {
foreach ($handler->get('validations') as $validation) {
$path = AgaviToolkit::literalize($validation->getValue());
$type = null;
if (!$validation->hasAttribute('type')) {
$type = $this->guessValidationType($path);
} else {
$type = $validation->getAttribute('type');
}
$for = $validation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
$step = $validation->getAttribute('step', AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER);
$validations[$for][$step][$type][] = $path;
}
}
$handlers[$category] = isset($handlers[$category]) ? $handlers[$category] : array('parameters' => array());
$handlers[$category] = array('class' => $class, 'parameters' => $handler->getAgaviParameters($handlers[$category]['parameters']), 'transformations' => $transformations, 'validations' => $validations);
}
}
$data = array('return ' . var_export($handlers, true));
return $this->generate($data, $document->documentURI);
}
示例7: getValidatorXMLForAction
/**
* Fetches the Validation xml for the action/module combination and returns it as
* an DOMDocument
*
* @param string The module name
* @param string The action to get the validation xml for
* @return AgaviXmlConfigDomDocument
*
* @author Jannis Moßhammer<jannis.mosshammer@netways.de>
* @throws AgaviConfigurationException when module or action does not exist
*/
protected function getValidatorXMLForAction($module, $action)
{
// get Module path
$path = AgaviToolkit::literalize('%core.module_dir%') . "/" . $module;
if (!file_exists(AgaviToolkit::normalizePath($path))) {
throw new AgaviConfigurationException("Couldn't find module " . $module);
}
// get Validation file
$actionPath = str_replace(".", "/", $action);
$xml = $path . "/validate/" . $actionPath . ".xml";
if (!file_exists(AgaviToolkit::normalizePath($path))) {
throw new AgaviConfigurationException("Couldn't find validation file for " . $action);
}
$dom = new AgaviXmlConfigDomDocument();
$dom->load(AgaviToolKit::normalizePath($xml));
//TODO: Validate xml
return $dom;
}
示例8: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author David Zülke <david.zuelke@bitextender.com>
* @author Sean Kerr <skerr@mojavi.org>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'filters');
$config = $document->documentURI;
$filters = array();
foreach ($document->getConfigurationElements() as $cfg) {
if ($cfg->has('filters')) {
foreach ($cfg->get('filters') as $filter) {
$name = $filter->getAttribute('name', AgaviToolkit::uniqid());
if (!isset($filters[$name])) {
$filters[$name] = array('params' => array(), 'enabled' => AgaviToolkit::literalize($filter->getAttribute('enabled', true)));
} else {
$filters[$name]['enabled'] = AgaviToolkit::literalize($filter->getAttribute('enabled', $filters[$name]['enabled']));
}
if ($filter->hasAttribute('class')) {
$filters[$name]['class'] = $filter->getAttribute('class');
}
$filters[$name]['params'] = $filter->getAgaviParameters($filters[$name]['params']);
}
}
}
$data = array();
foreach ($filters as $name => $filter) {
if (stripos($name, 'agavi') === 0) {
throw new AgaviConfigurationException('Filter names must not start with "agavi".');
}
if (!isset($filter['class'])) {
throw new AgaviConfigurationException('No class name specified for filter "' . $name . '" in ' . $config);
}
if ($filter['enabled']) {
$rc = new ReflectionClass($filter['class']);
$if = 'AgaviI' . ucfirst(strtolower(substr(basename($config), 0, strpos(basename($config), '_filters')))) . 'Filter';
if (!$rc->implementsInterface($if)) {
throw new AgaviFactoryException('Filter "' . $name . '" does not implement interface "' . $if . '"');
}
$data[] = '$filter = new ' . $filter['class'] . '();';
$data[] = '$filter->initialize($this->context, ' . var_export($filter['params'], true) . ');';
$data[] = '$filters[' . var_export($name, true) . '] = $filter;';
}
}
return $this->generate($data, $config);
}
示例9: importModuleConfigurations
private function importModuleConfigurations()
{
$moduleDir = AgaviToolkit::literalize("%core.module_dir%");
$modules = scandir($moduleDir);
foreach ($modules as $folder) {
$dir = $moduleDir;
if ($folder == ".." || $folder == "." || $folder == "Api") {
continue;
}
$dir = $dir . "/" . $folder . "/";
if (!is_dir($dir) || !is_readable($dir)) {
continue;
}
$accessLocation = $dir . "config/access.xml";
if (file_exists($accessLocation) && is_readable($accessLocation)) {
$this->importModuleXML($accessLocation);
}
}
}
示例10: validate
/**
* Validates the input.
*
* @return bool The value is a valid boolean
*
* @author Felix Gilcher <felix.gilcher@bitextender.com>
* @since 1.0.4
*/
protected function validate()
{
$value =& $this->getData($this->getArgument());
$castValue = $value;
if (is_bool($castValue)) {
// noop
} elseif (1 === $castValue || '1' === $castValue) {
$castValue = true;
} elseif (0 === $castValue || '0' === $castValue) {
$castValue = false;
} elseif (is_string($castValue)) {
$castValue = AgaviToolkit::literalize($castValue);
}
if (is_bool($castValue)) {
if ($this->hasParameter('export')) {
$this->export($castValue);
} else {
$value = $castValue;
}
return true;
}
$this->throwError('type');
return false;
}
示例11: literalize
/**
* Literalize a string value.
*
* @param string The value to literalize.
*
* @return string A literalized value.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author David Zülke <dz@bitxtender.com>
* @since 0.9.0
*
* @deprecated Use AgaviToolkit::expandDirectives() instead.
*/
public static function literalize($value)
{
return AgaviToolkit::literalize($value);
}
示例12: run
/**
* @param string An absolute filesystem path to a configuration file.
* @param string The environment name.
* @param string The optional context name.
* @param array An associative array of transformation information.
* @param array An associative array of validation information.
*
* @return DOMDocument A properly merged DOMDocument.
*
* @author David Zülke <dz@bitxtender.com>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @since 0.11.0
*/
public static function run($path, $environment, $context = null, array $transformationInfo = array(), array $validationInfo = array())
{
$isAgaviConfigFormat = true;
// build an array of documents (this one, and the parents)
$docs = array();
$previousPaths = array();
$nextPath = $path;
while ($nextPath !== null) {
// run the single stage parser
$parser = new AgaviXmlConfigParser($nextPath, $environment, $context);
$doc = $parser->execute($transformationInfo[self::STAGE_SINGLE], $validationInfo[self::STAGE_SINGLE]);
// put the new document in the list
$docs[] = $doc;
// make sure it (still) is a <configurations> file with the proper Agavi namespace
if ($isAgaviConfigFormat) {
$isAgaviConfigFormat = self::isAgaviConfigurationDocument($doc);
}
// is it an Agavi <configurations> element? does it have a parent attribute? yes? good. parse that next
// TODO: support future namespaces
if ($isAgaviConfigFormat && $doc->documentElement->hasAttribute('parent')) {
$theNextPath = AgaviToolkit::literalize($doc->documentElement->getAttribute('parent'));
// no infinite loop plz, kthx
if ($nextPath === $theNextPath) {
throw new AgaviParseException(sprintf("Agavi detected an infinite loop while processing parent configuration files of \n%s\n\nFile\n%s\nincludes itself as a parent.", $path, $theNextPath));
} elseif (isset($previousPaths[$theNextPath])) {
throw new AgaviParseException(sprintf("Agavi detected an infinite loop while processing parent configuration files of \n%s\n\nFile\n%s\nhas previously been included by\n%s", $path, $theNextPath, $previousPaths[$theNextPath]));
} else {
$previousPaths[$theNextPath] = $nextPath;
$nextPath = $theNextPath;
}
} else {
$nextPath = null;
}
}
// TODO: use our own classes here that extend DOM*
$retval = new AgaviXmlConfigDomDocument();
foreach (self::$agaviEnvelopeNamespaces as $envelopeNamespaceUri => $envelopeNamespacePrefix) {
$retval->getXpath()->registerNamespace($envelopeNamespacePrefix, $envelopeNamespaceUri);
}
if ($isAgaviConfigFormat) {
// if it is an Agavi config, we'll create a new document with all files' <configuration> blocks inside
$retval->appendChild(new AgaviXmlConfigDomElement('configurations', null, self::NAMESPACE_AGAVI_ENVELOPE_LATEST));
// reverse the array - we want the parents first!
$docs = array_reverse($docs);
$configurationElements = array();
// TODO: I bet this leaks memory due to the nodes being taken out of the docs. beware circular refs!
foreach ($docs as $doc) {
// iterate over all nodes (attributes, <sandbox>, <configuration> etc) inside the document element and append them to the <configurations> element in our final document
foreach ($doc->documentElement->childNodes as $node) {
if ($node->nodeType == XML_ELEMENT_NODE && $node->localName == 'configuration' && self::isAgaviEnvelopeNamespace($node->namespaceURI)) {
// it's a <configuration> element - put that on a stack for processing
$configurationElements[] = $node;
} else {
// import the node, recursively, and store the imported node
$importedNode = $retval->importNode($node, true);
// now append it to the <configurations> element
$retval->documentElement->appendChild($importedNode);
}
}
// if it's a <configurations> element, then we need to copy the attributes from there
if ($doc->isAgaviConfiguration()) {
$namespaces = $doc->getXPath()->query('namespace::*');
foreach ($namespaces as $namespace) {
if ($namespace->localName !== 'xml' && $namespace->localName != 'xmlns') {
$retval->documentElement->setAttributeNS(self::NAMESPACE_XMLNS_2000, 'xmlns:' . $namespace->localName, $namespace->namespaceURI);
}
}
foreach ($doc->documentElement->attributes as $attribute) {
// but not the "parent" attributes...
if ($attribute->namespaceURI === null && $attribute->localName === 'parent') {
continue;
}
$importedAttribute = $retval->importNode($attribute, true);
$retval->documentElement->setAttributeNode($importedAttribute);
}
}
}
// generic <configuration> first, then those with an environment attribute, then those with context, then those with both
$configurationOrder = array('count(self::node()[@agavi_annotations_latest:matched and not(@environment) and not(@context)])', 'count(self::node()[@agavi_annotations_latest:matched and @environment and not(@context)])', 'count(self::node()[@agavi_annotations_latest:matched and not(@environment) and @context])', 'count(self::node()[@agavi_annotations_latest:matched and @environment and @context])');
// now we sort the nodes according to the rules
foreach ($configurationOrder as $xpath) {
// append all matching nodes from the order array...
foreach ($configurationElements as &$element) {
// ... if the xpath matches, that is!
if ($element->ownerDocument->getXpath()->evaluate($xpath, $element)) {
// it did, so import the node and append it to the result doc
//.........这里部分代码省略.........
示例13: getValidatorArray
/**
* Builds an array of php code strings, each of them creating a validator
*
* @param AgaviXmlConfigDomElement The value holder of this validator.
* @param array The code of old validators (we simply
* overwrite "old" validators here).
* @param string The name of the parent container.
* @param string The severity of the parent container.
* @param string The method of the parent container.
* @param bool Whether parent container is required.
*
* @return array PHP code blocks that register the validators
*
* @author Uwe Mesecke <uwe@mesecke.net>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.11.0
*/
protected function getValidatorArray($validator, $code, $parent, $stdSeverity, $stdMethod, $stdRequired = true)
{
if (!isset($this->classMap[$validator->getAttribute('class')])) {
$class = $validator->getAttribute('class');
if (!class_exists($class)) {
throw new AgaviValidatorException('unknown validator found: ' . $class);
}
$this->classMap[$class] = array('class' => $class, 'parameters' => array());
} else {
$class = $this->classMap[$validator->getAttribute('class')]['class'];
}
// setting up parameters
$parameters = array('severity' => $validator->getAttribute('severity', $stdSeverity), 'required' => $stdRequired);
$arguments = array();
$errors = array();
$stdMethod = $validator->getAttribute('method', $stdMethod);
$stdSeverity = $parameters['severity'];
if ($validator->hasAttribute('name')) {
$name = $validator->getAttribute('name');
} else {
$name = AgaviToolkit::uniqid();
$validator->setAttribute('name', $name);
}
$parameters = array_merge($this->classMap[$validator->getAttribute('class')]['parameters'], $parameters);
$parameters = array_merge($parameters, $validator->getAttributes());
$parameters = $validator->getAgaviParameters($parameters);
foreach ($validator->get('arguments') as $argument) {
if ($argument->hasAttribute('name')) {
$arguments[$argument->getAttribute('name')] = $argument->getValue();
} else {
$arguments[] = $argument->getValue();
}
}
if ($validator->hasChild('arguments')) {
$parameters['base'] = $validator->getChild('arguments')->getAttribute('base');
if (!$arguments) {
// no arguments defined, but there is an <arguments /> element, so we're validating an array there
// lets add an empty fake argument for validation to work
// must be an empty string, not null
$arguments[] = '';
}
}
foreach ($validator->get('errors') as $error) {
if ($error->hasAttribute('for')) {
$errors[$error->getAttribute('for')] = $error->getValue();
} else {
$errors[''] = $error->getValue();
}
}
if ($validator->hasAttribute('required')) {
$stdRequired = $parameters['required'] = AgaviToolkit::literalize($validator->getAttribute('required'));
}
$methods = array('');
if (trim($stdMethod)) {
$methods = preg_split('/[\\s]+/', $stdMethod);
}
foreach ($methods as $method) {
$code[$method][$name] = implode("\n", array(sprintf('${%s} = new %s();', var_export('_validator_' . $name, true), $class), sprintf('${%s}->initialize($this->getContext(), %s, %s, %s);', var_export('_validator_' . $name, true), var_export($parameters, true), var_export($arguments, true), var_export($errors, true)), sprintf('${%s}->addChild(${%s});', var_export($parent, true), var_export('_validator_' . $name, true))));
}
// more <validator> or <validators> children
$code = $this->processValidatorElements($validator, $code, '_validator_' . $name, $stdSeverity, $stdMethod, $stdRequired);
return $code;
}
示例14: orderConfigurations
/**
* 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 <dz@bitxtender.com>
* @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;
}
示例15: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @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 David Zülke <dz@bitxtender.com>
* @since 0.11.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'caching');
$cachings = array();
foreach ($document->getConfigurationElements() as $cfg) {
if (!$cfg->has('cachings')) {
continue;
}
foreach ($cfg->get('cachings') as $caching) {
$groups = array();
if ($caching->has('groups')) {
foreach ($caching->get('groups') as $group) {
$groups[] = array('name' => $group->getValue(), 'source' => $group->getAttribute('source', 'string'), 'namespace' => $group->getAttribute('namespace'));
}
}
$actionAttributes = array();
if ($caching->has('action_attributes')) {
foreach ($caching->get('action_attributes') as $actionAttribute) {
$actionAttributes[] = $actionAttribute->getValue();
}
}
$views = null;
if ($caching->has('views')) {
$views = array();
foreach ($caching->get('views') as $view) {
if ($view->hasAttribute('module')) {
$views[] = array('module' => $view->getAttribute('module'), 'view' => $view->getValue());
} else {
$views[] = AgaviToolkit::literalize($view->getValue());
}
}
}
$outputTypes = array();
if ($caching->has('output_types')) {
foreach ($caching->get('output_types') as $outputType) {
$layers = null;
if ($outputType->has('layers')) {
$layers = array();
foreach ($outputType->get('layers') as $layer) {
$include = AgaviToolkit::literalize($layer->getAttribute('include', 'true'));
if ($layer->has('slots') && !$layer->hasAttribute('include') || !$include) {
$slots = array();
if ($layer->has('slots')) {
foreach ($layer->get('slots') as $slot) {
$slots[] = $slot->getValue();
}
}
$layers[$layer->getAttribute('name')] = $slots;
} else {
$layers[$layer->getAttribute('name')] = true;
}
}
}
$templateVariables = array();
if ($outputType->has('template_variables')) {
foreach ($outputType->get('template_variables') as $templateVariable) {
$templateVariables[] = $templateVariable->getValue();
}
}
$requestAttributes = array();
if ($outputType->has('request_attributes')) {
foreach ($outputType->get('request_attributes') as $requestAttribute) {
$requestAttributes[] = array('name' => $requestAttribute->getValue(), 'namespace' => $requestAttribute->getAttribute('namespace'));
}
}
$requestAttributeNamespaces = array();
if ($outputType->has('request_attribute_namespaces')) {
foreach ($outputType->get('request_attribute_namespaces') as $requestAttributeNamespace) {
$requestAttributeNamespaces[] = $requestAttributeNamespace->getValue();
}
}
$otnames = array_map('trim', explode(' ', $outputType->getAttribute('name', '*')));
foreach ($otnames as $otname) {
$outputTypes[$otname] = array('layers' => $layers, 'template_variables' => $templateVariables, 'request_attributes' => $requestAttributes, 'request_attribute_namespaces' => $requestAttributeNamespaces);
}
}
}
$methods = array_map('trim', explode(' ', $caching->getAttribute('method', '*')));
foreach ($methods as $method) {
if (!AgaviToolkit::literalize($caching->getAttribute('enabled', true))) {
unset($cachings[$method]);
} else {
$values = array('lifetime' => $caching->getAttribute('lifetime'), 'groups' => $groups, 'views' => $views, 'action_attributes' => $actionAttributes, 'output_types' => $outputTypes);
//.........这里部分代码省略.........