mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 07:37:43 +00:00
[ext] updated PHP code documenting C code
This commit is contained in:
+34
-22
@@ -781,14 +781,16 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
/*
|
||||
// array
|
||||
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
||||
if ((is_array($object) && array_key_exists($item, $object))
|
||||
|| ($object instanceof ArrayAccess && isset($object[$item]))
|
||||
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
||||
|
||||
if ((is_array($object) && array_key_exists($arrayItem, $object))
|
||||
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
|
||||
) {
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $object[$item];
|
||||
return $object[$arrayItem];
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -832,11 +834,13 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
}
|
||||
/*
|
||||
if (is_object($object)) {
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $arrayItem, get_class($object)), -1, $this->getTemplateName());
|
||||
} elseif (is_array($object)) {
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), -1, $this->getTemplateName());
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName());
|
||||
} elseif (Twig_TemplateInterface::ARRAY_CALL === $type) {
|
||||
throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
|
||||
} else {
|
||||
throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object)), -1, $this->getTemplateName());
|
||||
throw new Twig_Error_Runtime(sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,7 +875,7 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
||||
return null;
|
||||
}
|
||||
throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, implode(', ', array_keys($object))));
|
||||
throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
|
||||
}
|
||||
*/
|
||||
if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) {
|
||||
@@ -896,19 +900,19 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// get some information about the object
|
||||
$class = get_class($object);
|
||||
if (!isset(self::$cache[$class])) {
|
||||
$r = new ReflectionClass($class);
|
||||
self::$cache[$class] = array('methods' => array(), 'properties' => array());
|
||||
foreach ($r->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
||||
self::$cache[$class]['methods'][strtolower($method->getName())] = true;
|
||||
if (!is_object($object)) {
|
||||
if ($isDefinedTest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($r->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
self::$cache[$class]['properties'][$property->getName()] = true;
|
||||
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
|
||||
}
|
||||
|
||||
$class = get_class($object);
|
||||
*/
|
||||
if (Z_TYPE_P(object) == IS_OBJECT) {
|
||||
char *class_name = NULL;
|
||||
@@ -925,12 +929,11 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
/*
|
||||
// object property
|
||||
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
||||
if (isset(self::$cache[$class]['properties'][$item])
|
||||
|| isset($object->$item) || array_key_exists($item, $object)
|
||||
) {
|
||||
if (isset($object->$item) || array_key_exists((string) $item, $object)) {
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->env->hasExtension('sandbox')) {
|
||||
$this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
|
||||
}
|
||||
@@ -967,15 +970,19 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
}
|
||||
/*
|
||||
// object method
|
||||
if (!isset(self::$cache[$class]['methods'])) {
|
||||
self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object)));
|
||||
}
|
||||
|
||||
$lcItem = strtolower($item);
|
||||
if (isset(self::$cache[$class]['methods'][$lcItem])) {
|
||||
$method = $item;
|
||||
$method = (string) $item;
|
||||
} elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
|
||||
$method = 'get'.$item;
|
||||
} elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
|
||||
$method = 'is'.$item;
|
||||
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
|
||||
$method = $item;
|
||||
$method = (string) $item;
|
||||
*/
|
||||
{
|
||||
char *lcItem = TWIG_STRTOLOWER(item, item_len);
|
||||
@@ -1011,11 +1018,14 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
if ($isDefinedTest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
||||
return null;
|
||||
}
|
||||
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)));
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
|
||||
}
|
||||
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
}
|
||||
@@ -1067,6 +1077,8 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
efree(lcItem);
|
||||
}
|
||||
/*
|
||||
// useful when calling a template method from a template
|
||||
// this is not supported but unfortunately heavily used in the Symfony profiler
|
||||
if ($object instanceof Twig_TemplateInterface) {
|
||||
return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user