Skip to content
Snippets Groups Projects
Select Git revision
  • 0ba4e23dfa9b2ee18a2f5ffc4927b75fff99de74
  • master default protected
  • php84
  • ll-api-test
  • 6.x
  • release_6.2.0
  • modif_maintenance_phtml
  • 6.0.x
  • detached2
  • detached
  • php82
  • feature_SearchAndSelectFilter
  • 5.x
  • 4.x
  • 7.2.1
  • 7.2.0
  • 6.2.0
  • 7.1.0
  • 7.0.0
  • 1.1.1
  • 6.1.7
  • 6.1.6
  • 6.1.5
  • 6.0.16
  • 6.0.15
  • 6.1.4
  • 6.0.14
  • 6.1.3
  • 6.0.13
  • 6.1.2
  • 6.0.12
  • 6.1.1
  • 6.1.0
  • 6.0.11
34 results

Controleurs.dokuwiki

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ServiceAwareTrait.php 1.25 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('<name>');
            }
            return $this-><variable>;
        }
    }