Ejemplo n.º 1
0
 public function __get($propertyName)
 {
     if (!$this->defaultsSet) {
         $this->setDefaultValues();
     }
     // Should any type of magical getter below require that the value is cached for performance
     // this boolean will be set to true. At the end of the function we pick up on this and do the
     // caching - instead of having the caching line repeated all over the place.
     $addToPropertyCache = false;
     $value = parent::__get($propertyName);
     if ($value === null) {
         if (isset($this->propertyCache[$propertyName])) {
             return $this->propertyCache[$propertyName];
         }
         // Handle the dot operator by passing control to the next object in the chain.
         if (strpos($propertyName, ".") !== false) {
             $parts = explode(".", $propertyName, 2);
             $firstStep = $this[$parts[0]];
             if ($firstStep === null || !$firstStep instanceof Model) {
                 // If the next item in the chain is not model object we can't ask it to return
                 // a value can we!
                 return null;
             }
             return $firstStep[$parts[1]];
         }
         $this->ensureRelationshipsArePopulated();
         if (isset(self::$relationships[$this->modelName][$propertyName])) {
             $relationship = self::$relationships[$this->modelName][$propertyName];
             $value = $relationship->fetchFor($this);
             if ($value instanceof Model) {
                 $addToPropertyCache = true;
             }
         }
     }
     if ($addToPropertyCache) {
         $this->propertyCache[$propertyName] = $value;
     }
     if (isset(self::$modelDataTransforms[$this->modelName][$propertyName][0])) {
         $closure = self::$modelDataTransforms[$this->modelName][$propertyName][0];
         $value = $closure($value);
     }
     return $value;
 }
Ejemplo n.º 2
0
 /**
  * Attaches a change listener to the model state item and raises a property changed notification when that happens.
  *
  * @param $propertyName
  * @param ModelState $item
  */
 private function attachChangeListenerToModelProperty($propertyName, ModelState $item)
 {
     $item->clearEventHandlers();
     $item->attachEventHandler("AfterChange", function () use($propertyName, $item) {
         $this->raisePropertyChangedCallbacks($propertyName, $item, null);
     });
 }
Ejemplo n.º 3
0
 protected function getExportedPropertyList()
 {
     $list = parent::getExportedPropertyList();
     $list[] = "MyTestValue";
     return $list;
 }