Skip to content
Snippets Groups Projects
Select Git revision
  • ca7e11b1f3849ce7613a330b863563a9dd47d693
  • master default protected
  • 5.x
  • ll-php8-bs5
  • release_5_bs5
  • ll-php8
  • 4.x
  • laminas_migration
  • release_1.0.0.2
  • release_4.0.0
  • release_3.2.8
  • bootstrap4_migration
  • 1.0.0.3
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.1.1
  • 6.0.0
  • 5.1.0
  • 5.0.0
  • 4.0.2
  • 3.2.11
  • 4.0.1
  • 3.2.10
  • 4.0.0
  • 1.0.0.2
  • 3.2.9
  • 3.2.8
32 results

Module.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    FormAwareTrait.php 1.35 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;
        }
    
    
    
        /**
         * Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement.
         *
         * @return <targetClass>
         * @throws RuntimeException
         */
        public function get<method>()
        {
            if (!empty($this-><variable>)){
                return $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();
                }
            }
            return $serviceLocator->get('FormElementManager')->get('<name>');
        }
    }