本文整理汇总了PHP中Set::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::map方法的具体用法?PHP Set::map怎么用?PHP Set::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::map方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBrowserFontsList
public function getBrowserFontsList($type = 'object')
{
$fontsList = array();
$fontsList['items']['items'] = array(array('family' => 'Verdana,Geneva,sans-serif'), array('family' => 'Georgia,Times New Roman,Times, serif'), array('family' => 'Helvetica Neue,Helvetica,Arial,sans-serif'), array('family' => 'Trebuchet MS,Helvetica Neue,Helvetica,Arial,sans-serif'), array('family' => 'Arial Black,Gadjet,sans-serif'), array('family' => 'Times New Roman,Times,serif'), array('family' => 'Palatino Linotype,Book Antiqua,Palatino,serif'), array('family' => 'Lucida Sans Unicode,Lucida Grande,sans-serif'), array('family' => 'New York,serif'), array('family' => 'Lucida Console,Monaco,monospace'), array('family' => 'Comic Sans MS,cursive'));
$fontsList = Set::map($fontsList);
if ($type === 'list') {
$fontsList = $this->collectionToList($fontsList);
}
return $fontsList;
}
示例2: testErrorMessage
function testErrorMessage()
{
$data = Set::map(array('Error' => array('Error' => array('body' => array('users' => array(array('User' => array('id' => 1)), array('User' => array('id' => 2)))), 'string' => 'this is the error message'))));
$result = $this->AmfCallback->encode($data);
$error = new ErrorMessage($data->Error);
//have to unset cause they are autogenerated UUID
unset($result[0]->correlationId, $result[0]->messageId, $result[0]->clientId);
unset($error->_type, $error->correlationId, $error->messageId, $error->clientId);
$expected = array($error, 3, 'flex.messaging.messages.ErrorMessage');
$this->assertEqual($expected, $result);
}
示例3: beforeRender
/**
* undocumented function
*
* @return void
*/
function beforeRender()
{
if ($this->params['isAdmin'] !== true) {
$this->params['admin'] = false;
}
$this->params['project'] = null;
if (!empty($this->Project->current) && $this->Project->id !== '1') {
$this->params['project'] = $this->Project->current['url'];
}
if (isset($this->viewVars['rssFeed'])) {
$this->viewVars['rssFeed'] = array_merge(array('controller' => 'timeline', 'action' => 'index', 'ext' => 'rss'), $this->viewVars['rssFeed']);
}
$this->set('CurrentUser', Set::map($this->Auth->user()));
$this->set('CurrentProject', Set::map(Configure::read('Project'), true));
}
示例4: testNestedMappedData
/**
* testNestedMappedData method
*
* @return void
*/
public function testNestedMappedData()
{
$result = Set::map(array(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working')), array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working'))));
// @codingStandardsIgnoreStart
$expected = new stdClass();
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass();
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = '2007-03-17 01:16:23';
$expected->Author->updated = '2007-03-17 01:18:31';
$expected->Author->test = 'working';
$expected->Author->_name_ = 'Author';
$expected2 = new stdClass();
$expected2->_name_ = 'Post';
$expected2->id = '2';
$expected2->author_id = '3';
$expected2->title = 'Second Post';
$expected2->body = 'Second Post Body';
$expected2->published = 'Y';
$expected2->created = "2007-03-18 10:41:23";
$expected2->updated = "2007-03-18 10:43:31";
$expected2->Author = new stdClass();
$expected2->Author->id = '3';
$expected2->Author->user = 'larry';
$expected2->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected2->Author->created = '2007-03-17 01:20:23';
$expected2->Author->updated = '2007-03-17 01:22:31';
$expected2->Author->test = 'working';
$expected2->Author->_name_ = 'Author';
// @codingStandardsIgnoreEnd
$test = array();
$test[0] = $expected;
$test[1] = $expected2;
$this->assertEquals($test, $result);
$result = Set::map(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working')));
// @codingStandardsIgnoreStart
$expected = new stdClass();
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass();
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = "2007-03-17 01:16:23";
$expected->Author->updated = "2007-03-17 01:18:31";
$expected->Author->test = 'working';
$expected->Author->_name_ = 'Author';
// @codingStandardsIgnoreEnd
$this->assertEquals($expected, $result);
//Case where extra HABTM fields come back in a result
$data = array('User' => array('id' => 1, 'email' => 'user@example.com', 'first_name' => 'John', 'last_name' => 'Smith'), 'Piece' => array(array('id' => 1, 'title' => 'Moonlight Sonata', 'composer' => 'Ludwig van Beethoven', 'PiecesUser' => array('id' => 1, 'created' => '2008-01-01 00:00:00', 'modified' => '2008-01-01 00:00:00', 'piece_id' => 1, 'user_id' => 2)), array('id' => 2, 'title' => 'Moonlight Sonata 2', 'composer' => 'Ludwig van Beethoven', 'PiecesUser' => array('id' => 2, 'created' => '2008-01-01 00:00:00', 'modified' => '2008-01-01 00:00:00', 'piece_id' => 2, 'user_id' => 2))));
$result = Set::map($data);
// @codingStandardsIgnoreStart
$expected = new stdClass();
$expected->_name_ = 'User';
$expected->id = 1;
$expected->email = 'user@example.com';
$expected->first_name = 'John';
$expected->last_name = 'Smith';
$piece = new stdClass();
$piece->id = 1;
$piece->title = 'Moonlight Sonata';
$piece->composer = 'Ludwig van Beethoven';
$piece->PiecesUser = new stdClass();
$piece->PiecesUser->id = 1;
$piece->PiecesUser->created = '2008-01-01 00:00:00';
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
$piece->PiecesUser->piece_id = 1;
$piece->PiecesUser->user_id = 2;
$piece->PiecesUser->_name_ = 'PiecesUser';
$piece->_name_ = 'Piece';
$piece2 = new stdClass();
$piece2->id = 2;
$piece2->title = 'Moonlight Sonata 2';
$piece2->composer = 'Ludwig van Beethoven';
$piece2->PiecesUser = new stdClass();
$piece2->PiecesUser->id = 2;
$piece2->PiecesUser->created = '2008-01-01 00:00:00';
$piece2->PiecesUser->modified = '2008-01-01 00:00:00';
$piece2->PiecesUser->piece_id = 2;
//.........这里部分代码省略.........
示例5: testSetSerialization
/**
* testSetSerialization method
*
* @access public
* @return void
*/
function testSetSerialization()
{
$input = array(array('Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null), 'Style' => array('id' => null, 'name' => null), 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'), 'Industry' => array('id' => 1, 'name' => 'Financial')), array('Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null), 'Style' => array('id' => null, 'name' => null), 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'), 'Industry' => array('id' => 2, 'name' => 'Education')));
$expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>';
$xml = new Xml(Set::map($input), array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => false));
$this->assertEqual($expected, $result);
}
示例6: array
/**
* Append given node as a child.
*
* @param object $child XmlNode with appended child
* @param array $options XML generator options for objects and arrays
* @return object A reference to the appended child node
* @access public
*/
function &append(&$child, $options = array())
{
if (empty($child)) {
$return = false;
return $return;
}
if (is_object($child)) {
if ($this->compare($child)) {
trigger_error('Cannot append a node to itself.');
$return = false;
return $return;
}
} else {
if (is_array($child)) {
$child = Set::map($child);
if (is_array($child)) {
if (!is_a(current($child), 'XmlNode')) {
foreach ($child as $i => $childNode) {
$child[$i] = $this->normalize($childNode, null, $options);
}
} else {
foreach ($child as $childNode) {
$this->append($childNode, $options);
}
}
return $child;
}
} else {
$attributes = array();
if (func_num_args() >= 2) {
$attributes = func_get_arg(1);
}
$child =& $this->createNode($child, null, $attributes);
}
}
$child = $this->normalize($child, null, $options);
if (empty($child->namespace) && !empty($this->namespace)) {
$child->namespace = $this->namespace;
}
if (is_a($child, 'XmlNode')) {
$child->setParent($this);
}
return $child;
}
示例7: __decode3
//.........这里部分代码省略.........
} elseif ($data === null) {
$id = $id >> 1;
$data = array();
$_this->read('byte');
for ($i = 0; $i < $id; $i++) {
$data[] = $_this->__decode3();
}
$_this->stored[] = $data;
return $data;
} else {
return $data;
}
case 'object':
list($id, $object) = $_this->__ref();
if ($object === false) {
return false;
} elseif ($object === null) {
$classRef = $id >> 1;
$type = $classRef >> 1 & 0x3;
list($classRef, $classTemplate) = $_this->__ref($classRef);
if ($classTemplate === false) {
return false;
} elseif ($classTemplate != null) {
if (is_a($classTemplate, 'itypedobject') || is_a($classTemplate, 'ITypedObject')) {
$className = 'CakeClass';
} else {
$className = false;
}
} else {
$className = $_this->__decode3('str');
$classTemplate = false;
}
// Create the values array and store it in $stored
// before reading the properties.
$values = array();
$isMapped = false;
if ($className) {
if ($localClass == $className) {
$obj = new $localClass();
$isMapped = true;
} else {
$obj = Set::map($values);
}
} else {
$obj =& $values;
}
$_this->stored[] = $obj;
// Check to see the encoding type
switch ($objType) {
case 2:
if ($classTemplate) {
$propertyNames = array_keys($classTemplate->__decode());
for ($i = 0; $i < count($propertyNames); $i++) {
$values[$propertyNames[$i]] = $_this->__decode3();
}
} else {
// Property-value pairs
do {
$propertyName = $_this->read('str');
if ($propertyName != '' && !is_null($propertyName)) {
$propValue = $_this->__decode3();
$values[$propertyName] = $propValue;
}
} while ($propertyName != '');
}
break;
case 1:
// One single value, no propertyname. Not sure what to do with this, so following ServiceCapture's example and naming the property 'source'
$values["source"] = $_this->__decode3();
break;
case 0:
$propertyCount = $classref >> 3;
$propertyNames = array();
// First read all the propertynames, then the values
for ($i = 0; $i < $propertyCount; $i++) {
$propertyName = $_this->__decode3('str');
$propertyNames[] = $propertyName;
}
foreach ($propertyNames as $pn) {
$values[$pn] = $_this->__decode3();
}
break;
}
if ($isMapped) {
foreach ($values as $k => $v) {
$obj->{$k} = $v;
}
} else {
if (is_a($obj) && method_exists($obj, 'setAMFData')) {
$obj->setAMFData($values);
}
}
return $obj;
}
case 'xml_string':
$length = $_this->read('int') >> 1;
return $_this->read($length, 'str');
break;
}
}
示例8: __encodeBody
/**
* undocumented function
*
* @return void
*
**/
function __encodeBody($value)
{
if (!class_exists('AmfCallback')) {
App::import('Vendor', 'Amf.AmfCallback');
}
if (!empty($value['Error'])) {
if (!is_array($value['Error'])) {
$error = array('string' => $value['Error']);
}
unset($value['Error']);
$data = array('Error' => array_merge(array('body' => $value), $error));
$result = amf_encode($data, 1, $call);
return $result;
}
if (!empty($this->validationErrors)) {
$value['validationErrors'] = $this->validationErrors;
}
if (isset($value['useCallback'])) {
$AmfCallback =& new AmfCallback($this);
$result = amf_encode(Set::map(array('ResultSet' => $value)), 1, array($AmfCallback, "encode"));
return $result;
}
$result = amf_encode($value, 1, $call);
return $result;
}
示例9: __construct
/**
* Constructor. Sets up the XML parser with options, gives it this object as
* its XML object, and sets some variables.
*
* @param string $input What should be used to set up
* @param array $options Options to set up with
*/
function __construct($input = null, $options = array())
{
parent::__construct('root');
$this->__parser = xml_parser_create_ns();
xml_set_object($this->__parser, $this);
xml_parser_set_option($this->__parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->__parser, XML_OPTION_SKIP_WHITE, 1);
$this->children = array();
if ($input != null) {
$vars = null;
if (is_string($input)) {
$this->load($input);
} elseif (is_array($input)) {
$vars = $this->__objectToNode(Set::map($input));
} elseif (is_object($input)) {
$vars = $this->__objectToNode($input);
}
if ($vars != null) {
$this->children = $vars;
}
if (!is_array($this->children)) {
$this->children = array($this->children);
}
}
if (Configure::read('App.encoding') !== null) {
$this->encoding = Configure::read('App.encoding');
}
foreach ($options as $key => $val) {
switch ($key) {
case 'version':
$this->version = $val;
break;
case 'encoding':
$this->encoding = $val;
break;
}
}
}
示例10: encode
/**
* undocumented function
*
* @return void
*
**/
function encode($value)
{
if ($this->stop === true) {
return;
}
$className = get_class($value);
if ($className === 'AcknowledgeMessage') {
return array($value, 3, $value->_type);
}
if ($className == 'CommandMessage') {
$obj = new AcknowledgeMessage($value);
$type = $obj->_type;
unset($obj->_type);
return array($obj, 3, $type);
}
if ($className == 'RemotingMessage') {
$obj = new AcknowledgeMessage($value);
$type = $obj->_type;
unset($obj->_type);
return array($obj, 3, $type);
}
if ($className == 'stdClass') {
$type = 'Object';
if (isset($value->_name_)) {
$type = Inflector::camelize($value->_name_);
unset($value->_name_);
if ($type == 'Error') {
$type = null;
$value = new ErrorMessage($value);
}
} else {
if (empty($this->types)) {
$this->types = array_keys(get_object_vars($value));
if (empty($this->types)) {
return array($value, 3, $type);
}
$type = $this->types[0];
if (count($this->types) <= 1) {
$val = $value->{$type};
if (!is_array($val)) {
$types = array_keys(get_object_vars($val));
if (count($types) <= 1) {
$value = $val;
if (isset($value->_name_)) {
$type = Inflector::camelize($value->_name_);
unset($value->_name_);
}
}
}
} else {
$type = 'Array';
$this->step--;
}
} else {
if (isset($this->types[$this->step])) {
$type = $this->types[$this->step++];
} else {
$type = 'Array';
}
}
if (isset($value->{$type})) {
$value = Set::map(Set::reverse($value));
if (isset($value->_name_)) {
$type = Inflector::camelize($value->_name_);
unset($value->_name_);
}
}
}
if (isset($type)) {
if (ClassRegistry::isKeySet($type)) {
$typedClass =& ClassRegistry::getObject($type);
if (isset($typedClass->_remoteAlias)) {
$type = $typedClass->_remoteAlias;
unset($typedClass->_remoteAlias);
}
}
/* @todo add support for date fields
if(isset($value->created)) {
$value->created = number_format(strtotime($value->created) * 1000, 0, '.', '');
}
if(isset($value->modified)) {
$value->modified = number_format(strtotime($value->modified) * 1000, 0, '.', '');
}
*/
}
}
if (isset($value->_type)) {
$type = $value->_type;
unset($value->_type);
}
if (empty($type)) {
$type = Inflector::camelize(gettype($value));
}
return array($value, 3, $type);
//.........这里部分代码省略.........
示例11: testNestedMappedData
function testNestedMappedData()
{
$result = Set::map(array(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working')), array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working'))));
$expected = new stdClass();
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass();
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = "2007-03-17 01:16:23";
$expected->Author->updated = "2007-03-17 01:18:31";
$expected->Author->test = "working";
$expected2 = new stdClass();
$expected2->_name_ = 'Post';
$expected2->id = '2';
$expected2->author_id = '3';
$expected2->title = 'Second Post';
$expected2->body = 'Second Post Body';
$expected2->published = 'Y';
$expected2->created = "2007-03-18 10:41:23";
$expected2->updated = "2007-03-18 10:43:31";
$expected2->Author = new stdClass();
$expected2->Author->id = '3';
$expected2->Author->user = 'larry';
$expected2->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected2->Author->created = "2007-03-17 01:20:23";
$expected2->Author->updated = "2007-03-17 01:22:31";
$expected2->Author->test = "working";
$test = array();
$test[0] = $expected;
$test[1] = $expected2;
$this->assertIdentical($test, $result);
$result = Set::map(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working')));
$expected = new stdClass();
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass();
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = "2007-03-17 01:16:23";
$expected->Author->updated = "2007-03-17 01:18:31";
$expected->Author->test = "working";
$this->assertIdentical($expected, $result);
}
示例12: testMapReverse
function testMapReverse()
{
$expected = array('Array1' => array('Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2', 'Array1Data3' => 'Array1Data3 value 3', 'Array1Data4' => 'Array1Data4 value 4', 'Array1Data5' => 'Array1Data5 value 5', 'Array1Data6' => 'Array1Data6 value 6', 'Array1Data7' => 'Array1Data7 value 7', 'Array1Data8' => 'Array1Data8 value 8'), 'Array2' => array(0 => array('Array2Data1' => 1, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'), 1 => array('Array2Data1' => 2, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'), 2 => array('Array2Data1' => 3, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'), 3 => array('Array2Data1' => 4, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'), 4 => array('Array2Data1' => 5, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4')), 'Array3' => array(0 => array('Array3Data1' => 1, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'), 1 => array('Array3Data1' => 2, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'), 2 => array('Array3Data1' => 3, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'), 3 => array('Array3Data1' => 4, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'), 4 => array('Array3Data1' => 5, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4')));
$map = Set::map($expected);
$result = Set::reverse($map);
$this->assertIdentical($result, $expected);
}
示例13: _serialize
function _serialize($data, $name = null)
{
$type = $this->_getType($data);
if ($type == 'string') {
$type = null;
}
if ($type == 'boolean') {
$data = $data ? 'true' : 'false';
}
if ($type == 'datetime') {
if (preg_match('/^\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}\\:\\d{2}\\:\\d{2}Z$/', $data)) {
$data = gmdate('Y-m-d\\TH:i:s\\Z', strtotime($data));
} else {
$data = date('Y-m-d\\TH:i:s\\Z', strtotime($data));
}
}
if ($type == 'array') {
$map = Set::map($data);
$type = $this->_getType($map);
if ($type == 'array') {
$data = array();
if (isset($map[0]->_name_)) {
$name = Inflector::underscore(Inflector::pluralize($map[0]->_name_));
}
for ($i = 0; $i < count($map); $i++) {
$data[] = $this->_serialize($map[$i], Inflector::singularize($name));
}
$data = implode('', $data);
} else {
$type = 'object';
$name = Inflector::singularize($name);
$data = $map;
}
}
if ($type == 'object') {
$map = array();
if (isset($data->_name_)) {
$name = Inflector::underscore($data->_name_);
unset($data->_name_);
}
foreach ($data as $key => $value) {
$map[] = $this->_serialize($value, $key);
}
if (get_class($data) !== 'stdClass') {
$name = get_class($data);
}
$type = null;
$data = implode($map);
}
if (empty($name)) {
$name = 'var';
}
$tag = str_replace('_', '-', Inflector::underscore($name));
// Start tag
$result = '<' . $tag;
// Type attribute
if (!is_null($type)) {
$result .= ' type="' . $type . '"';
}
$result .= '>' . $data . '</' . $tag . '>';
return $result;
}
示例14: __encodeBody
/**
* undocumented function
*
* @return void
*
**/
function __encodeBody($value)
{
if (!class_exists('AmfCallback')) {
App::import('Vendor', 'Amf.AmfCallback');
}
$AmfCallback =& new AmfCallback($this);
if (!empty($value['Error'])) {
if (!is_array($value['Error'])) {
$error = array('string' => $value['Error']);
}
unset($value['Error']);
$data = array('Error' => array_merge(array('body' => $value), $error));
} else {
$data = array('ResultSet' => $value);
}
$result = amf_encode(Set::map($data), 1, array($AmfCallback, "encode"));
return $result;
}