Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from fagundes/develop
Browse files Browse the repository at this point in the history
Prepare to 0.1.6
  • Loading branch information
fagundes committed Mar 16, 2016
2 parents 6681a31 + 925f306 commit 686aa42
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 47 deletions.
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
'abstract_factories' => [
Form\FormAbstractFactory::class,
Form\InputFilterAbstractFactory::class,
Service\ServiceAbstractFactory::class
Service\ServiceAbstractFactory::class,
Controller\ControllerAbstractFactory::class,
],
],
];
26 changes: 26 additions & 0 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ class AbstractController extends AbstractActionController
*/
private $postedData;

/**
* @var array
*/
protected $forms;

/**
* @var array
*/
protected $services;

/**
* @return array list of forms's names
*/
public function getForms()
{
return $this->forms;
}

/**
* @return array list of service's names
*/
public function getServices()
{
return $this->services;
}

protected function getPostedData()
{
if (is_null($this->postedData)) {
Expand Down
113 changes: 113 additions & 0 deletions src/Controller/ControllerAbstractFactory.php
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);
}
}
1 change: 0 additions & 1 deletion src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public function exchangeArray($data)
{
$this->configure($data);
}

}
4 changes: 2 additions & 2 deletions src/Hydrator/DoctrineObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function handleTypeConversions($value, $typeOfField)
$dateTime->setTimestamp($value);
$value = $dateTime;
} elseif (is_string($value)) {
$value = $this->getDateFormat() ?
$value = $this->getDateFormat() ?
\DateTime::createFromFormat($this->getDateFormat(), $value) :
new DateTime($value);
}
Expand All @@ -65,4 +65,4 @@ protected function handleTypeConversions($value, $typeOfField)

return $value;
}
}
}
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ public function getViewHelperConfig()
],
];
}
}
}
4 changes: 2 additions & 2 deletions src/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ public function getPaginator(
$currentPageNumber = null,
$itemCountPerPage
= null
)
{
) {


$this->setPagination($currentPageNumber, $itemCountPerPage);
$query->setFirstResult($this->firstResult)
Expand Down
7 changes: 2 additions & 5 deletions src/Service/ServiceAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public function createServiceWithName(

$dbAdapter = $serviceLocator->get($service->getDbAdapterName());
$service->setDbAdapter($dbAdapter);
/**
* @todo lazy load here, table handler recebe o nome default mais
* nao instancia os servicos o mesmo com service
*/

$tableHandler = $serviceLocator->get(Table\TableHandler::class);
$tableHandler->setEntityManager($entityManager);
$tableHandler->setDbAdapter($dbAdapter);
Expand Down Expand Up @@ -84,7 +81,7 @@ protected function loadService(
if (!method_exists($service, $methodSet)) {
throw new \InvalidArgumentException(
sprintf(
'Espera-se o metodo %s::%s, para carregar o serviço %s.',
'Expected method %s::%s, to set the service %s.',
get_class($service),
$methodSet,
$serviceNeededName
Expand Down
27 changes: 2 additions & 25 deletions src/Service/Table/TableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

namespace Zff\Base\Service\Table;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\Parameters;
use ZfTable\AbstractTable;

class TableHandler implements ServiceLocatorAwareInterface
class TableHandler
{

/**
Expand All @@ -25,29 +23,11 @@ class TableHandler implements ServiceLocatorAwareInterface
*/
protected $dbAdapter;

/**
* @var ServiceLocatorInterface
*/
protected $serviceLocator;

public function getServiceLocator()
{
return $this->serviceLocator;
}

public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}

/**
* @return \Zend\Db\Adapter\Adapter
*/
public function getDbAdapter()
{
if (!$this->dbAdapter) {
$this->dbAdapter = $this->getServiceLocator()->get('zfdb_adapter');
}
return $this->dbAdapter;
}

Expand All @@ -62,10 +42,7 @@ public function setDbAdapter(\Zend\Db\Adapter\Adapter $dbAdapter)
*/
public function getEntityManager()
{
if (!$this->em) {
$this->em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
}
return $this->em;
return $this->entityManager;
}

public function setEntityManager(\Doctrine\ORM\EntityManager $entityManager)
Expand Down
2 changes: 1 addition & 1 deletion src/Util/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class File

public static function rmdirRecursive($dir)
{
if(!file_exists($dir)) {
if (!file_exists($dir)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/FileMoverTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ protected function updateFile(&$oldFilePath, $newFileSourceInfo, $newFileDestPat
$this->moveFile($oldFilePath, $newFileSourceInfo, $newFileDestPath);
}
}
}
}
5 changes: 3 additions & 2 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function testConfig()
$this->assertEquals($configArr, $this->module->getConfig());
}

public function testAutoloader() {
public function testAutoloader()
{
$this->assertNotEmpty($this->module->getAutoloaderConfig());
}
}
}
3 changes: 1 addition & 2 deletions test/Util/Assets/ConfigurableClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ public function setZ($z)
$this->z = $z;
return $this;
}

}
}
9 changes: 5 additions & 4 deletions test/Util/Assets/FileMoverClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ public function moveAllFiles()
$this->moveFile($this->filepathTwo, $this->filepathTwoInfo, 'test/data/upload/otherplace');
}

public function removeAllFiles() {
public function removeAllFiles()
{
$this->removeFile($this->filepathOne);
$this->removeFile($this->filepathTwo);
}

public function updateAllFiles() {
public function updateAllFiles()
{
$this->updateFile($this->filepathOne, $this->filepathOneInfo, 'test/data/upload');
$this->updateFile($this->filepathTwo, $this->filepathTwoInfo, 'test/data/upload/otherplace');
}

}
}

0 comments on commit 686aa42

Please sign in to comment.