Skip to content
Snippets Groups Projects
Commit 03b7d7cc authored by lecluse's avatar lecluse
Browse files

Adaptation à la MAJ majeure d'UnicaenCode

parent 789ad595
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @var $this \Zend\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
*/
use UnicaenCode\Util;
$outputdir = '/tmp/entityInterfaces/';
$sIntrospection = $controller->getServiceLocator()->get('UnicaenCode\Introspection');
/* @var $sIntrospection \UnicaenCode\Service\Introspection */
$sCodeGenerator = $controller->getServiceLocator()->get('UnicaenCode\CodeGenerator');
/* @var $sCodeGenerator \UnicaenCode\Service\CodeGenerator */
$entities = $sIntrospection->getEntities();
$sCodeGenerator->setTemplate('EntityInterface');
foreach( $entities as $entity ){
$entityPath = Util::namespaceClass($entity);
$entityClass = Util::baseClassName($entity);
$entityParam = lcfirst($entityClass);
$sCodeGenerator->setParams( compact('entityPath', 'entityClass', 'entityParam') );
$sCodeGenerator->generateToFile($outputdir, $entityClass.'AwareInterface.php');
}
?>
<h1>Génération des aware interfaces de getters/setters d\'entités</h1>
Résultats dans <b><?php echo $outputdir ?></b>
\ No newline at end of file
<h1>Génération des aware traits de getters/setters d\'entités</h1>
<?php
/**
* @var $this \Zend\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
*/
use UnicaenCode\Util;
$outputdir = '/tmp/entityTraits/';
$sIntrospection = $controller->getServiceLocator()->get('UnicaenCode\Introspection');
/* @var $sIntrospection \UnicaenCode\Service\Introspection */
$sCodeGenerator = $controller->getServiceLocator()->get('UnicaenCode\CodeGenerator');
/* @var $sCodeGenerator \UnicaenCode\Service\CodeGenerator */
$entities = $sIntrospection->getEntities();
$sCodeGenerator->setTemplate('EntityTrait');
foreach( $entities as $entity ){
$entityPath = Util::namespaceClass($entity);
$entityClass = Util::baseClassName($entity);
$entityParam = lcfirst($entityClass);
$sCodeGenerator->setParams( compact('entityPath', 'entityClass', 'entityParam') );
$sCodeGenerator->generateToFile($outputdir, $entityClass.'AwareTrait.php');
}
?>
Résultats dans <b><?php echo $outputdir ?></b>
\ No newline at end of file
<h1>Génération des aware traits d\'accès aux services</h1>
<?php
/**
* @var $this \Zend\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
*/
$outputdir = '/tmp/serviceTraits/';
$sIntrospection = $controller->getServiceLocator()->get('UnicaenCode\Introspection');
/* @var $sIntrospection \UnicaenCode\Service\Introspection */
$sCodeGenerator = $controller->getServiceLocator()->get('UnicaenCode\CodeGenerator');
/* @var $sCodeGenerator \UnicaenCode\Service\CodeGenerator */
$services = $sIntrospection->getServices('Application\\Service\\', 'AbstractService');
$sCodeGenerator->setTemplate('ServiceTrait');
foreach( $services as $entityClass ){
$sCodeGenerator->setParams( compact('entityClass') );
$sCodeGenerator->generateToFile($outputdir, $entityClass.'AwareTrait.php');
}
?>
Résultats dans <b><?php echo $outputdir ?></b>
\ No newline at end of file
<?php
namespace Application\Interfaces;
use <entityPath>\<entityClass>;
/**
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
interface <entityClass>AwareInterface
{
/**
* @param <entityClass> $<entityParam>
* @return self
*/
public function set<entityClass>(<entityClass> $<entityParam> = null);
/**
* @return <entityClass>
*/
public function get<entityClass>();
}
\ No newline at end of file
<?php
namespace Application\Traits;
use <entityPath>\<entityClass>;
/**
* Description of <entityClass>AwareTrait
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
trait <entityClass>AwareTrait
{
/**
* @var <entityClass>
*/
protected $<entityParam>;
/**
* @param <entityClass> $<entityParam>
* @return self
*/
public function set<entityClass>(<entityClass> $<entityParam> = null)
{
$this-><entityParam> = $<entityParam>;
return $this;
}
/**
* @return <entityClass>
*/
public function get<entityClass>()
{
return $this-><entityParam>;
}
}
\ No newline at end of file
<?php <?php
namespace Application\Service\Traits; namespace <namespace>;
use Application\Service\<entityClass>; use <targetFullClass>;
use Application\Module; use Application\Module;
use Common\Exception\RuntimeException; use RuntimeException;
trait <entityClass>AwareTrait
{
/** /**
* description * Description of <class>
* *
* @var <entityClass> * @author UnicaenCode
*/
trait <class>
{
/**
* @var <targetClass>
*/ */
private $service<entityClass>; private $<variable>;
/** /**
* * @param <targetClass> $<variable>
* @param <entityClass> $service<entityClass>
* @return self * @return self
*/ */
public function setService<entityClass>( <entityClass> $service<entityClass> ) public function set<method>( <targetClass> $<variable> )
{ {
$this->service<entityClass> = $service<entityClass>; $this-><variable> = $<variable>;
return $this; return $this;
} }
/** /**
* * @return <targetClass>
* @return <entityClass> * @throws RuntimeException
* @throws \Common\Exception\RuntimeException
*/ */
public function getService<entityClass>() public function get<method>()
{ {
if (empty($this->service<entityClass>)){ if (empty($this-><variable>)){
$serviceLocator = Module::$serviceLocator; $serviceLocator = Module::$serviceLocator;
if (! $serviceLocator) { if (! $serviceLocator) {
if (!method_exists($this, 'getServiceLocator')) { if (!method_exists($this, 'getServiceLocator')) {
...@@ -45,10 +52,8 @@ trait <entityClass>AwareTrait ...@@ -45,10 +52,8 @@ trait <entityClass>AwareTrait
$serviceLocator = $serviceLocator->getServiceLocator(); $serviceLocator = $serviceLocator->getServiceLocator();
} }
} }
return $serviceLocator->get('application<entityClass>'); $this-><variable> = $serviceLocator->getServiceLocator('FormElementManager')->get('<name>');
}else{
return $this->service<entityClass>;
} }
return $this-><variable>;
} }
} }
\ No newline at end of file
<?php
namespace <namespace>;
use <targetFullClass>;
use Application\Module;
use RuntimeException;
/**
* Description of <class>
*
* @author UnicaenCode
*/
trait <class>
{
/**
* @var <targetClass>
*/
private $<variable>;
/**
* @param <targetClass> $<variable>
* @return self
*/
public function set<method>( <targetClass> $<variable> )
{
$this-><variable> = $<variable>;
return $this;
}
/**
* @return <targetClass>
* @throws RuntimeException
*/
public function get<method>()
{
if (empty($this-><variable>)){
$serviceLocator = Module::$serviceLocator;
if (! $serviceLocator) {
if (!method_exists($this, 'getServiceLocator')) {
throw new RuntimeException('La classe ' . get_class($this) . ' n\'a pas accès au ServiceLocator.');
}
$serviceLocator = $this->getServiceLocator();
if (method_exists($serviceLocator, 'getServiceLocator')) {
$serviceLocator = $serviceLocator->getServiceLocator();
}
}
$this-><variable> = $serviceLocator->get('<name>');
}
return $this-><variable>;
}
}
\ No newline at end of file
<?php <?php
$settings = [ $settings = [
'view-dir' => APPLICATION_PATH . '/code', 'view-dirs' => [APPLICATION_PATH . '/code'],
'template-dir' => APPLICATION_PATH . '/code/template', 'template-dirs' => [APPLICATION_PATH . '/code/template'],
]; ];
return [ return [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment