| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Kunstmaan\Skylab\Skeleton; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Kunstmaan\Skylab\Entity\PermissionDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Finder\Finder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Finder\SplFileInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * ApacheSkeleton | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class PHPSkeleton extends AbstractSkeleton | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     const NAME = "php5"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function getName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         return self::NAME; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function create(\ArrayObject $project) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->fileSystemProvider->createDirectory($project, 'php-fpm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $permissionDefinition = new PermissionDefinition(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $permissionDefinition->setPath("/php-fpm"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $permissionDefinition->setOwnership("-R @project.user@[email protected]@"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             $permissionDefinition->addAcl("-R -m user::rwX"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $permissionDefinition->addAcl("-R -m group::r-X"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             $permissionDefinition->addAcl("-R -m other::---"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $permissionDefinition->addAcl("-R -m u:@config.wwwuser@:r-X"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $project["permissions"]["/php-fpm"] = $permissionDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->fileSystemProvider->createDirectory($project, 'tmp'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             $permissionDefinition = new PermissionDefinition(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $permissionDefinition->setPath("/tmp"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             $permissionDefinition->setOwnership("-R @project.user@[email protected]@"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $permissionDefinition->addAcl("-R -m user::rwX"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $permissionDefinition->addAcl("-R -m group::r-X"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $permissionDefinition->addAcl("-R -m other::---"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $permissionDefinition->addAcl("-R -m u:@config.wwwuser@:r-X"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $project["permissions"]["/tmp"] = $permissionDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->fileSystemProvider->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             "/php/nginx.d/19php.conf.twig", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/nginx.d/19php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             array() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->fileSystemProvider->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             "/php/nginx.d/10location.conf.twig", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/nginx.d/10location", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             array() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->fileSystemProvider->renderDistConfig($this->fileSystemProvider->getConfigTemplateDir("php"),$this->fileSystemProvider->getConfigTemplateDir("php", true),$this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/apache.d/"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->fileSystemProvider->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             "/php/fcron.d/01php.twig", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/fcron.d/01php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 "projectdir" => $this->fileSystemProvider->getProjectDirectory($project["name"]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function preMaintenance() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->processProvider->executeSudoCommand("rm -Rf /etc/php5/fpm/pool.d/*"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->processProvider->executeSudoCommand("rm -Rf /etc/php/7.0/fpm/pool.d/*"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function postMaintenance() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return mixed | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |     public function maintenance(\ArrayObject $project) | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $this->processProvider->executeSudoCommand("mkdir -p /etc/php5/fpm/pool.d/"); | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         $this->fileSystemProvider->render( | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |             "/php/php-fpm.conf.twig", | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |             "/etc/php5/fpm/pool.d/" . $project["name"] . ".conf", | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |             array( | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |                 "projectdir" => $this->fileSystemProvider->getProjectDirectory($project["name"]), | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                 "projectname" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |                 "projectuser" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |                 "projectgroup" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |                 "develmode" => $this->app["config"]["develmode"] | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         $this->processProvider->executeSudoCommand("mkdir -p /etc/php/7.0/fpm/pool.d/"); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |         $this->fileSystemProvider->render( | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |             "/php/php-fpm.conf.twig", | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |             "/etc/php/7.0/fpm/pool.d/" . $project["name"] . ".conf", | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             array( | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |                 "projectdir" => $this->fileSystemProvider->getProjectDirectory($project["name"]), | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |                 "projectname" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |                 "projectuser" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |                 "projectgroup" => $project["name"], | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |                 "develmode" => $this->app["config"]["develmode"] | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      *< | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     public function preBackup(\ArrayObject $project) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     public function postBackup(\ArrayObject $project) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     public function preRemove(\ArrayObject $project) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $this->processProvider->executeSudoCommand("rm -f /etc/php5/fpm/pool.d/".$project["name"].".conf"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $this->processProvider->executeSudoCommand("rm -f /etc/php/7.0/fpm/pool.d/".$project["name"].".conf"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @param \ArrayObject $project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     public function postRemove(\ArrayObject $project) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     public function dependsOn() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         return array("base", "apache", "monitoring"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 171 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 172 |  |  |  |