/**
  * Returns the attribute value for a given array/object.
  *
  * @param mixed  $object            The object or array from where to get the item
  * @param mixed  $item              The item to get from the array or object
  * @param array  $arguments         An array of arguments to pass if the item is an object method
  * @param string $type              The type of attribute (@see \Twig_Template constants)
  * @param bool   $isDefinedTest     Whether this is only a defined check
  * @param bool   $ignoreStrictCheck Whether to ignore the strict attribute check or not
  *
  * @throws \Twig_Error_Runtime If the attribute does not exist and Twig is running in strict mode and $isDefinedTest
  *                             is false
  * @return mixed               The attribute value, or a bool when $isDefinedTest is true, or null when the
  *                             attribute is not set and $ignoreStrictCheck is true
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
 {
     if (is_object($object) && $object instanceof BaseElementModel) {
         $this->_includeElementInTemplateCaches($object);
     }
     return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
 }
 /**
  * @param         $object
  * @param         $item
  * @param  array  $arguments
  * @param  string $type
  * @param  bool   $isDefinedTest
  *
  * @return mixed
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false)
 {
     $attribute = parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest);
     if (self::$recorder && is_object($object)) {
         self::$recorder->add($object);
     }
     return $attribute;
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 protected function getAttribute($object, $item, array $arguments = [], $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
 {
     // Twig uses isset() to check if attribute exists which does not work when attribute exists but is null
     if ($object instanceof \yii\db\BaseActiveRecord) {
         if ($type === \Twig_Template::METHOD_CALL) {
             return $object->{$item}($arguments);
         } else {
             return $object->{$item};
         }
     }
     return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
 }
Beispiel #4
0
 /**
  * Override the getAttribute to handle lazy loaded li3 helpers
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $line = -1)
 {
     $result = parent::getAttribute($object, $item, $arguments, $type, $noStrictCheck, $line);
     if (is_null($result)) {
         // Fetch the helper object and return it
         try {
             $result = is_object($object) ? $object->helper($item) : null;
         } catch (\Exception $e) {
             $result = null;
         }
     }
     return $result;
 }
Beispiel #5
0
 /**
  * Override the getAttribute to handle lazy loaded li3 helpers
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $line = -1)
 {
     $result = parent::getAttribute($object, $item, $arguments, $type, $noStrictCheck, $line);
     if ($result === null) {
         // Fetch the helper object and return it
         try {
             if (preg_match('|Model|', get_parent_class($object)) || preg_match('|Model|', get_parent_class(get_parent_class($object)))) {
                 return $object->{$item};
             } else {
                 $result = is_object($object) ? $object->helper($item) : null;
             }
         } catch (\Exception $e) {
             $result = null;
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * @inheritdoc
  */
 protected function getAttribute($object, $item, array $arguments = [], $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
 {
     // Twig uses isset() to check if attribute exists which does not work when attribute exists but is null
     if ($object instanceof \yii\base\Model) {
         if ($type === \Twig_Template::METHOD_CALL) {
             if ($this->env->hasExtension('sandbox')) {
                 $this->env->getExtension('sandbox')->checkMethodAllowed($object, $item);
             }
             return call_user_func_array([$object, $item], $arguments);
         } else {
             if ($this->env->hasExtension('sandbox')) {
                 $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
             }
             return $object->{$item};
         }
     }
     return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
 }
Beispiel #7
0
 /** 
  * {@inheritdoc}
  * 
  * Additianally, currycms automatically wraps ModelCriteria-objects in
  * Curry_Twig_QueryWrapper objects, and automatically calls the toTwig()
  * function if it exists.
  * 
  * @see Curry_Twig_QueryWrapper
  */
 protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $line = -1)
 {
     if (is_object($object) && method_exists($object, '__get') && isset($object->{$item})) {
         $attr = $object->{$item};
     } else {
         $attr = parent::getAttribute($object, $item, $arguments, $type, $noStrictCheck, $line);
     }
     while (is_object($attr)) {
         if (method_exists($attr, 'toTwig')) {
             $attr = $attr->toTwig();
         } else {
             if ($attr instanceof \ModelCriteria) {
                 $attr = new \Curry_Twig_QueryWrapper($attr);
             } else {
                 break;
             }
         }
     }
     return $attr;
 }
Beispiel #8
0
 public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
 {
     if ($this->useExtGetAttribute) {
         return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
     } else {
         return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
     }
 }
Beispiel #9
0
 public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY, $noStrictCheck = false, $lineno = -1)
 {
     return parent::getAttribute($object, $item, $arguments, $type);
 }
 public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false)
 {
     return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest);
 }
 public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY)
 {
     return parent::getAttribute($object, $item, $arguments, $type);
 }
 public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $lineno = -1)
 {
     return parent::getAttribute($object, $item, $arguments, $type);
 }