Skip to content
Snippets Groups Projects
Select Git revision
  • 15e07cff3dbb4f3a083bb5af245fc1cc5acc92af
  • master default protected
  • subtemplate
  • release_7.0.6
  • php84
  • 6.x
  • v5.x-test
  • 5x
  • 7.1.0
  • 7.0.6
  • 7.0.5
  • 7.0.4
  • 7.0.3
  • 7.0.2
  • 7.0.1
  • 7.0.0
  • 6.1.7
  • 6.1.6
  • 6.1.5
  • 6.1.4
  • 6.1.3
  • 6.1.2
  • 6.1.1
  • 6.1.0
  • 6.0.3
  • 6.0.2
  • 5.0.6
  • 6.0.1
28 results

IndexControllerFactory.php

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    HydratorAwareTrait.php 1.23 KiB
    <?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('HydratorManager')->get('<name>');
            }
            return $this-><variable>;
        }
    }