/** * Loads a specific configuration. * * @param array $configs An array of configuration values * @param ContainerBuilder $container A ContainerBuilder instance * * @throws \InvalidArgumentException When provided tag is not defined in this extension */ public function load(array $configs, ContainerBuilder $container) { $filesystem = new \phpbb\filesystem\filesystem(); $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($this->config_path))); $loader->load($container->getParameter('core.environment') . '/container/environment.yml'); $config = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($config, $configs); if ($config['require_dev_dependencies']) { if (!class_exists('Goutte\\Client', true)) { trigger_error('Composer development dependencies have not been set up for the ' . $container->getParameter('core.environment') . ' environment yet, run ' . "'php ../composer.phar install --dev' from the phpBB directory to do so.", E_USER_ERROR); } } // Set the Twig options if defined in the environment $definition = $container->getDefinition('template.twig.environment'); $twig_environment_options = $definition->getArgument(7); if ($config['twig']['debug']) { $twig_environment_options['debug'] = true; } if ($config['twig']['auto_reload']) { $twig_environment_options['auto_reload'] = true; } // Replace the 8th argument, the options passed to the environment $definition->replaceArgument(7, $twig_environment_options); if ($config['twig']['enable_debug_extension']) { $definition = $container->getDefinition('template.twig.extensions.debug'); $definition->addTag('twig.extension'); } // Set the debug options foreach ($config['debug'] as $name => $value) { $container->setParameter('debug.' . $name, $value); } }
public function realpath_resolve_relative_without_symlinks_data() { if (!function_exists('getcwd')) { return array(); } $filesystem = new \phpbb\filesystem\filesystem(); $relative_path = $filesystem->make_path_relative(__DIR__, getcwd()); return array(array($relative_path, __DIR__), array($relative_path . '../filesystem/../filesystem', __DIR__), array($relative_path . '././', __DIR__), array($relative_path . 'realpath_test.php', __FILE__)); }
public function test_includephp_absolute() { global $phpbb_root_path; $filesystem = new \phpbb\filesystem\filesystem(); $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc'; $this->assertTrue($filesystem->is_absolute_path($path_to_php)); $template_text = "Path is absolute.\n<!-- INCLUDEPHP {$path_to_php} -->"; $cache_dir = $phpbb_root_path . 'cache/'; $fp = fopen($cache_dir . 'includephp_absolute.html', 'w'); fputs($fp, $template_text); fclose($fp); $this->setup_engine(array('tpl_allow_php' => true)); $this->template->set_custom_style('tests', $cache_dir); $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_absolute.html')); $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); }
/** * Removes absolute path to phpBB root directory from error messages * and converts backslashes to forward slashes. * * @param string $errfile Absolute file path * (e.g. /var/www/phpbb3/phpBB/includes/functions.php) * Please note that if $errfile is outside of the phpBB root, * the root path will not be found and can not be filtered. * @return string Relative file path * (e.g. /includes/functions.php) */ function phpbb_filter_root_path($errfile) { global $phpbb_filesystem; static $root_path; if (empty($root_path)) { if ($phpbb_filesystem) { $root_path = $phpbb_filesystem->realpath(dirname(__FILE__) . '/../'); } else { $filesystem = new \phpbb\filesystem\filesystem(); $root_path = $filesystem->realpath(dirname(__FILE__) . '/../'); } } return str_replace(array($root_path, '\\'), array('[ROOT]', '/'), $errfile); }
// available as used by the redirect function $server_name = !empty($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : (!empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME')); $server_port = !empty($_SERVER['SERVER_PORT']) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'); $secure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 1 : 0; $script_name = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF'); if (!$script_name) { $script_name = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI'); } // $phpbb_root_path accounts for redirects from e.g. /adm $script_path = trim(dirname($script_name)) . '/' . $phpbb_root_path . 'install/app.' . $phpEx; // Replace any number of consecutive backslashes and/or slashes with a single slash // (could happen on some proxy setups and/or Windows servers) $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path); // Eliminate . and .. from the path require $phpbb_root_path . 'phpbb/filesystem.' . $phpEx; $phpbb_filesystem = new phpbb\filesystem\filesystem(); $script_path = $phpbb_filesystem->clean_path($script_path); $url = ($secure ? 'https://' : 'http://') . $server_name; if ($server_port && ($secure && $server_port != 443 || !$secure && $server_port != 80)) { // HTTP HOST can carry a port number... if (strpos($server_name, ':') === false) { $url .= ':' . $server_port; } } $url .= $script_path; header('Location: ' . $url); exit; } // In case $phpbb_adm_relative_path is not set (in case of an update), use the default. $phpbb_adm_relative_path = isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/'; $phpbb_admin_path = defined('PHPBB_ADMIN_PATH') ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path;
protected function load_services(ContainerBuilder $container) { $filesystem = new \phpbb\filesystem\filesystem(); $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($this->ext_path))); $loader->load('environment.yml'); }
/** * Loads the services.yml file. * * @param ContainerBuilder $container A ContainerBuilder instance */ protected function load_services(ContainerBuilder $container) { $services_directory = false; $services_file = false; if (file_exists($this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/environment.yml')) { $services_directory = $this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/'; $services_file = 'environment.yml'; } else { if (!is_dir($this->ext_path . 'config/' . $container->getParameter('core.environment'))) { if (file_exists($this->ext_path . 'config/default/container/environment.yml')) { $services_directory = $this->ext_path . 'config/default/container/'; $services_file = 'environment.yml'; } else { if (!is_dir($this->ext_path . 'config/default') && file_exists($this->ext_path . '/config/services.yml')) { $services_directory = $this->ext_path . 'config'; $services_file = 'services.yml'; } } } } if ($services_directory && $services_file) { $filesystem = new \phpbb\filesystem\filesystem(); $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($services_directory))); $loader->load($services_file); } }