| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of tenside/core. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Christian Schiffler <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * This project is provided in good faith and hope to be usable by anyone. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @package    tenside/core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author     Christian Schiffler <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @copyright  2015 Christian Schiffler <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @license    https://github.com/tenside/core/blob/master/LICENSE MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @link       https://github.com/tenside/core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @filesource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | namespace Tenside\Core\SelfTest\Php; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Tenside\Core\SelfTest\AbstractSelfTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * This class tests the that the $_ENV gets populated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | class SelfTestEnvPopulated extends AbstractSelfTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * Check that Suhosin is correctly configured. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function doTest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->setMessage('Check if $_ENV is populated.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if (!$this->isConfigured()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $this->markSuccess( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'The super global $_ENV is not populated. ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'This is default and correct on production servers. ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 'However, if your processes do not work in the background, you should enable `E` in the php.ini ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 'settings `variables_order` and see if it works. ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 'Please report your findings to the developer team.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         if (!$this->isPopulated()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $this->markWarning( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 'The super global $_ENV is not populated but should have been ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 '("variables_order" in php.ini contains "E").' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->markSuccess(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Check if php.ini tells to populate. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     private function isConfigured() | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         return (strpos(ini_get('variables_order'), 'E') !== false); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * Check if Suhosin is loaded. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @SuppressWarnings(PHPMD.Superglobals) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @SuppressWarnings(PHPMD.CamelCaseVariableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     private function isPopulated() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $keys = array_keys($_ENV); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return !empty($keys); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  |