コード例 #1
0
ファイル: FileVehicle.php プロジェクト: exside/teleport
 /**
  * Put a representation of a MySQL table and it's data into this vehicle.
  *
  * @param \xPDOTransport $transport The transport package hosting the vehicle.
  * @param mixed          &$object A reference to the artifact this vehicle will represent.
  * @param array          $attributes Additional attributes represented in the vehicle.
  */
 public function put(&$transport, &$object, $attributes = array())
 {
     if (!isset($this->payload['class'])) {
         $this->payload['class'] = $this->class;
     }
     if (!isset($object['in']) || !isset($object['target'])) {
         $transport->xpdo->log(\xPDO::LOG_LEVEL_ERROR, "Processing FileVehicle failed. You have to specify all required Object parameters: in, target");
         $object = null;
         $this->payload['object'] = $object;
     } else {
         $finder = new Finder();
         $finder->in($object['in']);
         foreach ($object as $method => $data) {
             if (in_array($method, $this->skipObjectParams)) {
                 continue;
             }
             if (method_exists($finder, $method)) {
                 if (is_array($data)) {
                     foreach ($data as $param) {
                         $finder->{$method}($param);
                     }
                 } else {
                     $finder->{$method}($data);
                 }
             }
         }
         $object['files'] = iterator_to_array($finder);
         $this->payload['object'] = $object;
     }
     \xPDOVehicle::put($transport, $object, $attributes);
 }
コード例 #2
0
ファイル: MySQLVehicle.php プロジェクト: exside/teleport
 /**
  * Put a representation of a MySQL table and it's data into this vehicle.
  *
  * @param \xPDOTransport $transport The transport package hosting the vehicle.
  * @param mixed          &$object A reference to the artifact this vehicle will represent.
  * @param array          $attributes Additional attributes represented in the vehicle.
  */
 public function put(&$transport, &$object, $attributes = array())
 {
     $this->payload['class'] = $this->class;
     if (is_array($object) && isset($object['table']) && isset($object['tableName'])) {
         $this->payload['object'] = $object;
     }
     parent::put($transport, $object, $attributes);
 }
コード例 #3
0
 /**
  * Put an xPDOObject representation into a transport package.
  *
  * This implementation supports the inclusion of related objects. Simply instantiate the related
  * objects that you want to include in the vehicle on the main object, and set
  * xPDOTransport::RELATED_OBJECTS => true in your attributes.
  */
 public function put(&$transport, &$object, $attributes = array())
 {
     parent::put($transport, $object, $attributes);
     if (is_object($object)) {
         if (!isset($this->payload['package'])) {
             if ($object instanceof xPDOObject) {
                 $packageName = $object->_package;
             } else {
                 $packageName = '';
             }
             $this->payload['package'] = $packageName;
         }
         if ($object instanceof xPDOObject) {
             $nativeKey = $object->getPrimaryKey();
             $this->payload['object'] = $object->toJSON('', true);
             $this->payload['native_key'] = $nativeKey;
             $this->payload['signature'] = md5($this->payload['class'] . '_' . $this->payload['guid']);
             if (isset($this->payload[xPDOTransport::RELATED_OBJECTS]) && !empty($this->payload[xPDOTransport::RELATED_OBJECTS])) {
                 $relatedObjects = array();
                 foreach ($object->_relatedObjects as $rAlias => $related) {
                     if (is_array($related)) {
                         foreach ($related as $rKey => $rObj) {
                             if (!isset($relatedObjects[$rAlias])) {
                                 $relatedObjects[$rAlias] = array();
                             }
                             $guid = md5(uniqid(rand(), true));
                             $relatedObjects[$rAlias][$guid] = array();
                             $this->_putRelated($transport, $rAlias, $rObj, $relatedObjects[$rAlias][$guid]);
                         }
                     } elseif (is_object($related)) {
                         if (!isset($relatedObjects[$rAlias])) {
                             $relatedObjects[$rAlias] = array();
                         }
                         $guid = md5(uniqid(rand(), true));
                         $relatedObjects[$rAlias][$guid] = array();
                         $this->_putRelated($transport, $rAlias, $related, $relatedObjects[$rAlias][$guid]);
                     }
                 }
                 if (!empty($relatedObjects)) {
                     $this->payload['related_objects'] = $relatedObjects;
                 }
             }
         } elseif (is_object($object)) {
             $this->payload['object'] = $transport->xpdo->toJSON(get_object_vars($object));
             $this->payload['native_key'] = $this->payload['guid'];
             $this->payload['signature'] = md5($this->payload['class'] . '_' . $this->payload['guid']);
         }
     }
 }
コード例 #4
0
 /**
  * Adds the file definition object to the payload.
  */
 public function put(&$transport, &$object, $attributes = array())
 {
     if (!isset($this->payload['class'])) {
         $this->payload['class'] = 'xPDOFileVehicle';
     }
     if (is_array($object) && isset($object['source']) && isset($object['target'])) {
         if (!isset($object['name'])) {
             $object['name'] = basename($object['source']);
         }
         $this->payload['object'] = $object;
     }
     parent::put($transport, $object, $attributes);
 }
コード例 #5
0
 /**
  * Adds the file definition object to the payload.
  */
 public function put(&$transport, &$object, $attributes = array())
 {
     if (!isset($this->payload['class'])) {
         $this->payload['class'] = 'xPDOScriptVehicle';
     }
     if (is_array($object) && isset($object['source'])) {
         $this->payload['object'] = $object;
     }
     parent::put($transport, $object, $attributes);
 }