Skip to content
Merged
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
13 changes: 6 additions & 7 deletions extra/Entities/Bridge.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Entities;

use ReflectionObject;
Expand All @@ -23,17 +25,16 @@ class Bridge
*/
protected $properties = [];


/**
* Make non-public members of the given object accessible
* Make non-public members of the given object accessible.
*
* @param object $object.- Object which members we'll make accessible
*/
public function __construct($object)
{
$this->object = $object;
$reflected = new ReflectionObject($this->object);
$this->properties = array();
$this->properties = [];

$properties = $reflected->getProperties(
ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PUBLIC
Expand All @@ -51,7 +52,7 @@ public function getProperties()
}

/**
* Returns a property of $this->object
* Returns a property of $this->object.
*
* @param string $name
*
Expand All @@ -64,7 +65,5 @@ public function __get($name)
if (isset($this->properties[$name])) {
return $this->properties[$name]->getValue($this->object);
}

return null;
}
}
14 changes: 8 additions & 6 deletions extra/Entities/Call.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Entities;

use BadMethodCallException;
Expand All @@ -15,10 +17,10 @@
trait Call
{
/**
* Get or Set property
* Get or Set property.
*
* @param string $name Name of the method
* @param array $arguments Arguments
* @param string $name Name of the method
* @param array $arguments Arguments
*
* @throws BadMethodCallException If the $name is not a property
*/
Expand All @@ -32,9 +34,9 @@ public function __call($name, $arguments)
}
if ($arguments && count($arguments) == 1) {
$reflect = new ReflectionClass($this);
$props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
$props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
foreach ($props as $prop) {
if ($prop->getName() == $name) {
if ($prop->getName() == $name) {
$this->{$name} = $arguments[0];
}
}
Expand Down
7 changes: 3 additions & 4 deletions extra/Entities/Entity.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/
namespace PhpFirebase\Entities;

use ReflectionObject;
use ReflectionProperty;
namespace PhpFirebase\Entities;

class Entity implements EntityInterface
{
Expand Down
4 changes: 3 additions & 1 deletion extra/Entities/EntityInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Entities;

interface EntityInterface
Expand Down
15 changes: 8 additions & 7 deletions extra/Entities/Repository/Repository.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Entities\Repository;

use PhpFirebase\Clients\GuzzleClient;
use PhpFirebase\Entities\Entity;
use PhpFirebase\Entities\EntityInterface;
use PhpFirebase\Firebase;
use PhpFirebase\Clients\GuzzleClient;

abstract class Repository implements RepositoryInterface
{
Expand Down Expand Up @@ -41,7 +43,7 @@ public function __construct($base, $token = null, $endpoint = null)
$this->firebase = new Firebase(
$this->base,
$this->token,
new GuzzleClient(['verify' => false,])
new GuzzleClient(['verify' => false])
);

$this->endpoint = $endpoint;
Expand All @@ -58,23 +60,22 @@ public function store($entity)
foreach ($entity as &$record) {
$id = $record->id() ? $record->id() : guid();
$record->id($id);
$this->firebase->put($this->endpoint . '/'. $id, $record->toArray());
$this->firebase->put($this->endpoint.'/'.$id, $record->toArray());
$record = $this->find($id);
}
} elseif ($entity instanceof EntityInterface) {
$id = $entity->id() ? $entity->id() : guid();
$entity->id($id);
$response = $this->firebase->put($this->endpoint . '/'. $id, $entity->toArray());
$response = $this->firebase->put($this->endpoint.'/'.$id, $entity->toArray());
$entity = $this->find($id);
}


return $entity;
}

public function find($id)
{
$model = (array) $this->firebase->get($this->endpoint . '/'. $id);
$model = (array) $this->firebase->get($this->endpoint.'/'.$id);
$class = $this->class;
$this->model = new $class($model);

Expand Down
4 changes: 3 additions & 1 deletion extra/Entities/Repository/RepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Entities\Repository;

interface RepositoryInterface
Expand Down
4 changes: 2 additions & 2 deletions extra/Entities/functions.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

function guid()
{
if (function_exists('com_create_guid') === true) {
Expand Down
57 changes: 26 additions & 31 deletions src/Clients/GuzzleClient.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
<?php
/**
* PHP-Firebase
* PHP-Firebase.
*
* @link https://github.com/adrorocker/php-firebase
*
* @copyright Copyright (c) 2018 Adro Rocker
* @author Adro Rocker <mes@adro.rocks>
*/

namespace PhpFirebase\Clients;

use InvalidArgumentException;
use PhpFirebase\Interfaces\ClientInterface;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Uri;
use PhpFirebase\Interfaces\ClientInterface;
use function GuzzleHttp\Psr7\stream_for;

/**
* Guzzle Client.
*
* @package PhpFirebase
* @subpackage Clients
* @since 0.1.0
*/
class GuzzleClient implements ClientInterface
{
/**
* Guzzle client
* Guzzle client.
*
* @var \GuzzleHttp\Client
*/
protected $guzzle;

/**
* Set the the guzzle client
* Set the the guzzle client.
*
* @param array $options The options to set the defaul
* @param Object|null $client Client to make the requests
* @param array $options The options to set the defaul
* @param object|null $client Client to make the requests
*/
public function __construct(array $options = [], $client = null)
{
if (!$client) {
$client = new HttpClient($options);
}

$this->guzzle = $client;
}

/**
* Create a new GET reuest
* Create a new GET reuest.
*
* @param string $endpoint The sub endpoint
* @param array $headers Request headers
* @param array $headers Request headers
*
* @return array
*/
Expand All @@ -66,11 +63,11 @@ public function get($endpoint, $headers = [])
}

/**
* Create a new POST reuest
* Create a new POST reuest.
*
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
*
* @return array
*/
Expand All @@ -84,11 +81,11 @@ public function post($endpoint, $data, $headers = [])
}

/**
* Create a new PUT reuest
* Create a new PUT reuest.
*
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
*
* @return array
*/
Expand All @@ -102,11 +99,11 @@ public function put($endpoint, $data, $headers = [])
}

/**
* Create a new PATCH reuest
* Create a new PATCH reuest.
*
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
* @param string $endpoint The sub endpoint
* @param string|array $data The data to be submited
* @param array $headers Request headers
*
* @return array
*/
Expand All @@ -120,10 +117,10 @@ public function patch($endpoint, $data, $headers = [])
}

/**
* Create a new DELETE reuest
* Create a new DELETE reuest.
*
* @param string $endpoint The sub endpoint
* @param array $headers Request headers
* @param array $headers Request headers
*
* @return array
*/
Expand All @@ -136,10 +133,8 @@ public function delete($endpoint, $headers = [])
return $this->handle($response);
}



/**
* Handle the response
* Handle the response.
*
* @param \GuzzleHttp\Psr7\Response $response The response
*
Expand Down
Loading