本文整理汇总了PHP中Transform类的典型用法代码示例。如果您正苦于以下问题:PHP Transform类的具体用法?PHP Transform怎么用?PHP Transform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: returnData
/**
* 返回数据到客户端
* @access protected
* @param mixed $data 要返回的数据
* @param String $type 返回数据格式
* @param bool $exit 是否终止执行
* @return void
*/
public static function returnData($data, $type = '', $exit = true)
{
$headers = ['json' => 'application/json', 'xml' => 'text/xml', 'html' => 'text/html', 'jsonp' => 'application/javascript', 'script' => 'application/javascript', 'text' => 'text/plain'];
$type = strtolower($type);
if (isset($headers[$type])) {
header('Content-Type:' . $headers[$type] . '; charset=utf-8');
}
switch ($type) {
case 'json':
// 返回JSON数据格式到客户端 包含状态信息
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
break;
case 'xml':
// 返回xml格式数据
$data = \org\Transform::xmlEncode($data);
break;
case 'jsonp':
// 返回JSON数据格式到客户端 包含状态信息
$handler = isset($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
$data = $handler . '(' . Transform::jsonEncode($data) . ');';
break;
}
if ($exit) {
exit($data);
} else {
echo $data;
}
}
示例2: loadFile
/**
* Load a config file or dir (no caching)
*
* @param Fs_Item $file_object
* @param string $group
* @return array
*/
protected function loadFile($file_object, $group = null)
{
if ($file_object instanceof Fs_File) {
return Transform::with('unserialize-yaml')->process($file_object->path());
} elseif ($file_object instanceof Fs_Dir) {
return $this->loadDir($file_object);
}
return array();
}
示例3: loadFile
/**
* Load a config file or dir
*
* @param Fs_Item $file_object
* @param string $group
* @return array
*/
protected function loadFile($file_object, $group = null)
{
if ($file_object instanceof Fs_File) {
return Transform::with('unserialize-ini')->process($file_object->path());
} elseif (!empty($this->_options['recursive']) && $file_object instanceof Fs_Dir) {
return $this->loadDir($file_object);
}
return array();
}
示例4: __construct
/**
* Constructs the class with given parameters and reads box related data from
* the ISO Base Media file.
*
* @param Reader $reader The reader object.
*/
public function __construct($reader, &$options = array())
{
parent::__construct($reader, $options);
$entryCount = $this->_reader->readUInt32BE();
$data = $this->_reader->read
($this->getOffset() + $this->getSize() - $this->_reader->getOffset());
for ($i = 1; $i <= $entryCount; $i++)
$this->_syncSampleTable[$i] =
Transform::fromUInt32BE(substr($data, ($i - 1) * 4, 4));
}
示例5: __construct
/**
* Constructs the class with given parameters and parses object related
* data.
*
* @param Zend_Io_Reader $reader The reader object.
* @param Array $options The options array.
*/
public function __construct($reader = null, &$options = array())
{
parent::__construct($reader, $options);
if ($this->_reader === null) {
throw new Zend_Media_Id3_Exception('Write not supported yet');
}
$this->_frames = Transform::fromInt16BE(substr($this->_data, 0, 2));
$this->_bytes = Transform::fromInt32BE(substr($this->_data, 2, 3));
$this->_milliseconds = Transform::fromInt32BE(substr($this->_data, 5, 3));
$byteDevBits = Transform::fromInt8($this->_data[8]);
$millisDevBits = Transform::fromInt8($this->_data[9]);
// $data = substr($this->_data, 10);
}
示例6: loadFile
/**
* Load a config file or dir (no caching)
*
* @param Fs_Item $file_object
* @param string $group
* @return array
*/
protected function loadFile($file_object, $group = null)
{
$settings = array();
if ($file_object instanceof Fs_File) {
$settings = Transform::with('unserialize-json')->process($file_object->path());
if (!isset($settings)) {
trigger_error("Failed to parse json file '{$file}'.", E_USER_WARNING);
}
} elseif (!empty($this->_options['recursive']) && $file_object instanceof Fs_Dir) {
$settings = $this->loadDir($file_object);
}
return $settings;
}
示例7: __construct
/**
* Constructs the class with given parameters and reads box related data from
* the ISO Base Media file.
*
* @param Reader $reader The reader object.
*/
public function __construct($reader, &$options = array())
{
parent::__construct($reader, $options);
$entryCount = $this->_reader->readUInt32BE();
$data = $this->_reader->read
($this->getOffset() + $this->getSize() - $this->_reader->getOffset());
for ($i = 1; $i <= $entryCount; $i++)
$this->_compositionOffsetTable[$i] = array
("sampleCount" =>
Transform::fromUInt32BE(substr($data, ($i - 1) * 8, 4)),
"sampleOffset" =>
Transform::fromUInt32BE(substr($data, $i * 8 - 4, 4)));
}
示例8: __construct
/**
* Constructs the class with given parameters and reads box related data from
* the ISO Base Media file.
*
* @param Reader $reader The reader object.
*/
public function __construct($reader, &$options = array())
{
parent::__construct($reader, $options);
$entryCount = $this->_reader->readUInt32BE();
$data = $this->_reader->read
($this->getOffset() + $this->getSize() - $this->_reader->getOffset());
for ($i = 1; $i <= $entryCount; $i++)
$this->_sampleToChunkTable[$i] = array
("firstChunk" =>
Transform::fromUInt32BE(substr($data, ($i - 1) * 12, 4)),
"samplesPerChunk" =>
Transform::fromUInt32BE(substr($data, $i * 12 - 8, 4)),
"sampleDescriptionIndex" =>
Transform::fromUInt32BE(substr($data, $i * 12 - 4, 4)));
}
示例9: __construct
/**
* Class constructor
*
* @param array $options
*/
public function __construct($path, $options = array())
{
if (is_array($path)) {
$options = $path + $options;
$path = null;
if (isset($options['driver'])) {
if (isset($options[0])) {
if (!isset($options['path'])) {
$options['path'] = $options[0];
}
if (!isset($options['ext'])) {
$options['ext'] = $options['driver'];
}
unset($options[0]);
} else {
$options[0] = $options['driver'];
}
}
}
if (isset($options[0])) {
if (strpos($options[0], ':') !== false) {
list($options['ext'], $options['path']) = explode(':', $options[0], 2);
} else {
$key = !isset($options['ext']) && strpos($options[0], '.') === false && strpos($options[0], '/') === false ? 'ext' : 'path';
if (!isset($options[$key])) {
$options[$key] = $options[0];
}
}
}
$this->_path = isset($path) ? Fs::dir($path) : (isset($options['path']) ? Fs::dir($options['path']) : null);
if (isset($options['transformer'])) {
$this->_transformer = $options['transformer'] instanceof Transformer ? $options['transformer'] : Transform::with($options['transformer']);
}
$this->_ext = isset($options['ext']) ? $options['ext'] : (isset($this->_transformer) ? $this->_transformer->ext : null);
if (!isset($this->_transformer) && !empty($this->_ext)) {
$this->_transformer = Transform::from($this->_ext);
}
\ArrayObject::__construct(array(), \ArrayObject::ARRAY_AS_PROPS);
if (!empty($options['loadall'])) {
$this->loadAll();
}
}
示例10: __construct
/**
* Constructs the class with given parameters and parses object related data.
*
* @param Reader $reader The reader object.
* @param Array $options The options array.
*/
public function __construct($reader = null, &$options = array())
{
parent::__construct($reader, $options);
if ($reader === null) {
throw new ID3_Exception("Write not supported yet");
}
$this->_dataStart = Transform::fromInt32BE(substr($this->_data, 0, 4));
$this->_dataLength = Transform::fromInt32BE(substr($this->_data, 4, 4));
$this->_size = Transform::fromInt16BE(substr($this->_data, 8, 2));
$bitsPerPoint = Transform::fromInt8($this->_data[10]);
/*for ($i = 0, $offset = 11; $i < $this->_size; $i++) {
if ($bitsPerPoint == 16) {
$this->_fractions[$i] = substr($this->_data, $offset, 2);
$offset += 2;
} else {
$this->_fractions[$i] = substr($this->_data, $offset, 1);
$offset ++;
}
}*/
}
示例11: write
/**
* Writes the changes back to the original media file.
*
* Please note: currently the method writes only ID32 and ILST boxes to
* <i>moov.udta.meta</i>. Changes to any other box are discarded. Write
* operation will overwrite <i>moov.udta</i>, if found.
*/
public function write()
{
if (!isset($this->moov->udta->meta->ilst) &&
!isset($this->moov->udta->meta->id32))
throw new ISO14496_Exception("Nothing to write");
if ($this->getOption("readonly", false) !== false)
throw new ISO14496_Exception("File is read only");
if (($fd = fopen($this->_filename, file_exists
($this->_filename) ? "r+b" : "wb")) === false)
throw new ISO14496_Exception
("Unable to open file for writing: " . $filename);
$this->moov->udta->meta->hdlr->setHandlerType("mdir");
/* Calculate start position */
$mark = ($this->moov->udta->getOffset() > 0 ?
$this->moov->udta->getOffset() :
$this->moov->getOffset() + $this->moov->getSize());
/* Calculate file size */
fseek($fd, 0, SEEK_END);
$oldFileSize = ftell($fd);
$newFileSize = $oldFileSize -
($this->moov->udta->getOffset() > 0 ? $this->moov->udta->getSize() : 0) -
(isset($this->moov->udta->meta->free) ?
$this->moov->udta->meta->free->getSize() : 0) +
strlen($this->moov->udta);
/* Calculate free space size */
if ($oldFileSize < $newFileSize) {
// Add free space to the file calculated using the following logaritmic
// equation: log(0.2(x + 10)), ranging from 1k to 9k given the file size
// of 0..4G
$this->moov->udta->meta->free->setSize
(ceil(log(0.2 * ($newFileSize / 1024 + 10), 10) * 1024));
ftruncate($fd, $newFileSize += $this->moov->udta->meta->free->getSize());
// Move data to the end of the file
for ($i = 1, $cur = $oldFileSize; $cur > $mark; $cur -= 1024, $i++) {
fseek($fd, -(($i * 1024) +
($excess = $cur - 1024 > $mark ? 0 : $cur - $mark - 1024) +
($newFileSize - $oldFileSize)), SEEK_END);
$buffer = fread($fd, 1024);
fseek($fd, -(($i * 1024) + $excess), SEEK_END);
fwrite($fd, $buffer, 1024);
}
// Update stco/co64 to correspond the data move
foreach ($this->moov->getBoxesByIdentifier("trak") as $trak) {
$chunkOffsetBox =
(isset($trak->mdia->minf->stbl->stco) ?
$trak->mdia->minf->stbl->stco : $trak->mdia->minf->stbl->co64);
$chunkOffsetTable = $chunkOffsetBox->getChunkOffsetTable();
$chunkOffsetTableCount = count($chunkOffsetTable);
$chunkOffsetDelta = $newFileSize - $oldFileSize;
for ($i = 1; $i <= $chunkOffsetTableCount; $i++)
$chunkOffsetTable[$i] += $chunkOffsetDelta;
$chunkOffsetBox->setChunkOffsetTable($chunkOffsetTable);
fseek($fd, $chunkOffsetBox->getOffset());
fwrite($fd, $chunkOffsetBox, $chunkOffsetBox->getSize());
}
}
else
$this->moov->udta->meta->free->setSize($oldFileSize - $newFileSize);
/* Update the target box */
fseek($fd, $mark);
$this->moov->udta->setSize(fwrite($fd, $this->moov->udta));
/* Update the parent box */
fseek($fd, $this->moov->getOffset());
fwrite($fd, Transform::toUInt32BE($this->moov->getSize()));
fclose($fd);
}
示例12: __toString
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$data = $this->_device . "\0";
foreach ($this->_adjustments as $channel) {
$data .= Transform::toInt8($channel[self::channelType]) .
Transform::toInt16BE($channel[self::volumeAdjustment] * 512);
if (abs($channel[self::peakVolume]) <= 0xff)
$data .= Transform::toInt8(8) .
Transform::toUInt8($channel[self::peakVolume]);
else if (abs($channel[self::peakVolume]) <= 0xffff)
$data .= Transform::toInt8(16) .
Transform::toUInt16BE($channel[self::peakVolume]);
else if (abs($channel[self::peakVolume]) <= 0xffffffff)
$data .= Transform::toInt8(32) .
Transform::toUInt32BE($channel[self::peakVolume]);
else
$data .= Transform::toInt8(64) .
Transform::toInt64BE($channel[self::peakVolume]); // UInt64
}
$this->setData($data);
return parent::__toString();
}
示例13: __toString
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$data = Transform::toInt8($this->_interpolation) . $this->_device . "\0";
foreach ($this->_adjustments as $frequency => $adjustment)
$data .= Transform::toUInt16BE($frequency * 2) .
Transform::toInt16BE($adjustment * 512);
$this->setData($data);
return parent::__toString();
}
示例14: _swapIndex
/**
* swaps the index from end to beginning
*
* swaps the index from end to beginning
*
* @return mixed True if everything wents fine, otherwise error-message as string
* @author Benjamin Carl <phpfluesterer@googlemail.com>
* @version 0.1
* @since Method available since Release 0.1
* @access private
*/
private function _swapIndex()
{
$moovSize = $this->_moovBytes->bytesAvailable();
$moovAType = '';
$moovASize = 0;
$offsetCount = 0;
$compressionCheck = $this->_moovBytes->readBytes(12, 4);
if ($compressionCheck == Atom::CMOV_ATOM) {
throw new Exception('compressed MP4/QT-file can\'t do this file: ' . $file);
}
// begin of metadata
$metaDataOffsets = array();
$metaDataStrings = array();
$metaDataCurrentLevel = 0;
$moovStartOffset = 12;
for ($i = $moovStartOffset; $i < $moovSize - $moovStartOffset; $i++) {
$moovAType = $this->_moovBytes->readUTFBytes($i, 4);
if (Atom::isValidAtom($moovAType)) {
$moovASize = $this->_moovBytes->readUnsignedInt($i - 4);
if ($moovASize > 8 && $moovASize + $i < $moovSize - $moovStartOffset) {
try {
$containerLength = 0;
$containerString = $moovAType;
for ($mi = count($metaDataOffsets) - 1; $mi > -1; $mi--) {
$containerLength = $metaDataOffsets[$mi];
if ($i - $moovStartOffset < $containerLength && $i - $moovStartOffset + $moovASize > $containerLength) {
throw new Exception('bad atom nested size');
}
if ($i - $moovStartOffset == $containerLength) {
array_pop($metaDataOffsets);
array_pop($metaDataStrings);
} else {
$containerString = $metaDataStrings[$mi] . "." . $containerString;
}
}
if ($i - $moovStartOffset <= $containerLength) {
array_push($metaDataOffsets, $i - $moovStartOffset + $moovASize);
array_push($metaDataStrings, $moovAType);
}
if ($moovAType != Atom::STCO_ATOM && $moovAType != Atom::CO64_ATOM) {
$i += 4;
} elseif ($moovAType == Atom::URL_ATOM || $moovAType == Atom::XML_ATOM) {
$i += $moovASize - 4;
}
} catch (Exception $e) {
echo 'EXCEPTION: ' . $e->getMessage();
}
}
}
if ($moovAType == Atom::STCO_ATOM) {
$moovASize = $this->_moovBytes->readUnsignedInt($i - 4);
if ($i + $moovASize - $moovStartOffset > $moovSize) {
throw new Exception('bad atom size');
return;
}
$offsetCount = $this->_moovBytes->readUnsignedInt($i + 8);
for ($j = 0; $j < $offsetCount; $j++) {
$position = $i + 12 + $j * 4;
$currentOffset = $this->_moovBytes->readUnsignedInt($position);
// cause of mooving the moov-atom right before the rest of data
// (behind ftyp) the new offset is caluclated:
// current-offset + size of moov atom (box) = new offset
$currentOffset += $moovSize;
$this->_moovBytes->writeBytes(Transform::toUInt32BE($currentOffset), $position + 1);
}
$i += $moovASize - 4;
} else {
if ($moovAType == Atom::CO64_ATOM) {
$moovASize = $this->_moovBytes->readUnsignedInt($i - 4);
if ($i + $moovASize - $moovStartOffset > $moovSize) {
throw new Exception('bad atom size');
return;
}
$offsetCount = $this->_moovBytes->readDouble($i + 8);
for ($j2 = 0; $j2 < $offsetCount; $j2++) {
$position = $i + 12 + $j * 8;
$currentOffset = $this->_moovBytes->readUnsignedInt($position);
// cause of mooving the moov-atom right before the rest of data
// (behind ftyp) the new offset is caluclated:
// current-offset + size of moov atom (box) = new offset
$currentOffset += $moovSize;
// TODO implement!
//$this->_moovBytes->writeBytes(Transform::toUInt64BE($currentOffset), $position+1);
}
$i += $moovASize - 4;
}
}
}
return true;
//.........这里部分代码省略.........
示例15: __toString
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$data = Transform::toInt8($this->_encoding) . $this->_currency . $this->_price . "" . $this->_date;
switch ($this->_encoding) {
case self::UTF16:
$data .= Transform::toString16($this->_seller);
break;
case self::UTF16BE:
$data .= Transform::toString16BE($this->_seller);
break;
case self::UTF16LE:
$data .= Transform::toString16LE($this->_seller);
break;
default:
$data .= $this->_seller;
}
$this->setData($data);
return parent::__toString();
}