This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'SpiffyJr/feature/navigation-service-fac…
…tory'
- Loading branch information
68 parents
47eb5a8
+
a36e34a
+
3e520ad
+
7b0d374
+
461c28b
+
3890e69
+
316384e
+
1431343
+
debad5a
+
1680741
+
4497a00
+
bb6633a
+
6b7ed03
+
35fcae3
+
0737e9d
+
c31bf4c
+
918649e
+
ecbe771
+
b4124fc
+
f4e1da0
+
a8c70a8
+
50d3c5d
+
79180fa
+
f6f9386
+
8ed6590
+
d79a4a4
+
3958052
+
eae6146
+
1cc7a46
+
1d9542f
+
a22d6e2
+
3496b67
+
9398e77
+
687d980
+
900dc7d
+
21f6363
+
0eeb6ff
+
8c442a3
+
adf1f8e
+
c2ceb18
+
9b17a1c
+
d5dab4a
+
346a62a
+
9808633
+
bdeec54
+
1a2506a
+
f5f3d02
+
b623064
+
4338bf4
+
bdababf
+
4054000
+
4449c16
+
d3d8b33
+
8427cf8
+
8d162ec
+
a988e9a
+
3e9d597
+
ee93c08
+
9d3ce53
+
f04a59c
+
0c3f2de
+
a654383
+
502d937
+
93350ca
+
23a0ccc
+
15dc071
+
6ca79e9
+
9a70b3d
commit a55ead5
Showing
12 changed files
with
419 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace Zend\Navigation\Service; | ||
|
||
use Zend\Config; | ||
use Zend\Navigation\Exception; | ||
use Zend\Navigation\Navigation; | ||
use Zend\Navigation\Page\Mvc as MvcPage; | ||
use Zend\Mvc\Router\RouteMatch; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use Zend\View\Helper\Url as UrlHelper; | ||
|
||
abstract class AbstractNavigationFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $pages; | ||
|
||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$pages = $this->getPages($serviceLocator); | ||
return new Navigation($pages); | ||
} | ||
|
||
abstract protected function getName(); | ||
|
||
protected function getPages(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
if (null === $this->pages) { | ||
$configuration = $serviceLocator->get('Configuration'); | ||
|
||
if (!isset($configuration['navigation'])) { | ||
throw new Exception\InvalidArgumentException('Could not find navigation configuration key'); | ||
} | ||
if (!isset($configuration['navigation'][$this->getName()])) { | ||
throw new Exception\InvalidArgumentException(sprintf( | ||
'Failed to find a navigation container by the name "%s"', | ||
$this->getName() | ||
)); | ||
} | ||
|
||
$application = $serviceLocator->get('Application'); | ||
$urlHelper = $serviceLocator->get('ViewHelperBroker')->load('url'); | ||
$routeMatch = $application->getMvcEvent()->getRouteMatch(); | ||
$pages = $this->getPagesFromConfig($configuration['navigation'][$this->getName()]); | ||
|
||
$this->pages = $this->injectComponents($pages, $routeMatch, $urlHelper); | ||
} | ||
return $this->pages; | ||
} | ||
|
||
protected function getPagesFromConfig($config = null) | ||
{ | ||
if (is_string($config)) { | ||
if (file_exists($config)) { | ||
$config = Config\Factory::fromFile($config); | ||
} else { | ||
throw new Exception\InvalidArgumentException(sprintf( | ||
'Config was a string but file "%s" does not exist', | ||
$config | ||
)); | ||
} | ||
} else if ($config instanceof Config\Config) { | ||
$config = $config->toArray(); | ||
} else if (!is_array($config)) { | ||
throw new Exception\InvalidArgumentException(' | ||
Invalid input, expected array, filename, or Zend\Config object' | ||
); | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
protected function injectComponents($pages, RouteMatch $routeMatch, UrlHelper $urlHelper) | ||
{ | ||
foreach($pages as &$page) { | ||
$hasMvc = isset($page['action']) || isset($page['controller']) || isset($page['route']); | ||
if ($hasMvc) { | ||
if (!isset($page['routeMatch'])) { | ||
$page['routeMatch'] = $routeMatch; | ||
} | ||
if (!isset($page['urlHelper'])) { | ||
$page['urlHelper'] = $urlHelper; | ||
} | ||
} | ||
|
||
if (isset($page['pages'])) { | ||
$page['pages'] = $this->injectComponents($page['pages'], $routeMatch, $urlHelper); | ||
} | ||
} | ||
return $pages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Zend\Navigation\Service; | ||
|
||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ConstructedNavigationFactory extends AbstractNavigationFactory | ||
{ | ||
public function __construct($config) | ||
{ | ||
$this->pages = $this->getPagesFromConfig($config); | ||
} | ||
|
||
public function getPages(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
return $this->pages; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'constructed'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Zend\Navigation\Service; | ||
|
||
class DefaultNavigationFactory extends AbstractNavigationFactory | ||
{ | ||
protected function getName() | ||
{ | ||
return 'default'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.