This repository has been archived by the owner on Oct 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fagundes/develop
Prepare to 0.1.6
- Loading branch information
Showing
14 changed files
with
161 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: vinicius | ||
* Date: 15/03/16 | ||
* Time: 21:43 | ||
*/ | ||
|
||
namespace Zff\Base\Controller; | ||
|
||
use Zend\ServiceManager\AbstractFactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ControllerAbstractFactory implements AbstractFactoryInterface | ||
{ | ||
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | ||
{ | ||
if (class_exists($requestedName)) { | ||
$reflect = new \ReflectionClass($requestedName); | ||
if ($reflect->isSubclassOf(AbstractController::class)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function createServiceWithName( | ||
ServiceLocatorInterface $serviceLocator, | ||
$name, | ||
$requestedName | ||
) { | ||
|
||
if ($this->canCreateServiceWithName($serviceLocator, $name, $requestedName)) { | ||
$reflect = new \ReflectionClass($requestedName); | ||
$controller = $reflect->newInstance(); | ||
|
||
$forms = (array)$controller->getForms(); | ||
foreach ($forms as $customFormName => $formName) { | ||
$this->loadForm($serviceLocator, $controller, $formName, $customFormName); | ||
} | ||
|
||
$services = (array)$controller->getServices(); | ||
foreach ($services as $customServiceName => $serviceName) { | ||
$this->loadService($serviceLocator, $controller, $serviceName, $customServiceName); | ||
} | ||
|
||
return $controller; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function loadService( | ||
ServiceLocatorInterface $serviceLocator, | ||
AbstractController $controller, | ||
$serviceNeededName, | ||
$customServiceName | ||
) { | ||
|
||
if (is_int($customServiceName)) { | ||
$simpleServiceName = preg_replace('/(.*)\\\/', '', $serviceNeededName); | ||
} else { | ||
$simpleServiceName = ucfirst($customServiceName); | ||
} | ||
|
||
$methodSet = 'set' . $simpleServiceName . 'Service'; | ||
|
||
if (!method_exists($controller, $methodSet)) { | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Expected method %s::%s, to set the service %s.', | ||
get_class($controller), | ||
$methodSet, | ||
$serviceNeededName | ||
) | ||
); | ||
} | ||
|
||
$serviceNeeded = $serviceLocator->get($serviceNeededName); | ||
call_user_func([$controller,$methodSet], $serviceNeeded); | ||
} | ||
|
||
protected function loadForm( | ||
ServiceLocatorInterface $serviceLocator, | ||
AbstractController $controller, | ||
$formNeededName, | ||
$customFormName | ||
) { | ||
|
||
if (is_int($customFormName)) { | ||
$simpleServiceName = preg_replace('/(.*)\\\/', '', $formNeededName); | ||
} else { | ||
$simpleServiceName = ucfirst($customFormName); | ||
} | ||
|
||
$methodSet = 'set' . $simpleServiceName . 'Form'; | ||
|
||
if (!method_exists($controller, $methodSet)) { | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Expected method %s::%s, to set the form %s.', | ||
get_class($controller), | ||
$methodSet, | ||
$formNeededName | ||
) | ||
); | ||
} | ||
|
||
$serviceNeeded = $serviceLocator->get($formNeededName); | ||
call_user_func([$controller,$methodSet], $serviceNeeded); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -29,5 +29,4 @@ public function exchangeArray($data) | |
{ | ||
$this->configure($data); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -63,4 +63,4 @@ public function getViewHelperConfig() | |
], | ||
]; | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -91,5 +91,4 @@ public function setZ($z) | |
$this->z = $z; | ||
return $this; | ||
} | ||
|
||
} | ||
} |
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