| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the PommProject/ModelManager package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) 2014 - 2015 Grégoire HUBERT <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace PommProject\ModelManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PommProject\Foundation\Client\ClientHolder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PommProject\Foundation\Session as FoundationSession; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PommProject\Foundation\Session\Connection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PommProject\Foundation\Session\Session; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PommProject\Foundation\SessionBuilder as FoundationSessionBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use PommProject\ModelManager\Model\ModelPooler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use PommProject\ModelManager\ModelLayer\ModelLayerPooler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use PommProject\ModelManager\Session as ModelManagerSession; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * SessionBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * Session builder for the ModelManager package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @package   ModelManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @copyright 2014 - 2015 Grégoire HUBERT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @author    Grégoire HUBERT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @license   X11 {@link http://opensource.org/licenses/mit-license.php} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @see       FoundationSessionBuilder | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | class SessionBuilder extends FoundationSessionBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * postConfigure | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * Register ModelManager's poolers. | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * @access protected | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @param  Session          $session | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @return SessionBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     protected function postConfigure(Session $session) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         parent::postConfigure($session); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->registerClientPooler(new ModelPooler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->registerClientPooler(new ModelLayerPooler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * createSession | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * @param Connection   $connection | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @param ClientHolder $client_holder | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @param null|string  $stamp | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @return  ModelManagerSession | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * @see     VanillaSessionBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected function createSession(Connection $connection, ClientHolder $client_holder, $stamp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->configuration->setDefaultValue('class:session', '\PommProject\ModelManager\Session'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return parent::createSession($connection, $client_holder, $stamp); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  | 
            
                        
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: