Skip to content

Commit

Permalink
Reorganized imports, removed Action::METHOD_*** constants in favour…
Browse files Browse the repository at this point in the history
… of `Method::***`, removed NotificationPresenter in favour of ResponseFactory.
  • Loading branch information
top-webmaster committed Apr 5, 2016
1 parent 1cfff10 commit ac4cd46
Show file tree
Hide file tree
Showing 69 changed files with 651 additions and 686 deletions.
7 changes: 4 additions & 3 deletions spec/Action/ActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace spec\Oxygen\Core\Action;

use Oxygen\Core\Action\Group;
use Oxygen\Core\Http\Method;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

Expand All @@ -26,9 +27,9 @@ function it_has_a_pattern() {

function it_has_a_method() {
// must return uppercase
$this->getMethod()->shouldReturn('GET');
$this->method = 'post';
$this->getMethod()->shouldReturn('POST');
$this->getMethod()->shouldReturn(Method::GET);
$this->method = Method::POST;
$this->getMethod()->shouldReturn(Method::POST);
}

function it_has_a_uses_property() {
Expand Down
1 change: 0 additions & 1 deletion spec/Blueprint/BlueprintSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace spec\Oxygen\Core\Blueprint;

use Oxygen\Core\Action\Action;
use Oxygen\Core\Blueprint\Blueprint;;
use Oxygen\Core\Html\Toolbar\ToolbarItem;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
Expand Down
41 changes: 17 additions & 24 deletions src/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@
use Oxygen\Core\Http\Method;
use URL;

use Oxygen\Core\Html\Toolbar\ButtonToolbarItem;
use Oxygen\Core\Blueprint\Blueprint;

class Action {

const PERMISSIONS_FILTER_NAME = 'oxygen.permissions';

const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
const METHOD_ANY = 'ANY';

const REGISTER_AT_END = 'atEnd';
const REGISTER_AT_END = 'atEnd';

/**
* Pattern to match. (usually a URI)
Expand Down Expand Up @@ -110,22 +100,23 @@ class Action {
*
* @param string $name
* @param string $pattern
* @param mixed $uses
* @param Group $group
* @param mixed $uses
* @param Group $group
*/
public function __construct($name, $pattern, $uses, Group $group = null) {
$this->pattern = $pattern;
$this->name = $name;
$this->method = Method::GET;
$this->group = $group ?: new Group();
$this->middleware = [];
$this->permissions = null;
$this->uses = $uses;
$this->register = true;
$this->routeParametersCallback = function($action, array $options) {
$this->pattern = $pattern;
$this->name = $name;
$this->method = Method::GET;
$this->group = $group ?: new Group();
$this->middleware = [];
$this->permissions = null;
$this->uses = $uses;
$this->register = true;
$this->routeParametersCallback = function ($action, array $options) {
return [];
};
$this->customRouteCallback = function($action, $route) { };
$this->customRouteCallback = function ($action, $route) {
};
}

/**
Expand Down Expand Up @@ -174,6 +165,7 @@ public function getMiddleware() {
if($this->usesPermissions()) {
$middleware[] = self::PERMISSIONS_FILTER_NAME . ':' . $this->getPermissions();
}

return $middleware;
}

Expand Down Expand Up @@ -203,14 +195,15 @@ public function getPermissions() {
*/
public function getRouteParameters(array $options = []) {
$callback = $this->routeParametersCallback;

return $callback($this, $options);
}

/**
* Throws an exception when trying to set a non-existent property.
*
* @param string $variable name of the variable
* @param mixed $value value of the variable
* @param mixed $value value of the variable
* @throws Exception
*/
public function __set($variable, $value) {
Expand Down
7 changes: 4 additions & 3 deletions src/Action/AdminAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class AdminAction extends Action {
*
* @param string $name
* @param string $pattern
* @param mixed $uses
* @param Group $group
* @param mixed $uses
* @param Group $group
*/
public function __construct($name, $pattern, $uses, Group $group = null) {
parent::__construct($name, $pattern, $uses, $group);
$this->permissions = ($this->group->hasName() ? $this->group->getName() . '.' : '') . $this->name;
$this->useSmoothState = true;
$this->routeParametersCallback = function($action, array $options) {
$this->routeParametersCallback = function ($action, array $options) {
if(isset($options['model'])) {
return [
$options['model']->getId()
Expand All @@ -36,6 +36,7 @@ public function __construct($name, $pattern, $uses, Group $group = null) {
*/
public function getMiddleware() {
$middleware = [self::AUTH_MIDDLEWARE_NAME];

return array_merge($middleware, parent::getMiddleware());
}

Expand Down
8 changes: 3 additions & 5 deletions src/Action/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
namespace Oxygen\Core\Action\Factory;

use InvalidArgumentException;

use Oxygen\Core\Action\Action;
use Oxygen\Core\Action\Group;
use Oxygen\Core\Factory\FactoryInterface;

class ActionFactory implements FactoryInterface {

/**
* Creates a new Action using the passed parameters.
*
* @param array $parameters Passed parameters
* @param array $parameters Passed parameters
* @param string $controller Default controller to use if none is provided
* @return mixed
*/
Expand Down Expand Up @@ -54,8 +52,8 @@ protected function parseParameters(array $parameters, $controller) {
/**
* Sets properties on the action from an input array.
*
* @param Action $action Action to set the properties on
* @param array $properties Properties to set
* @param Action $action Action to set the properties on
* @param array $properties Properties to set
*/
protected function setProperties($action, $properties) {
unset($properties['name'], $properties['pattern'], $properties['uses'], $properties['group']);
Expand Down
4 changes: 1 addition & 3 deletions src/Action/Factory/AdminActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace Oxygen\Core\Action\Factory;

use Oxygen\Core\Action\AdminAction;
use Oxygen\Core\Action\Group;
use Oxygen\Core\Factory\FactoryInterface;

class AdminActionFactory extends ActionFactory {

/**
* Creates a new Action using the passed parameters.
*
* @param array $parameters Passed parameters
* @param array $parameters Passed parameters
* @param string $controller Default controller to use if none is provided
* @return mixed
*/
Expand Down
28 changes: 14 additions & 14 deletions src/Blueprint/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace Oxygen\Core\Blueprint;

use InvalidArgumentException;

use Oxygen\Core\Action\Action;
use Oxygen\Core\Action\Group;
use Oxygen\Core\Action\Factory\AdminActionFactory;
use Oxygen\Core\Html\Toolbar\ToolbarItem;
use Oxygen\Core\Html\Toolbar\Factory\ButtonToolbarItemFactory;
use Oxygen\Core\Form\FieldMetadata;
use Oxygen\Core\Action\Group;
use Oxygen\Core\Factory\FactoryInterface;
use Oxygen\Core\Html\Toolbar\Factory\ButtonToolbarItemFactory;
use Oxygen\Core\Html\Toolbar\ToolbarItem;
use Oxygen\Core\Support\Str;

class Blueprint {
Expand Down Expand Up @@ -134,13 +132,13 @@ public function __construct($name, $baseURI = '/') {
$this->pluralName = Str::plural($name);
$this->displayName = Str::camelToWords($name);
$this->pluralDisplayName = Str::plural(Str::camelToWords($name));
$this->controller = null;
$this->controller = null;
$this->primaryToolbarItem = null;
$this->icon = null;
$this->actions = [];
$this->icon = null;
$this->actions = [];
$this->toolbarOrders = [
'section' => [],
'item' => []
'item' => []
];
$this->toolbarItems = [];
$this->defaultActionFactory = new AdminActionFactory();
Expand Down Expand Up @@ -187,7 +185,7 @@ public function setPluralName($name) {
/**
* Set the display name of the Blueprint.
*
* @param string $name
* @param string $name
* @return void
*/
public function setDisplayName($name) {
Expand All @@ -197,7 +195,7 @@ public function setDisplayName($name) {
/**
* Set the plural display name of the Blueprint.
*
* @param string $name
* @param string $name
* @return void
*/
public function setPluralDisplayName($name) {
Expand Down Expand Up @@ -233,6 +231,7 @@ public function getPluralDisplayName() {
*/
public function getRouteName($actionName = null) {
$name = Str::camel($this->pluralName);

return $actionName == null ? $name : $name . '.' . $actionName;
}

Expand All @@ -244,6 +243,7 @@ public function getRouteName($actionName = null) {
*/
public function getRoutePattern() {
$slug = Str::slug(Str::camelToWords($this->pluralName));

return $this->baseURI !== '/' ? $this->baseURI . '/' . $slug : $slug;
}

Expand Down Expand Up @@ -371,7 +371,7 @@ public function addAction(Action $action) {
/**
* Adds an action.
*
* @param array $parameters
* @param array $parameters
* @param FactoryInterface $factory Optional FactoryInterface
* @return Action
*/
Expand Down Expand Up @@ -437,7 +437,7 @@ public function getToolbarOrder($group) {
* particular toolbar group.
*
* @param string $group
* @param array $items
* @param array $items
* @return void
*/
public function setToolbarOrder($group, $items) {
Expand Down Expand Up @@ -499,7 +499,7 @@ public function addToolbarItem(ToolbarItem $item) {
/**
* Makes a new toolbar item and adds it to the Blueprint.
*
* @param array $parameters
* @param array $parameters
* @param FactoryInterface $factory Optional FactoryInterface
* @return Action
*/
Expand Down
12 changes: 5 additions & 7 deletions src/Blueprint/BlueprintManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Oxygen\Core\Blueprint;

use DirectoryIterator;

use Illuminate\Contracts\Config\Repository as Config;
use Oxygen\Core\Contracts\CoreConfiguration;
use Oxygen\Core\Contracts\Routing\BlueprintRegistrar;
use Oxygen\Core\Html\Navigation\Navigation;

use Illuminate\Contracts\Config\Repository as Config;

class BlueprintManager {

/**
Expand Down Expand Up @@ -38,8 +36,8 @@ class BlueprintManager {
/**
* Constructs the BlueprintManager.
*
* @param \Oxygen\Core\Html\Navigation\Navigation $navigation
* @param CoreConfiguration $config
* @param \Oxygen\Core\Html\Navigation\Navigation $navigation
* @param CoreConfiguration $config
*/
public function __construct(Navigation $navigation, CoreConfiguration $config) {
$this->navigation = $navigation;
Expand Down Expand Up @@ -79,7 +77,7 @@ public function registerRoutes(BlueprintRegistrar $registrar) {
/**
* Make a new Blueprint.
*
* @param string $name display name of the blueprint
* @param string $name display name of the blueprint
* @param callable $callback
* @return void
*/
Expand Down Expand Up @@ -111,7 +109,7 @@ public function get($name) {
/**
* Edits an existing Blueprint.
*
* @param string $name display name of the blueprint
* @param string $name display name of the blueprint
* @param callable $callback
* @return void
*/
Expand Down
Loading

0 comments on commit ac4cd46

Please sign in to comment.