github.com/symfony-cli/symfony-cli@v0.0.0-20240514161054-ece2df437dfa/local/php/php_builtin_server.go (about)

     1  /*
     2   * Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com>
     3   *
     4   * This file is part of Symfony CLI project
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU Affero General Public License as
     8   * published by the Free Software Foundation, either version 3 of the
     9   * License, or (at your option) any later version.
    10   *
    11   * This program is distributed in the hope that it will be useful,
    12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14   * GNU Affero General Public License for more details.
    15   *
    16   * You should have received a copy of the GNU Affero General Public License
    17   * along with this program. If not, see <http://www.gnu.org/licenses/>.
    18   */
    19  
    20  package php
    21  
    22  import (
    23  	"fmt"
    24  	"os"
    25  	"path/filepath"
    26  )
    27  
    28  var phprouter = []byte(`<?php
    29  /*
    30   * This file is part of the Symfony package.
    31   *
    32   * (c) Fabien Potencier <fabien@symfony.com>
    33   *
    34   * For the full copyright and license information, please view the LICENSE
    35   * file that was distributed with this source code.
    36   */
    37  
    38  // Workaround https://bugs.php.net/64566
    39  if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) {
    40      require ini_get('auto_prepend_file');
    41  }
    42  
    43  if (isset($_SERVER['HTTP___SYMFONY_LOCAL_REQUEST_ID__'])) {
    44  if (file_exists($envFile = __FILE__.'-'.$_SERVER['HTTP___SYMFONY_LOCAL_REQUEST_ID__'].'-env')) {
    45  		require $envFile;
    46  	}
    47  	unset($_SERVER['HTTP___SYMFONY_LOCAL_REQUEST_ID__']);
    48  }
    49  
    50  if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
    51  	return false;
    52  }
    53  
    54  $script = $_ENV['APP_FRONT_CONTROLLER'];
    55  $_SERVER = array_merge($_SERVER, $_ENV);
    56  $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$script;
    57  $_SERVER['SCRIPT_NAME'] = DIRECTORY_SEPARATOR.$script;
    58  $_SERVER['PHP_SELF'] = DIRECTORY_SEPARATOR.$script;
    59  
    60  require $script;
    61  `)
    62  
    63  func (p *Server) phpRouterFile() string {
    64  	path := filepath.Join(p.homeDir, fmt.Sprintf("php/%s-router.php", name(p.projectDir)))
    65  	if _, err := os.Stat(filepath.Dir(path)); os.IsNotExist(err) {
    66  		_ = os.MkdirAll(filepath.Dir(path), 0755)
    67  	}
    68  	return path
    69  }