Skip to content

Commit

Permalink
Moved Defaults to Non Abstract Provider
Browse files Browse the repository at this point in the history
For certain scenarios, the default static property isn’t necessary.
It’s a good base class to have, but not necessary for the abstract,
which most might choose to extend from.
  • Loading branch information
MichaelJ2324 committed Jun 16, 2017
1 parent 4c84a91 commit 844c194
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
16 changes: 0 additions & 16 deletions src/Endpoint/Provider/AbstractEndpointProvider.php
Expand Up @@ -8,27 +8,11 @@

abstract class AbstractEndpointProvider implements EndpointProviderInterface
{

/**
* List of default endpoints to load
* @var array
*/
protected static $_DEFAULT_ENDPOINTS = array();

/**
* @var array
*/
protected $registry = array();

public function __construct() {
foreach(static::$_DEFAULT_ENDPOINTS as $name => $epData){
if (!isset($epData['properties'])){
$epData['properties'] = array();
}
$this->registerEndpoint($name,$epData['class'],$epData['properties']);
}
}

/**
* @inheritdoc
* @throws InvalidRegistration
Expand Down
22 changes: 22 additions & 0 deletions src/Endpoint/Provider/DefaultEndpointProvider.php
@@ -0,0 +1,22 @@
<?php

namespace MRussell\REST\Endpoint\Provider;


class DefaultEndpointProvider extends AbstractEndpointProvider
{
/**
* List of default endpoints to load
* @var array
*/
protected static $_DEFAULT_ENDPOINTS = array();

public function __construct() {
foreach(static::$_DEFAULT_ENDPOINTS as $name => $epData){
if (!isset($epData['properties'])){
$epData['properties'] = array();
}
$this->registerEndpoint($name,$epData['class'],$epData['properties']);
}
}
}
3 changes: 2 additions & 1 deletion tests/Endpoint/AbstractEndpointProviderTest.php
Expand Up @@ -3,6 +3,7 @@
namespace MRussell\REST\Tests\Endpoint;

use MRussell\Http\Request\JSON;
use MRussell\REST\Endpoint\Provider\DefaultEndpointProvider;
use MRussell\REST\Endpoint\Provider\EndpointProviderInterface;
use MRussell\REST\Tests\Stubs\Endpoint\AuthEndpoint;
use MRussell\REST\Tests\Stubs\Endpoint\EndpointProvider;
Expand Down Expand Up @@ -39,7 +40,7 @@ public function tearDown()
}

/**
* @covers ::__construct
* @covers MRussell\REST\Endpoint\Provider\DefaultEndpointProvider::__construct
* @covers ::registerEndpoint
*/
public function testConstructor(){
Expand Down
1 change: 0 additions & 1 deletion tests/Stubs/Endpoint/EndpointProvider.php
Expand Up @@ -6,5 +6,4 @@

class EndpointProvider extends AbstractEndpointProvider
{

}
4 changes: 2 additions & 2 deletions tests/Stubs/Endpoint/EndpointProviderWithDefaults.php
Expand Up @@ -4,9 +4,9 @@


use MRussell\Http\Request\JSON;
use MRussell\REST\Endpoint\Provider\AbstractEndpointProvider;
use MRussell\REST\Endpoint\Provider\DefaultEndpointProvider;

class EndpointProviderWithDefaults extends AbstractEndpointProvider
class EndpointProviderWithDefaults extends DefaultEndpointProvider
{
protected static $_DEFAULT_ENDPOINTS = array(
'auth' => array(
Expand Down

0 comments on commit 844c194

Please sign in to comment.