/** * Supports getBlob() and setBlob() tests. * * @see ResultSetTest::getBlob() * @see PreparedStatementTest::setBlob() * @return Blob */ public function createBlob() { // read in the file $b = new Blob(); $b->setInputFile(CREOLE_TEST_BASE . '/etc/lob/creole.png'); return $b; }
public function setThumbnail($v) { if ($v instanceof Lob && $v === $this->thumbnail) { $changed = $v->isModified(); } else { $changed = $this->thumbnail !== $v; } if ($changed) { if (!$v instanceof Lob) { $obj = new Blob(); $obj->setContents($v); } else { $obj = $v; } $this->thumbnail = $obj; $this->modifiedColumns[] = MemberPhotoPeer::THUMBNAIL; } }
public function setGzContent($v) { if ($v instanceof Lob && $v === $this->gz_content) { $changed = $v->isModified(); } else { $changed = $this->gz_content !== $v; } if ($changed) { if (!$v instanceof Lob) { $obj = new Blob(); $obj->setContents($v); } else { $obj = $v; } $this->gz_content = $obj; $this->modifiedColumns[] = nahoWikiContentPeer::GZ_CONTENT; } }
/** * Visit a Block * * @param object BlockSiteComponent $siteComponent * @return mixed * @access public * @since 6/11/08 */ public function visitBlock(BlockSiteComponent $siteComponent) { $orig = $siteComponent->getDisplayName(); $new = $this->replacePlaceholders($orig); if ($orig != $new) { $siteComponent->updateDisplayName($new); } // $orig = $siteComponent->getDescription(); // $new = $this->replacePlaceholders($orig); // if ($orig != $new) // $siteComponent->updateDescription($new); $asset = $siteComponent->getAsset(); $orig = $asset->getContent()->asString(); $new = $this->replacePlaceholders($orig); if ($orig != $new) { $asset->updateContent(Blob::withValue($new)); } }
/** * @see ResultSet::getBlob() */ public function getBlob($column) { if ($this->fetchmode == ResultSet::FETCHMODE_NUM) { $column--; } if (!isset($this->fieldsInResultSet[$column])) { throw new SQLException("Invalid resultset column: " . $column); } if ($this->fields[$column] === null) { return null; } require_once 'creole/util/Blob.php'; $b = new Blob(); $b->setContents($this->fields[$column]); return $b; }
/** * @see CallableStatement::getBlob() */ function getBlob($paramIndex) { if (!array_key_exists($paramIndex, $this->boundOutVars)) { throw new SQLException('Requesting variable not bound to output var: ' . $paramIndex); } if ($this->boundOutVars[$paramIndex] === null) { return null; } require_once 'creole/util/Blob.php'; $b = new Blob(); $b->setContents($this->boundOutVars[$paramIndex]); return $b; }
/** * @see ResultSet::getBlob() */ public function getBlob($column) { require_once 'creole/util/Blob.php'; $idx = is_int($column) ? $column - 1 : $column; if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } $data = $this->readLobData($column, ODBC_BINMODE_RETURN, $this->fields[$idx]); if (!$data) { return null; } $b = new Blob(); $b->setContents($data); return $b; }
/** * Update the asset content based on the values from the wizard * * @param array $results * @param object Asset $asset * @return void * @access public * @since 10/26/05 */ function updateAssetContent($results, $asset) { // Content try { $content = $asset->getContent(); $newContent = Blob::withValue($results); if (is_object($content) && !$content->isEqualTo($newContent)) { $asset->updateContent($newContent); } } catch (UnimplementedException $e) { $this->saveMessages[] = _("Could not content.") . " " . _("Not supported by this repository."); } catch (PermissionDeniedException $e) { $this->saveMessages[] = _("Could not content.") . " " . _("Permission denied."); } }
/** * @param string|Blob $s * @return string */ public function addQuotes($s) { if ($s instanceof MssqlBlob) { return $s->fetch(); } elseif ($s instanceof Blob) { // this shouldn't really ever be called, but it's here if needed // (and will quite possibly make the SQL error out) $blob = new MssqlBlob($s->fetch()); return $blob->fetch(); } else { if (is_bool($s)) { $s = $s ? 1 : 0; } return parent::addQuotes($s); } }
/** * @param Blob|string $s * @return string */ function addQuotes($s) { if ($s instanceof Blob) { return "x'" . bin2hex($s->fetch()) . "'"; } elseif (is_bool($s)) { return (int) $s; } elseif (strpos($s, "") !== false) { // SQLite doesn't support \0 in strings, so use the hex representation as a workaround. // This is a known limitation of SQLite's mprintf function which PDO should work around, // but doesn't. I have reported this to php.net as bug #63419: // https://bugs.php.net/bug.php?id=63419 // There was already a similar report for SQLite3::escapeString, bug #62361: // https://bugs.php.net/bug.php?id=62361 return "x'" . bin2hex($s) . "'"; } else { return $this->mConn->quote($s); } }
public function testReturnsOriginalBytesAsBinaryString() { $blob = new Blob("Hi"); $this->assertEquals("Hi", (string) $blob->toBinaryString()); }
/** * Returns Blob with contents of column value. * * @param mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used). * @return Blob New Blob with data from column. * @throws SQLException - If the column specified is not a valid key in current field array. */ public function getBlob($column) { if (is_int($column)) { $column--; } // because Java convention is to start at 1 if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); } if ($this->fields[$column] === null) { return null; } require_once 'creole/util/Blob.php'; $b = new Blob(); $b->setContents(pg_unescape_bytea($this->fields[$column])); return $b; }
/** * @see ResultSet::getBlob() */ public function getBlob($column) { $idx = is_int($column) ? $column - 1 : $column; if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } if ($this->fields[$idx] === null) { return null; } require_once 'creole/util/Blob.php'; $b = new Blob(); $b->setContents($this->fields[$idx]); return $b; }
/** * Set the persisted 'content' of this plugin. * Content is a single persisted string that can be used if the complexity of * 'dataRecords' is not needed. * * @param string $content * @return void * @access public * @since 1/13/06 */ public final function setContent($content) { $string = Blob::withValue($content); $this->_asset->updateContent($string); }
public function setFiles($v) { if ($v instanceof Lob && $v === $this->files) { $changed = $v->isModified(); } else { $changed = $this->cover !== $v; } if ($changed) { if (!$v instanceof Lob) { $obj = new Blob(); $obj->setContents($v); } else { $obj = $v; } $this->files = $obj; $this->modifiedColumns[] = CatalogCopiedPeer::FILES; } }
/** * Get any object from the repository. * * @param string $name Reference name or (partial) object hash * @return Object Immutable Object of given name. * @throws \InvalidArgumentException * @throws \OutOfBoundsException */ public function get($name) { $hash = false; if (ctype_xdigit($name)) { $hash_len = strlen($name); if ($hash_len < 4) { throw new \InvalidArgumentException('Hash must be at least 4 characters long.'); } if ($hash_len % 2) { throw new \InvalidArgumentException('Hash must be divisible by two.'); } $hash = $name; } elseif (array_key_exists($name, $this->refs)) { $hash = $this->refs[$name]; } else { throw new \InvalidArgumentException('Invalid ref: ' . $name); } $data = false; $objectPath = $this->path . '/objects/' . substr($hash, 0, 2) . '/' . substr($hash, 2); if (strlen($hash) < 40) { $hits = glob($objectPath . '*'); if (count($hits) > 0) { $data = gzuncompress(file_get_contents($hits[0])); } } elseif (file_exists($objectPath)) { $data = gzuncompress(file_get_contents($objectPath)); } if (!$data) { foreach ($this->packs as &$pack) { $data = $pack->search($hash); if ($data) { break; } } } if (!$data) { throw new \OutOfBoundsException($name); } $hash = strlen($hash) == 40 ? $hash : sha1($data); list($prefix, $body) = explode("", $data, 2); list($type, $size) = explode(' ', $prefix, 2); switch ($type) { case 'commit': return Commit::fromRaw($body, $size, $hash); case 'tag': return Tag::fromRaw($body, $size, $hash); case 'tree': return Tree::fromRaw($body, $size, $hash); case 'blob': return Blob::fromRaw($body, $size, $hash); default: throw new InvalidArgumentException($type); } }
/** * Get a blob by its id * * @param string $blobId The blob's id * * @return Blob */ public function retrieveBlob($blobId) { $response = $this->transport->request('GET', $this->baseUrl . 'blobs/' . (string) $blobId, null, array()); return Blob::fromResponse($response); }
/** * Store changes to our asset's XML document * * @return void * @access private * @since 10/5/06 */ function _saveXml() { // printpre("<hr/><h2>Saving AssetXML for ".get_class($this)." ".$this->getId().": </h2>"); // HarmoniErrorHandler::printDebugBacktrace(); // print("<h3>Previous XML</h3>"); // $oldContent = $this->_asset->getContent(); // printpre(htmlentities($oldContent->asString())); // print("<h3>New XML</h3>"); $element = $this->getElement(); // printpre(htmlentities($element->ownerDocument->saveXMLWithWhitespace())); // exit; $this->_asset->updateContent(Blob::fromString($element->ownerDocument->saveXMLWithWhitespace())); $this->clearDomCache(); }
/** * Update the asset content based on the values from the wizard * * @param array $results * @param object Asset $asset * @return void * @access public * @since 10/26/05 */ function updateAssetContent($results, $asset) { // Content if ($results['checked'] == '1') { $content = $asset->getContent(); $newContent = Blob::withValue($results['value']); if (is_object($content) && !$content->isEqualTo($newContent)) { $asset->updateContent($newContent); } } }
/** * Store changes to our asset's XML document. This asset's 'element' * is actually in its parent component, so store the parent asset's xml. * * @return void * @access private * @since 10/5/06 */ function _saveXml() { // printpre("<hr/><h2>Saving Parent AssetXML for ".get_class($this)." ".$this->getId().": </h2>"); // print("<h3>Previous XML</h3>"); $parentComponent = $this->getParentComponent(); $parentAsset = $parentComponent->getAsset(); // $oldContent = $parentAsset->getContent(); // printpre(htmlentities($oldContent->asString())); // print("<h3>New XML</h3>"); $element = $this->getElement(); // printpre(htmlentities($element->ownerDocument->saveXMLWithWhitespace())); // exit; $parentAsset->updateContent(Blob::fromString($element->ownerDocument->saveXMLWithWhitespace())); }
/** * @param Blob|string $s * @return string */ function addQuotes($s) { if ($s instanceof Blob) { return "x'" . bin2hex($s->fetch()) . "'"; } elseif (is_bool($s)) { return (int) $s; } elseif (strpos($s, "") !== false) { // SQLite doesn't support \0 in strings, so use the hex representation as a workaround. // This is a known limitation of SQLite's mprintf function which PDO should work around, // but doesn't. I have reported this to php.net as bug #63419: // https://bugs.php.net/bug.php?id=63419 // There was already a similar report for SQLite3::escapeString, bug #62361: // https://bugs.php.net/bug.php?id=62361 // There is an additional bug regarding sorting this data after insert // on older versions of sqlite shipped with ubuntu 12.04 // https://bugzilla.wikimedia.org/show_bug.cgi?id=72367 wfDebugLog(__CLASS__, __FUNCTION__ . ': Quoting value containing null byte. For consistency all binary data should have been first processed with self::encodeBlob()'); return "x'" . bin2hex($s) . "'"; } else { return $this->mConn->quote($s); } }
/** * Performs sqlite_udf_decode_binary on binary data. * @see ResultSet::getBlob() */ public function getBlob($column) { $idx = is_int($column) ? $column - 1 : $column; if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } if ($this->fields[$idx] === null) { return null; } require_once CREOLE_ROOT . 'util/Blob.php'; $b = new Blob(); $b->setContents(sqlite_udf_decode_binary($this->fields[$idx])); return $b; }
/** * @param string $paramIndex * @param mixed $blob Blob object or string containing data. * @return void */ function setBlob($paramIndex, $blob) { require_once CREOLE_ROOT . 'util/Blob.php'; if (!$blob instanceof Blob) { $b = new Blob(); $b->setContents($blob); $blob = $b; } $this->lobDescriptors[$paramIndex] = oci_new_descriptor($this->conn->getResource(), OCI_D_LOB); $this->lobs[$paramIndex] = $blob; }
/** * Convert this object to a StorableBlob * * @return object * @access public * @since 6/9/06 */ function asABlob() { return Blob::fromString($this->asString()); }
/** * Set the value of [text] column. * * @param string $v new value * @return void */ public function setText($v) { // if the passed in parameter is the *same* object that // is stored internally then we use the Lob->isModified() // method to know whether contents changed. if ($v instanceof Lob && $v === $this->text) { $changed = $v->isModified(); } else { $changed = $this->text !== $v; } if ($changed) { if (!$v instanceof Lob) { $obj = new Blob(); $obj->setContents($v); } else { $obj = $v; } $this->text = $obj; $this->modifiedColumns[] = ImportErrorPeer::TEXT; } }
/** * Save our results. Tearing down and unsetting the Wizard is handled by * in {@link runWizard()} and does not need to be implemented here. * * @param string $cacheName * @return boolean TRUE if save was successful and tear-down/cleanup of the * Wizard should ensue. * @access public * @since 4/28/05 */ function saveWizard($cacheName) { $wizard = $this->getWizard($cacheName); if (!$wizard->validate()) { return false; } // Make sure we have a valid Repository $idManager = Services::getService("Id"); $authZ = Services::getService("AuthZ"); $repository = $this->getRepository(); $properties = $wizard->getAllValues(); if (isset($properties['parentstep']['parent']) && $properties['parentstep']['parent'] && $properties['parentstep']['parent'] != 'NONE') { $parentId = $idManager->getId($properties['parentstep']['parent']); $authorizedToAddToParent = $authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $parentId); } // First, verify that we chose a parent that we can add children to. if (!$properties['parentstep']['parent'] || $properties['parentstep']['parent'] == 'NONE' || isset($parentId) && $authorizedToAddToParent) { // Get the type from the select if one is specified if (is_string($properties['typestep']['type'])) { $typeString = urldecode($properties['typestep']['type']); $assetType = HarmoniType::fromString($typeString); } else { if (is_array($properties['typestep']['type']) && $properties['typestep']['type']['type_domain'] && $properties['typestep']['type']['type_authority'] && $properties['typestep']['type']['type_keyword']) { $domain = $properties['typestep']['type']['type_domain']; $authority = $properties['typestep']['type']['type_authority']; $keyword = $properties['typestep']['type']['type_keyword']; $description = $properties['typestep']['type']['type_description']; if (!($domain && $authority && $keyword)) { $wizard->setStep("typestep"); return false; } $assetType = new Type($domain, $authority, $keyword, $description); } else { $assetType = new Type("Asset Types", "edu.middlebury", "Generic Asset", "This is an <em>Asset</em> of unspecified type."); } } $asset = $repository->createAsset($properties['namedescstep']['display_name'], $properties['namedescstep']['description'], $assetType); $assetId = $asset->getId(); $this->_assetId = $assetId; if (isset($properties['contentstep']['content'])) { $content = Blob::withValue($properties['contentstep']['content']); try { $asset->updateContent($content); } catch (UnimplementedException $e) { $this->saveMessages[] = _("Could set Asset content.") . " " . _("Not supported by this repository."); } } // Update the effective/expiration dates // if ($properties['datestep']['effective_date']) // $asset->updateEffectiveDate( // DateAndTime::fromString($properties['datestep']['effective_date'])); // if ($properties['datestep']['expiration_date']) // $asset->updateExpirationDate( // DateAndTime::fromString($properties['datestep']['expiration_date'])); // Add our parent if we have specified one. if ($properties['parentstep']['parent'] && $properties['parentstep']['parent'] != 'NONE') { $parentId = $idManager->getId($properties['parentstep']['parent']); $parentAsset = $repository->getAsset($parentId); $parentAsset->addAsset($assetId); } // Log the success or failure if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Concerto"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events."); $item = new AgentNodeEntryItem("Create Node", "Asset added"); $item->addNodeId($assetId); $item->addNodeId($repository->getId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } return TRUE; } else { $wizard->setStep("parentstep"); return FALSE; } }