Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use Countable;
use IteratorAggregate;

class Collection implements ArrayAccess, Countable, IteratorAggregate
class GraphCollection implements ArrayAccess, Countable, IteratorAggregate
{
/**
* The items contained in the collection.
Expand Down Expand Up @@ -129,7 +129,7 @@ public function all()
public function asArray()
{
return array_map(function ($value) {
return $value instanceof Collection ? $value->asArray() : $value;
return $value instanceof GraphCollection ? $value->asArray() : $value;
}, $this->items);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Facebook/GraphNodes/GraphEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @package Facebook
*/
class GraphEdge extends Collection
class GraphEdge extends GraphCollection
{
/**
* @var FacebookRequest The original request that generated this data.
Expand Down
2 changes: 1 addition & 1 deletion src/Facebook/GraphNodes/GraphNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @package Facebook
*/
class GraphNode extends Collection
class GraphNode extends GraphCollection
{
/**
* @var array Maps object key names to Graph object types.
Expand Down
50 changes: 50 additions & 0 deletions src/Facebook/Http/Util.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
* form for use in connection with the web services and APIs provided by
* Facebook.
*
* As with any software that integrates with the Facebook platform, your use
* of this software is subject to the Facebook Developer Principles and
* Policies [http://developers.facebook.com/policy/]. This copyright notice
* shall be included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

namespace Facebook\Http;

abstract class Util
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like file is a duplicate, and not used

{

/**
* Avoid parse_str() for HHVM compatibility
* This implementation is not a complete sobstitute, but covers all the
* requirements of the Facebook Http namespace.
*
* @see hhvm.hack.disallow_dynamic_var_env_funcs
* @param $query_string
* @return array
*/
public static function parseUrlQuery($query_string)
{
$query = array();
$pairs = explode('&', $query_string);
foreach ($pairs as $pair) {
list($key, $value) = explode('=', $pair);
$query[$key] = urldecode($value);
}

return $query;
}
}
6 changes: 3 additions & 3 deletions src/Facebook/Url/FacebookUrlManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function removeParamsFromUrl($url, array $paramsToFilter)
$query = '';
if (isset($parts['query'])) {
$params = [];
parse_str($parts['query'], $params);
$params = Util::parseUrlQuery($parts['query']);

// Remove query params
foreach ($paramsToFilter as $paramName) {
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function appendParamsToUrl($url, array $newParams = [])

list($path, $query) = explode('?', $url, 2);
$existingParams = [];
parse_str($query, $existingParams);
$existingParams = Util::parseUrlQuery($query);

// Favor params from the original URL over $newParams
$newParams = array_merge($newParams, $existingParams);
Expand All @@ -111,7 +111,7 @@ public static function getParamsAsArray($url)
return [];
}
$params = [];
parse_str($query, $params);
$params = Util::parseUrlQuery($query);

return $params;
}
Expand Down
50 changes: 50 additions & 0 deletions src/Facebook/Url/Util.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
* form for use in connection with the web services and APIs provided by
* Facebook.
*
* As with any software that integrates with the Facebook platform, your use
* of this software is subject to the Facebook Developer Principles and
* Policies [http://developers.facebook.com/policy/]. This copyright notice
* shall be included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

namespace Facebook\Url;

abstract class Util
{

/**
* Avoid parse_str() for HHVM compatibility
* This implementation is not a complete sobstitute, but covers all the
* requirements of the Facebook Url namesapce.
*
* @see hhvm.hack.disallow_dynamic_var_env_funcs
* @param $query_string
* @return array
*/
public static function parseUrlQuery($query_string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of a static function in that utility class, I'd move the function definition in the FacebookUrlManipulator (as it's used only there, rename it to parse_str, and wrap it with a if (!function_exists('parse_str')).

{
$query = array();
$pairs = explode('&', $query_string);
foreach ($pairs as $pair) {
list($key, $value) = explode('=', $pair);
$query[$key] = urldecode($value);
}

return $query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*/
namespace Facebook\Tests\GraphNodes;

use Facebook\GraphNodes\Collection;
use Facebook\GraphNodes\GraphCollection;

class CollectionTest extends \PHPUnit_Framework_TestCase
{

public function testAnExistingPropertyCanBeAccessed()
{
$graphNode = new Collection(['foo' => 'bar']);
$graphNode = new GraphCollection(['foo' => 'bar']);

$field = $graphNode->getField('foo');
$this->assertEquals('bar', $field);
Expand All @@ -42,15 +42,15 @@ public function testAnExistingPropertyCanBeAccessed()

public function testAMissingPropertyWillReturnNull()
{
$graphNode = new Collection(['foo' => 'bar']);
$graphNode = new GraphCollection(['foo' => 'bar']);
$field = $graphNode->getField('baz');

$this->assertNull($field, 'Expected the property to return null.');
}

public function testAMissingPropertyWillReturnTheDefault()
{
$graphNode = new Collection(['foo' => 'bar']);
$graphNode = new GraphCollection(['foo' => 'bar']);

$field = $graphNode->getField('baz', 'faz');
$this->assertEquals('faz', $field);
Expand All @@ -62,7 +62,7 @@ public function testAMissingPropertyWillReturnTheDefault()

public function testFalseDefaultsWillReturnSameType()
{
$graphNode = new Collection(['foo' => 'bar']);
$graphNode = new GraphCollection(['foo' => 'bar']);

$field = $graphNode->getField('baz', '');
$this->assertSame('', $field);
Expand All @@ -76,7 +76,7 @@ public function testFalseDefaultsWillReturnSameType()

public function testTheKeysFromTheCollectionCanBeReturned()
{
$graphNode = new Collection([
$graphNode = new GraphCollection([
'key1' => 'foo',
'key2' => 'bar',
'key3' => 'baz',
Expand All @@ -92,13 +92,13 @@ public function testTheKeysFromTheCollectionCanBeReturned()

public function testAnArrayCanBeInjectedViaTheConstructor()
{
$collection = new Collection(['foo', 'bar']);
$collection = new GraphCollection(['foo', 'bar']);
$this->assertEquals(['foo', 'bar'], $collection->asArray());
}

public function testACollectionCanBeConvertedToProperJson()
{
$collection = new Collection(['foo', 'bar', 123]);
$collection = new GraphCollection(['foo', 'bar', 123]);

$collectionAsString = $collection->asJson();

Expand All @@ -107,7 +107,7 @@ public function testACollectionCanBeConvertedToProperJson()

public function testACollectionCanBeCounted()
{
$collection = new Collection(['foo', 'bar', 'baz']);
$collection = new GraphCollection(['foo', 'bar', 'baz']);

$collectionCount = count($collection);

Expand All @@ -116,15 +116,15 @@ public function testACollectionCanBeCounted()

public function testACollectionCanBeAccessedAsAnArray()
{
$collection = new Collection(['foo' => 'bar', 'faz' => 'baz']);
$collection = new GraphCollection(['foo' => 'bar', 'faz' => 'baz']);

$this->assertEquals('bar', $collection['foo']);
$this->assertEquals('baz', $collection['faz']);
}

public function testACollectionCanBeIteratedOver()
{
$collection = new Collection(['foo' => 'bar', 'faz' => 'baz']);
$collection = new GraphCollection(['foo' => 'bar', 'faz' => 'baz']);

$this->assertInstanceOf('IteratorAggregate', $collection);

Expand Down