Skip to content

Commit

Permalink
Develop (#3)
Browse files Browse the repository at this point in the history
* refactoring
  • Loading branch information
n3vrax authored Mar 9, 2017
1 parent eb164c1 commit 77a8cba
Show file tree
Hide file tree
Showing 28 changed files with 380 additions and 505 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 0.1.0 - 2017-03-09

Initial tagged release

### Added
* Everything

### Deprecated
* Nothing

### Removed
* Nothing

### Fixed
* Nothing
56 changes: 26 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,40 @@ In your `config/autoload` directory, create a config file
```php
return [
'dot_navigation' => [

//enable menu item active if any child is active
'active_recursion' => true,

//map a provider name to a provider type
'providers_map' => [
'default' => \Dot\Navigation\Provider\ArrayProvider::class,
],


//map a provider name to its config
'containers' => [
'default' => [
[
'options' => [
'label' => 'Menu #1',
'route' => 'home',
'type' => 'ArrayProvider'
'options' => [
'items' => [
[
'options' => [
'label' => 'Menu #1',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
],
[
'options' => [
'label' => 'Menu #2',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
]
],
'attributes' => [
'name' => 'Menu #1',
]
],
[
'options' => [
'label' => 'Menu #2',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
]
]
],
],

//register custom providers here
'provider_manager' => [

]
'provider_manager' => [],
],
];
```
Expand Down Expand Up @@ -85,7 +82,6 @@ Each provider must implement the interface `ProviderInterface` and be registered

We offer just one provider for now, `ArrayProvider`, that is able to fetch and create a menu container from a php array that is defined in the configuration file.

When configuring the module, you'll have to associate each defined navigation container to its provider, in the `provider_map` key.

## NavigationRenderer

Expand All @@ -106,4 +102,4 @@ The following are options that each page should define in the configuration
* `label` - the text of the menu item
* `route` or `uri` - defines the route or link the menu item will have
* `params`, `query_params`, `fragment` - are all options to use with the route option, to generate the complete route, if required. These are optional.
* `permission` - can be used optionally, if authorization service is present, in order to omit menu items that are not authorized to visit.
* `permission` - can be used optionally, if authorization service is present, in order to omit menu items that are not authorized to visit.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dotkernel/dot-navigation",
"type": "library",
"description": "Navigation library for easy menu parsing",
"description": "DotKernel navigation component",
"license": "MIT",
"authors": [
{
Expand All @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.1",
"psr/http-message": "^1.0",
"container-interop/container-interop": "^1.1",
"zendframework/zend-servicemanager": "^3.1",
Expand All @@ -23,7 +23,7 @@
"squizlabs/php_codesniffer": "^2.3",

"zendframework/zend-stdlib": "^3.1",
"dotkernel/dot-authorization": "0.6.x-dev"
"dotkernel/dot-authorization": "~0.1"
},
"autoload": {
"psr-4": {
Expand All @@ -37,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.6-dev"
"dev-master": "0.2-dev"
}
}
}
61 changes: 24 additions & 37 deletions navigation.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,39 @@

return [
'dot_navigation' => [

//enable menu item active if any child is active
'active_recursion' => true,

'menu_options' => [
//depths between the menu hierarchy is iterated
'min_depth' => -1,
'max_depth' => -1,

//css classes to use for menu rendering
'active_class' => 'active',
'ul_class' => 'nav',
],

//map a provider name to a provider type
'providers_map' => [
'default' => \Dot\Navigation\Provider\ArrayProvider::class,
],

//map a provider name to its config
'containers' => [
'default' => [
[
'options' => [
'label' => 'Menu #1',
'route' => 'home',
'type' => 'ArrayProvider'
'options' => [
'items' => [
[
'options' => [
'label' => 'Menu #1',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
],
[
'options' => [
'label' => 'Menu #2',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
]
],
'attributes' => [
'name' => 'Menu #1',
]
],
[
'options' => [
'label' => 'Menu #2',
'route' => 'home',
],
'attributes' => [
'name' => 'Menu #1',
]
]
]
],
],

//register custom providers here
'provider_manager' => [

]
'provider_manager' => [],
],
];
];
42 changes: 14 additions & 28 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation;

use Dot\Navigation\Factory\NavigationMiddlewareFactory;
Expand All @@ -16,7 +18,9 @@
use Dot\Navigation\Factory\ProviderPluginManagerFactory;
use Dot\Navigation\Options\NavigationOptions;
use Dot\Navigation\Provider\ProviderPluginManager;
use Dot\Navigation\Service\Navigation;
use Dot\Navigation\Service\NavigationInterface;
use Dot\Navigation\View\NavigationRenderer;
use Dot\Navigation\View\RendererInterface;

/**
Expand All @@ -28,57 +32,39 @@ class ConfigProvider
/**
* @return array
*/
public function __invoke()
public function __invoke(): array
{
return [

'dependencies' => $this->getDependencyConfig(),

'dot_navigation' => [

'menu_options' => [

'min_depth' => -1,
'max_depth' => -1,

'active_class' => 'active',
'ul_class' => 'nav',
],

'active_recursion' => true,

'containers' => [

],

'providers_map' => [
'containers' => [],

],

'provider_manager' => [

]
'provider_manager' => []
],
];
}

/**
* @return array
*/
public function getDependencyConfig()
public function getDependencyConfig(): array
{
return [
'factories' => [
NavigationOptions::class => NavigationOptionsFactory::class,

ProviderPluginManager::class => ProviderPluginManagerFactory::class,

NavigationInterface::class => NavigationServiceFactory::class,

RendererInterface::class => NavigationRendererFactory::class,

Navigation::class => NavigationServiceFactory::class,
NavigationRenderer::class => NavigationRendererFactory::class,
NavigationMiddleware::class => NavigationMiddlewareFactory::class,
],
'aliases' => [
NavigationInterface::class => Navigation::class,
RendererInterface::class => NavigationRenderer::class,
]
];
}
}
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation\Exception;

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Factory/NavigationMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation\Factory;

use Dot\Navigation\NavigationMiddleware;
Expand All @@ -21,11 +23,12 @@ class NavigationMiddlewareFactory
{
/**
* @param ContainerInterface $container
* @param $requestedName
* @return NavigationMiddleware
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName): NavigationMiddleware
{
$navigation = $container->get(NavigationInterface::class);
return new NavigationMiddleware($navigation);
return new $requestedName($navigation);
}
}
7 changes: 5 additions & 2 deletions src/Factory/NavigationOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Time: 5:20 PM
*/

declare(strict_types = 1);

namespace Dot\Navigation\Factory;

use Dot\Navigation\Options\NavigationOptions;
Expand All @@ -20,11 +22,12 @@ class NavigationOptionsFactory
{
/**
* @param ContainerInterface $container
* @param $requestedName
* @return NavigationOptions
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName): NavigationOptions
{
$config = $container->get('config')['dot_navigation'];
return new NavigationOptions($config);
return new $requestedName($config);
}
}
Loading

0 comments on commit 77a8cba

Please sign in to comment.