/** * Get the properties on this source * @param boolean $parsed * @return array */ public function getProperties($parsed = false) { $properties = $this->get('properties'); $defaultProperties = $this->getDefaultProperties(); if (!empty($properties) && is_array($properties)) { foreach ($properties as &$property) { $property['overridden'] = 0; if (array_key_exists($property['name'], $defaultProperties)) { if ($defaultProperties[$property['name']]['value'] != $property['value']) { $property['overridden'] = 1; } } else { $property['overridden'] = 2; } } $properties = array_merge($defaultProperties, $properties); } else { $properties = $defaultProperties; } /** @var array $results Allow manipulation of media source properties via event */ $results = $this->xpdo->invokeEvent('OnMediaSourceGetProperties', array('properties' => $this->xpdo->toJSON($properties))); if (!empty($results)) { foreach ($results as $result) { $result = is_array($result) ? $result : $this->xpdo->fromJSON($result); $properties = array_merge($properties, $result); } } if ($parsed) { $properties = $this->parseProperties($properties); } return $this->prepareProperties($properties); }
/** * Set a raw value on a field converted to the appropriate type. * * @access protected * @param string $key The key identifying the field to set. * @param mixed $val The value to set. * @return boolean Returns true if the value was set, false otherwise. */ protected function _setRaw($key, $val) { $set = false; if ($val === null) { $this->_fields[$key] = null; $set = true; } else { $phptype = $this->_getPHPType($key); $dbtype = $this->_getDataType($key); switch ($phptype) { case 'int': case 'integer': case 'boolean': $this->_fields[$key] = (int) $val; $set = true; break; case 'float': $this->_fields[$key] = (double) $val; $set = true; break; case 'array': if (is_array($val)) { $this->_fields[$key] = serialize($val); $set = true; } elseif (is_string($val)) { $this->_fields[$key] = $val; $set = true; } elseif (is_object($val) && $val instanceof xPDOObject) { $this->_fields[$key] = serialize($val->toArray()); $set = true; } break; case 'json': if (!is_string($val)) { $v = $val; if (is_array($v)) { $this->_fields[$key] = $this->xpdo->toJSON($v); $set = true; } elseif (is_object($v) && $v instanceof xPDOObject) { $this->_fields[$key] = $this->xpdo->toJSON($v->toArray()); $set = true; } } else { $this->_fields[$key] = $val; $set = true; } break; case 'date': case 'datetime': case 'timestamp': if (preg_match('/int/i', $dbtype)) { $this->_fields[$key] = (int) $val; $set = true; break; } default: $this->_fields[$key] = $val; $set = true; } } if ($set) { $this->setDirty($key); } return $set; }
/** * Compile necessary resources in preparation for storing the vehicle. * * @access protected * @param xPDOTransport &$transport A reference to the transport the vehicle is being stored in. */ protected function _compilePayload(&$transport) { $cacheManager = $transport->xpdo->getCacheManager(); if ($cacheManager) { if (isset($this->payload['resolve']) && is_array($this->payload['resolve'])) { foreach ($this->payload['resolve'] as $rKey => $r) { $type = $r['type']; $body = array(); switch ($type) { case 'file': $fileSource = $r['source']; $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/' . $rKey . '/'; $fileTarget = $transport->path . $body['source']; $body['target'] = $r['target']; $fileName = isset($r['name']) ? $r['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; } break; case 'php': $fileSource = $r['source']; $scriptName = basename($fileSource, '.php'); $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.resolver'; $fileTarget = $transport->path . $body['source']; $body['name'] = $scriptName; $body = array_merge($r, $body); if (!$cacheManager->copyFile($fileSource, $fileTarget)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written"); } break; default: $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support resolvers of type {$type}."); break; } if ($body) { $this->payload['resolve'][$rKey] = array('type' => $type, 'body' => xPDO::toJSON($body)); } else { $this->payload['resolve'][$rKey] = null; } } } if (isset($this->payload['validate']) && is_array($this->payload['validate'])) { foreach ($this->payload['validate'] as $vKey => $v) { $type = $r['type']; $body = array(); switch ($type) { case 'php': $fileSource = $r['source']; $scriptName = basename($fileSource, '.php'); $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.validator'; $fileTarget = $transport->path . $body['source']; $body['name'] = $scriptName; $body = array_merge($r, $body); if (!$cacheManager->copyFile($fileSource, $fileTarget)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written"); } break; default: $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support validators of type {$type}."); break; } if ($body) { $this->payload['validate'][$vKey] = array('type' => $type, 'body' => xPDO::toJSON($body)); } else { $this->payload['validate'][$vKey] = null; } } } } }