Skip to content

Commit

Permalink
added HelperBasic
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed Jun 1, 2015
1 parent e009d46 commit f53746a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
32 changes: 32 additions & 0 deletions src/PServerCMS/Helper/HelperBasic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


namespace PServerCMS\Helper;

use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceLocatorInterface;

trait HelperBasic
{
/** @var array */
protected $serviceCache;

/**
* @return ServiceLocatorInterface
*/
abstract public function getServiceManager();

/**
* @param $serviceName
*
* @return array|object
*/
protected function getService( $serviceName )
{
if (!isset( $this->serviceCache[$serviceName] )) {
$this->serviceCache[$serviceName] = $this->getServiceManager()->get( $serviceName );
}
return $this->serviceCache[$serviceName];
}

}
8 changes: 7 additions & 1 deletion src/PServerCMS/Helper/HelperOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

trait HelperOptions
{
use HelperService;

/**
* @return \PServerCMS\Options\EntityOptions
Expand Down Expand Up @@ -39,4 +38,11 @@ protected function getGeneralOptions()
{
return $this->getService('pserver_general_options');
}

/**
* @param $serviceName
*
* @return array|object
*/
abstract function getService( $serviceName );
}
30 changes: 2 additions & 28 deletions src/PServerCMS/Helper/HelperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,9 @@

namespace PServerCMS\Helper;

use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceLocatorInterface;

trait HelperService
{
/** @var array */
protected $serviceCache;

/**
* @return ServiceLocatorInterface
*/
abstract public function getServiceManager();

/**
* @param ServiceManager $serviceManager
*
* @return $this
*/
public function setServiceManager( ServiceManager $serviceManager )
{
$this->serviceManager = $serviceManager;

return $this;
}

/**
* @return \Doctrine\ORM\EntityManager
Expand Down Expand Up @@ -129,11 +108,6 @@ protected function getSecretQuestionService()
*
* @return array|object
*/
protected function getService( $serviceName )
{
if (!isset( $this->serviceCache[$serviceName] )) {
$this->serviceCache[$serviceName] = $this->getServiceManager()->get( $serviceName );
}
return $this->serviceCache[$serviceName];
}
abstract function getService( $serviceName );

}
4 changes: 3 additions & 1 deletion src/PServerCMS/Service/InvokableBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
namespace PServerCMS\Service;

use PServerCMS\Helper\HelperOptions;
use PServerCMS\Helper\HelperService;
use PServerCMS\Helper\HelperBasic;
use SmallUser\Service\InvokableBase as UserBase;
use Zend\Form\FormInterface;

abstract class InvokableBase extends UserBase
{
use HelperOptions;
use HelperService, HelperOptions, HelperBasic;

/**
* @param $userId
Expand Down
4 changes: 3 additions & 1 deletion src/PServerCMS/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PServerCMS\Entity\UserCodes;
use PServerCMS\Entity\UserInterface;
use PServerCMS\Helper\HelperOptions;
use PServerCMS\Helper\HelperBasic;
use PServerCMS\Helper\HelperService;
use SmallUser\Entity\UserInterface as SmallUserInterface;
use PServerCMS\Entity\User as Entity;
use PServerCMS\Entity\Repository\AvailableCountries as RepositoryAvailableCountries;
Expand All @@ -23,7 +25,7 @@
*/
class User extends \SmallUser\Service\User
{
use HelperOptions;
use HelperService, HelperOptions, HelperBasic;

/**
* @param array $data
Expand Down

0 comments on commit f53746a

Please sign in to comment.