Exemplo n.º 1
0
 public function getObject($primary_key_value)
 {
     $m2o_object_name = $this->object_name;
     $object = ObjectLoader::get($m2o_object_name);
     $object->sync($primary_key_value);
     return $object;
 }
Exemplo n.º 2
0
 public function generateQuerySet(QuerySet $query_set, $field_name)
 {
     $object_name = $this->object_name;
     // Load objects
     $object = ObjectLoader::get($object_name);
     // Handle One2Many
     return $object::all()->associate($this->foreign_key, $query_set, $field_name);
 }
Exemplo n.º 3
0
 public function __get($attribute_name)
 {
     if (!isset($this->map[$attribute_name])) {
         throw new \Exception('No mapping defined in collection ' . get_class() . ' for attribute ' . $attribute_name . '!');
     }
     if (!isset($this->_instances[$attribute_name])) {
         if (is_string($this->map[$attribute_name])) {
             $this->_instances[$attribute_name] = ObjectLoader::get($this->map[$attribute_name]);
         } else {
             $this->_instances[$attribute_name] = $this->map[$attribute_name];
         }
     }
     return $this->_instances[$attribute_name];
 }
Exemplo n.º 4
0
 protected function parameterInjection($type, $name, $required, $args)
 {
     $request = \Biome\Biome::getService('request');
     $value = NULL;
     if (empty($type)) {
         return $args[$name];
     }
     switch ($type) {
         // Default PHP type
         case 'string':
         case 'int':
             return $value;
             break;
         default:
             // Class injection
     }
     /**
      * Collection injection
      */
     if (substr($type, -strlen('Collection')) == 'Collection') {
         // Instanciate the collection
         $collection_name = strtolower(substr($type, 0, -strlen('Collection')));
         $value = Collection::get($collection_name);
         // Check if data are sent
         foreach ($request->request->keys() as $key) {
             if (strncmp($collection_name . '/', $key, strlen($collection_name . '/')) == 0) {
                 $raw = explode('/', $key);
                 $total = count($raw);
                 $iter = $value;
                 for ($i = 1; $i < $total - 1; $i++) {
                     $iter = $iter->{$raw[$i]};
                 }
                 $v = $request->request->get($key);
                 $iter->{$raw[$i]} = $v;
             }
         }
     } else {
         $object_name = strtolower($type);
         $value = ObjectLoader::get($object_name);
         // Check if data are sent
         foreach ($request->request->keys() as $key) {
             if (strncmp($object_name . '/', $key, strlen($object_name . '/')) == 0) {
                 $raw = explode('/', $key);
                 $total = count($raw);
                 $iter = $value;
                 for ($i = 1; $i < $total - 1; $i++) {
                     $iter = $iter->{$raw[$i]};
                 }
                 $v = $request->request->get($key);
                 $iter->{$raw[$i]} = $v;
             }
         }
     }
     return $value;
 }
Exemplo n.º 5
0
 public function getDestinationObject()
 {
     return $this->object = ObjectLoader::get($this->object_name);
 }
Exemplo n.º 6
0
 /**
  * From the longest to the smallest.
  */
 protected function rec_fetchValue($var, &$inner_context = 'global')
 {
     $ctx = NULL;
     $result = $this->getContext($var, $ctx);
     if ($result !== NULL) {
         return $result;
     }
     /* Remove one item, save the name of the last one. */
     $raw = explode('.', $var);
     if (count($raw) > 1) {
         $end = array_pop($raw);
         $result = $this->rec_fetchValue(join('.', $raw), $ctx);
         /* We find the preceding item, fetch the next. */
         if (method_exists($result, 'get' . $end)) {
             $end = 'get' . $end;
             $result = $result->{$end}();
         } else {
             if (method_exists($result, $end)) {
                 $result = $result->{$end}();
             } else {
                 if (is_array($result) && isset($result[$end])) {
                     $result = $result[$end];
                 } else {
                     $result = $result->{$end};
                 }
             }
         }
         $this->setContext($var, $result, $ctx);
         return $result;
     }
     /* No item found, check view. */
     $view = \Biome\Biome::getService('view');
     $result = $view->{$raw[0]};
     if ($result !== NULL) {
         return $result;
     }
     /* No item found, check collections. */
     $result = Collection::get($raw[0]);
     if ($result !== NULL) {
         return $result;
     }
     /* No item found, check objects. */
     $result = ObjectLoader::get($raw[0]);
     if ($result !== NULL) {
         return $result;
     }
     throw new \Exception('Unable to find the variable ' . $var . ' in the context!');
 }