Project

General

Profile

« Previous | Next » 

Revision 1938

Added by darkviper almost 11 years ago

update Twig template engine to version 1.13.1

View differences:

Template.php
13 13
/**
14 14
 * Default base class for compiled templates.
15 15
 *
16
 * @package twig
17
 * @author  Fabien Potencier <fabien@symfony.com>
16
 * @author Fabien Potencier <fabien@symfony.com>
18 17
 */
19 18
abstract class Twig_Template implements Twig_TemplateInterface
20 19
{
......
337 336
     */
338 337
    protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
339 338
    {
340
        $item = ctype_digit((string) $item) ? (int) $item : (string) $item;
341

  
342 339
        // array
343 340
        if (Twig_TemplateInterface::METHOD_CALL !== $type) {
344
            if ((is_array($object) && array_key_exists($item, $object))
345
                || ($object instanceof ArrayAccess && isset($object[$item]))
341
            $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
342

  
343
            if ((is_array($object) && array_key_exists($arrayItem, $object))
344
                || ($object instanceof ArrayAccess && isset($object[$arrayItem]))
346 345
            ) {
347 346
                if ($isDefinedTest) {
348 347
                    return true;
349 348
                }
350 349

  
351
                return $object[$item];
350
                return $object[$arrayItem];
352 351
            }
353 352

  
354
            if (Twig_TemplateInterface::ARRAY_CALL === $type) {
353
            if (Twig_TemplateInterface::ARRAY_CALL === $type || !is_object($object)) {
355 354
                if ($isDefinedTest) {
356 355
                    return false;
357 356
                }
......
361 360
                }
362 361

  
363 362
                if (is_object($object)) {
364
                    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());
363
                    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());
365 364
                } elseif (is_array($object)) {
366
                    throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), -1, $this->getTemplateName());
365
                    throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName());
366
                } elseif (Twig_TemplateInterface::ARRAY_CALL === $type) {
367
                    throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
367 368
                } else {
368
                    throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object)), -1, $this->getTemplateName());
369
                    throw new Twig_Error_Runtime(sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
369 370
                }
370 371
            }
371 372
        }
......
379 380
                return null;
380 381
            }
381 382

  
382
            throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, is_array($object) ? 'Array' : $object), -1, $this->getTemplateName());
383
            throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
383 384
        }
384 385

  
385 386
        $class = get_class($object);
386 387

  
387 388
        // object property
388 389
        if (Twig_TemplateInterface::METHOD_CALL !== $type) {
389
            if (isset($object->$item) || array_key_exists($item, $object)) {
390
            if (isset($object->$item) || array_key_exists((string) $item, $object)) {
390 391
                if ($isDefinedTest) {
391 392
                    return true;
392 393
                }
......
406 407

  
407 408
        $lcItem = strtolower($item);
408 409
        if (isset(self::$cache[$class]['methods'][$lcItem])) {
409
            $method = $item;
410
            $method = (string) $item;
410 411
        } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
411 412
            $method = 'get'.$item;
412 413
        } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
413 414
            $method = 'is'.$item;
414 415
        } elseif (isset(self::$cache[$class]['methods']['__call'])) {
415
            $method = $item;
416
            $method = (string) $item;
416 417
        } else {
417 418
            if ($isDefinedTest) {
418 419
                return false;

Also available in: Unified diff