public/index.php line 5

Open in your IDE?
  1. <?php
  2. use App\Kernel;
  3. require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  4. return function (array $context) {
  5. // Function to check if we're running inside a Docker container
  6. function isRunningInDocker(): bool {
  7. return (
  8. file_exists('/.dockerenv') || // Check for Docker environment file
  9. (getenv('DOCKER_CONTAINER') !== false) || // Check for Docker environment variable
  10. strpos(file_get_contents('/proc/1/cgroup'), 'docker') !== false // Check cgroup
  11. );
  12. }
  13. // Only attempt to set permissions if we're NOT in Docker
  14. if (! isRunningInDocker()) {
  15. $basePath = dirname(__DIR__);
  16. $files = [
  17. 'env' => $basePath . '/.env',
  18. 'var' => $basePath . '/var',
  19. 'config' => $basePath . '/config',
  20. 'public' => $basePath . '/public',
  21. 'migrations' => $basePath . '/migrations',
  22. ];
  23. foreach ($files as $key => $file) {
  24. if (file_exists($file)) {
  25. try {
  26. chmod($file, 0775);
  27. } catch (\Exception $e) {
  28. // Log the error if you have a logger configured
  29. error_log("Failed to set permissions for {$key}: " . $e->getMessage());
  30. }
  31. }
  32. }
  33. }
  34. return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  35. };