当前位置: 首页>>代码示例>>PHP>>正文


PHP Convert::json2array方法代码示例

本文整理汇总了PHP中Convert::json2array方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::json2array方法的具体用法?PHP Convert::json2array怎么用?PHP Convert::json2array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Convert的用法示例。


在下文中一共展示了Convert::json2array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSearch

	function testSearch() {
		$team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
		$team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');

		$response = $this->get('GridFieldAddExistingAutocompleterTest_Controller');
		$this->assertFalse($response->isError());
		$parser = new CSSContentParser($response->getBody());
		$btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationfind');

		$response = $this->post(
			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Team 2',
			array(
				(string)$btns[0]['name'] => 1
			)
		);
		$this->assertFalse($response->isError());
		$result = Convert::json2array($response->getBody());
		$this->assertEquals(1, count($result));
		$this->assertEquals(array($team2->ID => 'Team 2'), $result);

		$response = $this->post(
			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Unknown',
			array(
				(string)$btns[0]['name'] => 1
			)
		);
		$this->assertFalse($response->isError());
		$result = Convert::json2array($response->getBody());
		$this->assertEmpty($result, 'The output is either an empty array or boolean FALSE');
	}
开发者ID:redema,项目名称:sapphire,代码行数:30,代码来源:GridFieldAddExistingAutocompleterTest.php

示例2: testPublish

 /**
  * @todo Test the results of a publication better
  */
 public function testPublish()
 {
     $page1 = $this->objFromFixture('Page', "page1");
     $page2 = $this->objFromFixture('Page', "page2");
     $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
     $response = $this->get('admin/pages/publishall?confirm=1');
     $this->assertContains('Done: Published 30 pages', $response->getBody());
     $actions = CMSBatchActionHandler::config()->batch_actions;
     // Some modules (e.g., cmsworkflow) will remove this action
     $actions = CMSBatchActionHandler::config()->batch_actions;
     if (isset($actions['publish'])) {
         $response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', array($page1->ID, $page2->ID)));
         $responseData = Convert::json2array($response->getBody());
         $this->assertArrayHasKey($page1->ID, $responseData['modified']);
         $this->assertArrayHasKey($page2->ID, $responseData['modified']);
     }
     // Get the latest version of the redirector page
     $pageID = $this->idFromFixture('RedirectorPage', 'page5');
     $latestID = DB::prepared_query('select max("Version") from "RedirectorPage_versions" where "RecordID" = ?', array($pageID))->value();
     $dsCount = DB::prepared_query('select count("Version") from "RedirectorPage_versions" where "RecordID" = ? and "Version"= ?', array($pageID, $latestID))->value();
     $this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID);
     $this->session()->clear('loggedInAs');
     //$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
     /*
     $response = Director::test("admin/pages/publishitems", array(
     	'ID' => ''
     	'Title' => ''
     	'action_publish' => 'Save and publish',
     ), $session);
     $this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
     */
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:35,代码来源:CMSMainTest.php

示例3: Weather

 public function Weather()
 {
     if (!$this->Location) {
         return false;
     }
     $rnd = time();
     $url = "http://query.yahooapis.com/v1/public/yql?format=json&rnd={$rnd}&diagnostics=true&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=";
     $query = urlencode("select * from weather.forecast where location in (select id from weather.search where query=\"{$this->Location}\") and u=\"{$this->Units}\"");
     $response = file_get_contents($url . $query);
     if ($response) {
         $result = Convert::json2array($response);
         if (!$result["query"]["results"]) {
             return false;
         }
         $days = ArrayList::create(array());
         $channel = isset($result["query"]["results"]["channel"][0]) ? $result["query"]["results"]["channel"][0] : $result["query"]["results"]["channel"];
         $label = $channel["title"];
         $link = $channel["link"];
         $forecast = $channel["item"]["forecast"];
         for ($i = 0; $i < 2; $i++) {
             $item = $forecast[$i];
             $days->push(ArrayData::create(array('High' => $item["high"], 'Low' => $item["low"], 'ImageURL' => "http://l.yimg.com/a/i/us/we/52/" . $item["code"] . ".gif", 'Label' => $i == 0 ? _t('Dashboard.TODAY', 'Today') : _t('Dashboard.TOMORROW', 'Tomorrow'))));
         }
         $html = $this->customise(array('Location' => str_replace("Yahoo! Weather - ", "", $label), 'Link' => $link, 'Days' => $days))->renderWith('DashboardWeatherContent');
         $this->WeatherHTML = $html;
         $this->write();
         return $html;
     }
     return $this->WeatherHTML;
 }
开发者ID:nathancox,项目名称:silverstripe-dashboard,代码行数:30,代码来源:DashboardWeatherPanel.php

示例4: testEnablePluginsByArrayWithPaths

 public function testEnablePluginsByArrayWithPaths()
 {
     Config::inst()->update('Director', 'alternate_base_url', 'http://mysite.com/subdir');
     $c = new TinyMCEConfig();
     $c->setTheme('modern');
     $c->setOption('language', 'es');
     $c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss');
     $c->enablePlugins(array('plugin1' => 'mypath/plugin1.js', 'plugin2' => '/anotherbase/mypath/plugin2.js', 'plugin3' => 'https://www.google.com/plugin.js', 'plugin4' => null, 'plugin5' => null));
     $attributes = $c->getAttributes();
     $config = Convert::json2array($attributes['data-config']);
     $plugins = $config['external_plugins'];
     $this->assertNotEmpty($plugins);
     // Plugin specified via relative url
     $this->assertContains('plugin1', array_keys($plugins));
     $this->assertEquals('http://mysite.com/subdir/mypath/plugin1.js', $plugins['plugin1']);
     // Plugin specified via root-relative url
     $this->assertContains('plugin2', array_keys($plugins));
     $this->assertEquals('http://mysite.com/anotherbase/mypath/plugin2.js', $plugins['plugin2']);
     // Plugin specified with absolute url
     $this->assertContains('plugin3', array_keys($plugins));
     $this->assertEquals('https://www.google.com/plugin.js', $plugins['plugin3']);
     // Plugin specified with standard location
     $this->assertContains('plugin4', array_keys($plugins));
     $this->assertEquals('http://mysite.com/subdir/framework/thirdparty/tinymce/plugins/plugin4/plugin.min.js', $plugins['plugin4']);
     // Check that internal plugins are extractable separately
     $this->assertEquals(['plugin4', 'plugin5'], $c->getInternalPlugins());
     // Test plugins included via gzip compresser
     Config::inst()->update('HTMLEditorField', 'use_gzip', true);
     $this->assertEquals('framework/thirdparty/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true', $c->getScriptURL());
     // If gzip is disabled only the core plugin is loaded
     Config::inst()->remove('HTMLEditorField', 'use_gzip');
     $this->assertEquals('framework/thirdparty/tinymce/tinymce.min.js', $c->getScriptURL());
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:33,代码来源:HTMLEditorConfigTest.php

示例5: recordInbound

 function recordInbound()
 {
     $strJson = file_get_contents("php://input");
     try {
         $arrResponse = Convert::json2array($strJson);
         if ($savedMessage = PostmarkMessage::get()->filter('MessageID', $arrResponse['MessageID'])->first()) {
             return;
         }
         $hash = $arrResponse['ToFull'][0]['MailboxHash'];
         $hashParts = explode('+', $hash);
         $lastMessage = PostmarkMessage::get()->filter(array('UserHash' => $hashParts[0], 'MessageHash' => $hashParts[1]))->first();
         $fromCustomer = PostmarkHelper::find_or_make_client($arrResponse['From']);
         $inboundSignature = null;
         if ($lastMessage) {
             $inboundSignature = $lastMessage->From();
         } else {
             if (!$lastMessage && isset($arrResponse['To'])) {
                 $inboundSignature = PostmarkSignature::get()->filter('Email', $arrResponse['To'])->first();
             }
         }
         if (!$inboundSignature) {
             $inboundSignature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
         }
         $message = new PostmarkMessage(array('Subject' => $arrResponse['Subject'], 'Message' => $arrResponse['HtmlBody'], 'ToID' => 0, 'MessageID' => $arrResponse['MessageID'], 'InReplyToID' => $lastMessage ? $lastMessage->ID : 0, 'FromCustomerID' => $fromCustomer ? $fromCustomer->ID : 0, 'InboundToID' => $inboundSignature ? $inboundSignature->ID : 0));
         $message->write();
         if (isset($arrResponse['Attachments']) && count($arrResponse['Attachments'])) {
             foreach ($arrResponse['Attachments'] as $attachment) {
                 $attachmentObject = new Attachment(array('Content' => $attachment['Content'], 'FileName' => $attachment['Name'], 'ContentType' => $attachment['ContentType'], 'Length' => $attachment['ContentLength'], 'ContentID' => $attachment['ContentID'], 'PostmarkMessageID' => $message->ID));
                 $attachmentObject->write();
             }
         }
     } catch (Exception $e) {
     }
     return 'OK';
 }
开发者ID:bueckl,项目名称:postmarkedapp,代码行数:35,代码来源:PostmarkNotifier.php

示例6: testPublish

 /**
  * @todo Test the results of a publication better
  */
 function testPublish()
 {
     $page1 = $this->objFromFixture('Page', "page1");
     $page2 = $this->objFromFixture('Page', "page2");
     $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
     $response = $this->get("admin/cms/publishall?confirm=1");
     $this->assertContains(sprintf(_t('CMSMain.PUBPAGES', "Done: Published %d pages"), 30), $response->getBody());
     // Some modules (e.g., cmsworkflow) will remove this action
     if (isset(CMSBatchActionHandler::$batch_actions['publish'])) {
         $response = Director::test("admin/cms/batchactions/publish", array('csvIDs' => implode(',', array($page1->ID, $page2->ID)), 'ajax' => 1), $this->session());
         $responseData = Convert::json2array($response->getBody());
         $this->assertTrue(property_exists($responseData['modified'], $page1->ID));
         $this->assertTrue(property_exists($responseData['modified'], $page2->ID));
     }
     // Get the latest version of the redirector page
     $pageID = $this->idFromFixture('RedirectorPage', 'page5');
     $latestID = DB::query('select max("Version") from "RedirectorPage_versions" where "RecordID"=' . $pageID)->value();
     $dsCount = DB::query('select count("Version") from "RedirectorPage_versions" where "RecordID"=' . $pageID . ' and "Version"=' . $latestID)->value();
     $this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID);
     $this->session()->clear('loggedInAs');
     //$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
     /*
     $response = Director::test("admin/publishitems", array(
     	'ID' => ''
     	'Title' => ''
     	'action_publish' => 'Save and publish',
     ), $session);
     $this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
     */
 }
开发者ID:rixrix,项目名称:silverstripe-cms,代码行数:33,代码来源:CMSMainTest.php

示例7: updateAddress

 public function updateAddress()
 {
     $RestfulService = new RestfulService("https://www.odeon.co.uk/cinemas/odeon/", 315360);
     $Response = $RestfulService->request($this->ID);
     if (!$Response->isError()) {
         $html = HtmlDomParser::str_get_html($Response->getBody());
         $cinema = $html->find('div[id="gethere"]', 0);
         foreach ($cinema->find('.span4') as $span4) {
             foreach ($span4->find('p.description') as $description) {
                 $address = implode(', ', preg_split('/\\s+\\s+/', trim($description->plaintext)));
                 $RestfulService = new RestfulService("http://maps.google.com/maps/api/geocode/json?address={$address}");
                 $RestfulService_geo = $RestfulService->request();
                 if (!$RestfulService_geo->isError()) {
                     $body = Convert::json2array($RestfulService_geo->getBody());
                     if (isset($body['results'][0]['geometry']['location']['lat']) && isset($body['results'][0]['geometry']['location']['lng'])) {
                         $this->Address = $address;
                         $this->lat = $body['results'][0]['geometry']['location']['lat'];
                         $this->lng = $body['results'][0]['geometry']['location']['lng'];
                         $this->write();
                     }
                 }
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:mattclegg-odeon-availability-checker,代码行数:25,代码来源:OdeonCinema.php

示例8: testJSON2Array

 function testJSON2Array()
 {
     $val = '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}';
     $decoded = Convert::json2array($val);
     $this->assertEquals(3, count($decoded), '3 items in the decoded array');
     $this->assertContains('Bloggs', $decoded, 'Contains "Bloggs" value in decoded array');
     $this->assertContains('Jones', $decoded, 'Contains "Jones" value in decoded array');
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:8,代码来源:ConvertTest.php

示例9: process

 /**
  * @return string
  */
 public function process()
 {
     if (isset($_POST['SourceURL'])) {
         $sourceURL = $_POST['SourceURL'];
         $bIsCloudinary = CloudinaryVideo::isCloudinary($sourceURL);
         $bIsYoutube = YoutubeVideo::is_youtube($sourceURL);
         $bIsVimeo = VimeoVideo::is_vimeo($sourceURL);
         $video = null;
         if ($bIsYoutube || $bIsVimeo || $bIsCloudinary) {
             if ($bIsCloudinary) {
                 $filterClass = 'CloudinaryVideo';
                 $fileType = 'video';
             } elseif ($bIsYoutube) {
                 $filterClass = 'YoutubeVideo';
                 $fileType = 'youtube';
             } else {
                 $filterClass = 'VimeoVideo';
                 $fileType = 'vimeo';
             }
             $funcForID = $bIsYoutube ? 'youtube_id_from_url' : 'vimeo_id_from_url';
             $funcForDetails = $bIsYoutube ? 'youtube_video_details' : 'vimeo_video_details';
             if ($bIsCloudinary) {
                 $arr = Config::inst()->get('CloudinaryConfigs', 'settings');
                 if (isset($arr['CloudName']) && !empty($arr['CloudName'])) {
                     $arrPieces = explode('/', $sourceURL);
                     $arrFileName = array_slice($arrPieces, 7);
                     $fileName = implode('/', $arrFileName);
                     $publicID = substr($fileName, 0, strrpos($fileName, '.'));
                     $video = $filterClass::get()->filterAny(array('URL' => $sourceURL, 'PublicID' => $publicID))->first();
                     if (!$video) {
                         $api = new \Cloudinary\Api();
                         $resource = $api->resource($publicID, array("resource_type" => "video"));
                         //qoogjqs9ksyez7ch8sh5
                         $json = json_encode($resource);
                         $arrResource = Convert::json2array($json);
                         $video = new $filterClass(array('Title' => $arrResource['public_id'] . '.' . $arrResource['format'], 'PublicID' => $arrResource['public_id'], 'Version' => $arrResource['version'], 'URL' => $arrResource['url'], 'SecureURL' => $arrResource['secure_url'], 'FileType' => $arrResource['resource_type'], 'FileSize' => $arrResource['bytes'], 'Format' => $arrResource['format'], 'Signature' => isset($arrResource['signature']) ? $arrResource['signature'] : ''));
                         $video->write();
                     }
                 }
             } else {
                 $video = $filterClass::get()->filter('URL', $sourceURL)->first();
                 if (!$video) {
                     $sourceID = $filterClass::$funcForID($sourceURL);
                     $details = $filterClass::$funcForDetails($sourceID);
                     $video = new $filterClass(array('Title' => $details['title'], 'Duration' => $details['duration'], 'URL' => $sourceURL, 'secure_url' => $sourceURL, 'PublicID' => $sourceID, 'FileType' => $fileType));
                     $video->write();
                 }
             }
             if ($video) {
                 $this->value = $iVideoID = $video->ID;
                 $file = $this->customiseCloudinaryFile($video);
                 return Convert::array2json(array('colorselect_url' => $file->UploadFieldImageURL, 'thumbnail_url' => $file->UploadFieldThumbnailURL, 'fieldname' => $this->getName(), 'id' => $file->ID, 'url' => $file->URL, 'buttons' => $file->UploadFieldFileButtons, 'more_files' => $this->canUploadMany(), 'field_id' => $this->ID()));
             }
         }
     }
     return Convert::array2json(array());
 }
开发者ID:helpfulrobot,项目名称:mademedia-silverstripe-cloudinary,代码行数:60,代码来源:CloudinaryMediaField.php

示例10: handleMailChimpResponse

 /**
  * Handles responses from the MailChimp API.
  *
  * @param MailChimp $mailChimp
  * @return Array
  */
 public function handleMailChimpResponse($mailChimp)
 {
     $response = $mailChimp->getLastResponse();
     if (!$mailChimp->success()) {
         $message = $response && array_key_exists($response['errors']) ? $response['errors'][0]['message'] : 'Error connecting to MailChimp API';
         user_error($message, E_USER_ERROR);
     }
     return Convert::json2array($response['body']);
 }
开发者ID:somardesignstudios,项目名称:silverstripe-chimpify,代码行数:15,代码来源:ChimpifyAdmin.php

示例11: testLoadFromDatetime

 /**
  * @covers EventInvitationField::loadfromtime()
  */
 public function testLoadFromDatetime()
 {
     $request = new SS_HTTPRequest('GET', null, array('PastTimeID' => $this->idFromFixture('Group', 'group')));
     $field = new EventInvitationField(new RegistrableEvent(), 'Invitations');
     $response = $field->loadfromtime($request);
     $data = Convert::json2array($response->getBody());
     $expect = array((object) array('name' => 'First Registration', 'email' => 'first@example.com'), (object) array('name' => 'Second Registration', 'email' => 'second@example.com'));
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals($expect, $data);
 }
开发者ID:helpfulrobot,项目名称:ajshort-silverstripe-eventmanagement,代码行数:13,代码来源:EventInvitationFieldTest.php

示例12: removePresentation

 /**
  * Removes a presentation from the user's random list
  * @param  int $id The presentation ID     
  */
 public function removePresentation($id)
 {
     if (!$this->owner->PresentationList) {
         return;
     }
     $ids = Convert::json2array($this->owner->PresentationList);
     unset($ids[$id]);
     $this->owner->PresentationList = Convert::array2json($ids);
     $this->owner->write();
 }
开发者ID:rbowen,项目名称:openstack-org,代码行数:14,代码来源:PresentationMemberExtension.php

示例13: run

 /**
  *
  */
 public function run()
 {
     SapphireTransactionManager::getInstance()->transaction(function () {
         $pageToken = null;
         while (true) {
             if ($this->videosUpdated >= SummitVideoApp::config()->popular_video_limit) {
                 break;
             }
             // Prevent an infinite loop if the YouTube service is acting strange
             if ($this->sanityCheck === 5) {
                 $e = new Exeception('Task has run too many times. Seems to be an infinite loop. Could be something wrong with the YouTube service?');
                 SS_Log::log($e, SS_Log::ERR);
                 throw $e;
             }
             try {
                 $response = $this->api->getPopularVideos($pageToken);
             } catch (\Exception $e) {
                 SS_Log::log("YouTube Search failed" . $e->getMessage(), SS_Log::ERR);
             }
             $this->sanityCheck++;
             $body = $response->getBody()->getContents();
             $data = Convert::json2array($body);
             $nextPageToken = @$data['nextPageToken'];
             $ids = [];
             foreach ($data['items'] as $item) {
                 if ($item['id']['kind'] === 'youtube#video') {
                     $ids[] = $item['id']['videoId'];
                 }
             }
             try {
                 $response = $this->api->getVideoStatsById($ids);
             } catch (\Exception $e) {
                 SS_Log::log("YouTube video stats failed" . $e->getMessage(), SS_Log::ERR);
             }
             $body = $response->getBody()->getContents();
             $data = Convert::json2array($body);
             foreach ($data['items'] as $v) {
                 $video = PresentationVideo::get()->filter(['YouTubeID' => $v['id']])->first();
                 if ($video) {
                     $video->Views = $v['statistics']['viewCount'];
                     $video->write();
                     $this->videosUpdated++;
                 }
             }
             // If there are no more pages, then bail
             if ($nextPageToken === $pageToken) {
                 break;
             }
             $pageToken = $nextPageToken;
         }
         echo "{$this->videosUpdated} videos updated.\n";
     });
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:56,代码来源:SummitVideoViewTask.php

示例14: callRestfulService

 protected function callRestfulService($endpoint, $query = array())
 {
     $req = $this->restfulService;
     $req->httpHeader("Accept-Charset: utf-8");
     $query['api_key'] = $this->apiKey;
     $query['format'] = $this->format;
     $req->setQueryString($query);
     $response = $req->request($endpoint);
     if (!$response) {
         return false;
     }
     return Convert::json2array($response->getBody(), true);
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:13,代码来源:SchedAPI.php

示例15: getLocation

 public function getLocation($ip, $ipNumber)
 {
     $api = Config::inst()->get('DBIP_IpParser', 'api');
     $url = "http://api.db-ip.com/v2/{$api}/{$ip}";
     try {
         $json = file_get_contents($url);
         $data = Convert::json2array($json);
         $location = new ArrayData(array('Country' => $data['countryCode'], 'Region' => $data['stateProv'], 'City' => $data['city'], 'Type' => ContinentalContentUtils::IPType($ip)));
         $this->debugLocation($location);
         return $location;
     } catch (Exception $e) {
     }
 }
开发者ID:silverstripers,项目名称:continental-content,代码行数:13,代码来源:DBIP_IpParser.php


注:本文中的Convert::json2array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。