/** * 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); }
/** * Copies the files into the vehicle and transforms the payload for storage. */ protected function _compilePayload(&$transport) { \xPDOVehicle::_compilePayload($transport); if (isset($this->payload['object']['in']) && isset($this->payload['object']['target'])) { $fs = new Filesystem(); $rootFolder = explode('/', $this->payload['object']['in']); $rootFolder = array_pop($rootFolder); $this->payload['object']['name'] = $rootFolder; $this->payload['object']['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature']; $filePath = $transport->path . $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/' . $rootFolder; $fs->mkdir($filePath); /** @var SplFileInfo $file */ foreach ($this->payload['object']['files'] as $file) { if ($file->isDir()) { $fs->mkdir($filePath . '/' . $file->getRelativePathname()); } else { $fs->copy($file->getRealpath(), $filePath . '/' . $file->getRelativePathname()); } } unset($this->payload['object']['files']); } }
/** * 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']); } } }
/** * Copies the files into the vehicle and transforms the payload for storage. */ protected function _compilePayload(&$transport) { parent::_compilePayload($transport); $body = array(); $cacheManager = $transport->xpdo->getCacheManager(); if ($cacheManager) { if (isset($this->payload['object'])) { $object = $this->payload['object']; $fileSource = $object['source']; $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/'; $fileTarget = $transport->path . $body['source']; $body['target'] = $object['target']; $fileName = isset($object['name']) ? $object['name'] : basename($fileSource); $body['name'] = $fileName; if (!is_writable($fileTarget)) { $cacheManager->writeTree($fileTarget); } if (file_exists($fileSource) && is_writable($fileTarget)) { $copied = false; if (is_dir($fileSource)) { $copied = $cacheManager->copyTree($fileSource, $fileTarget . $fileName); } elseif (is_file($fileSource)) { $copied = $cacheManager->copyFile($fileSource, $fileTarget . $fileName); } if (!$copied) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy file from {$fileSource} to {$fileTarget}{$fileName}"); $body = null; } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} is not writable"); $body = null; } } } if (!empty($body)) { $this->payload['object'] = $body; } }
/** * Put an xPDOTransport representation into a transport package. */ public function put(&$transport, &$object, $attributes = array()) { if (!isset($this->payload['class'])) { $this->payload['class'] = 'xPDOTransportVehicle'; } 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); }
/** * Copies the files into the vehicle and transforms the payload for storage. */ protected function _compilePayload(&$transport) { parent::_compilePayload($transport); $body = array(); $cacheManager = $transport->xpdo->getCacheManager(); if ($cacheManager) { if (isset($this->payload['object'])) { $object = $this->payload['object']; $fileSource = $object['source']; $scriptName = basename($fileSource, '.php'); $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.script'; $fileTarget = $transport->path . $body['source']; $body = array_merge($object, $body); if (!$cacheManager->copyFile($fileSource, $fileTarget)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written"); $body = null; } } } if (!empty($body)) { $this->payload['object'] = $body; } }