From 31fd6832fcf4101b4ea6dbddf43a95fcfc88e3a0 Mon Sep 17 00:00:00 2001 From: lchampel Date: Mon, 21 Mar 2016 14:34:03 +0100 Subject: [PATCH] correction pour initialisation kernel symfony en mode prod sans le debug --- sources/wordpress/sf2/sf2plugin.php | 61 +++++++++++++++-------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/sources/wordpress/sf2/sf2plugin.php b/sources/wordpress/sf2/sf2plugin.php index cc77899..39ded69 100755 --- a/sources/wordpress/sf2/sf2plugin.php +++ b/sources/wordpress/sf2/sf2plugin.php @@ -8,20 +8,21 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class Sf2Plugin { +class Sf2Plugin +{ private $container = null; private $kernel = null; private $in_sf2 = true; private function isValidSymfonyPath($dir) { - return (file_exists($dir.'var/bootstrap.php.cache')); + return (file_exists($dir . 'var/bootstrap.php.cache')); } private function calculatePath() { $dir = __DIR__; - if (($pos = strpos($dir, 'vendor'))!==false) { + if (($pos = strpos($dir, 'vendor')) !== false) { //Lien symbolique dans les vendor $dir = substr($dir, 0, $pos); @@ -29,7 +30,7 @@ private function calculatePath() return null; } return $dir; - } elseif (($pos=strpos($dir, 'wordpress/wp-content'))!==false) { + } elseif (($pos = strpos($dir, 'wordpress/wp-content')) !== false) { $dir = substr($dir, 0, $pos); if (!$this->isValidSymfonyPath($dir)) { return null; @@ -40,14 +41,13 @@ private function calculatePath() private function calculateUrl() { - $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if (($pos = strpos($url, 'wordpress/wp-admin')) != false) { - $url = substr($url, 0, $pos).'web/app_dev.php'; + $url = substr($url, 0, $pos) . 'web/app_dev.php'; } return $url; } - private function loadSf2() { global $kernel; @@ -58,16 +58,19 @@ private function loadSf2() $url = (get_option('symfony2_url')); if (!$this->isValidSymfonyPath($path)) { - add_action( 'admin_footer', array( $this, 'symfony2_warning' ) ); + add_action('admin_footer', array($this, 'symfony2_warning')); return; } - - if ($kernel==null) { - $loader = require_once $path.'var/bootstrap.php.cache'; - $autoload= require_once $path.'app/autoload.php'; - require_once $path.'app/AppKernel.php'; - $kernel = new AppKernel($env, true); + if ($kernel == null) { + $loader = require_once $path . 'var/bootstrap.php.cache'; + $autoload = require_once $path . 'app/autoload.php'; + require_once $path . 'app/AppKernel.php'; + $debug = true; + if ($env == 'prod') { + $debug = false; + } + $kernel = new AppKernel($env, $debug); $kernel->loadClassCache(); $kernel->boot(); $this->kernel = $kernel; @@ -75,7 +78,7 @@ private function loadSf2() if ($this->container->get('session')->isStarted() == false) { $this->container->get('session')->start(); } - if ($url!=null) { + if ($url != null) { $this->overloadUrlContext($url); } } else { @@ -84,7 +87,7 @@ private function loadSf2() } $wp_loader = $this->container->get('wordpress.loader'); $wp_loader->load(); - + $request = Request::createFromGlobals(); $response = new Response(); $kernel->terminate($request, $response); @@ -94,13 +97,13 @@ private function loadSf2() private function overloadUrlContext($url) { preg_match('%([^:]*):\/\/([^\/]*)(\/?.*)%', $url, $matches); - if (count($matches)==4) { + if (count($matches) == 4) { $context = $this->container->get('router')->getContext(); $context->setHost($matches[2]); $context->setScheme($matches[1]); $context->setBaseUrl($matches[3]); } else { - add_action( 'admin_footer', array( $this, 'symfony2_url_warning' ) ); + add_action('admin_footer', array($this, 'symfony2_url_warning')); } } @@ -126,7 +129,7 @@ public function __construct() { //register_activation_hook( __FILE__, array($this, 'activate')); add_action('activate_sf2/sf2plugin.php', array($this, 'activate')); - add_action('admin_menu', array ($this, 'menu_params') ); + add_action('admin_menu', array($this, 'menu_params')); add_action('admin_init', array($this, 'admin_init')); $this->loadSf2(); @@ -135,13 +138,13 @@ public function __construct() public function activate() { - if (get_option('symfony2_path')==null) { + if (get_option('symfony2_path') == null) { update_option('symfony2_path', $this->calculatePath()); } - if (get_option('symfony2_env')==null) { + if (get_option('symfony2_env') == null) { update_option('symfony2_env', 'dev'); } - if (get_option('symfony2_url')==null) { + if (get_option('symfony2_url') == null) { update_option('symfony2_url', $this->calculateUrl()); } @@ -150,10 +153,10 @@ public function activate() public function admin_init() { //add_management_page( 'Custom Permalinks', 'Custom Permalinks', 'manage_options', 'my-unique-identifier', 'custom_permalinks_options_page' ); - if ($this->container!=null) { + if ($this->container != null) { $shortcodes = $this->getContainer()->get('wordpress.loader')->getShortcodes(); foreach ($shortcodes as $shortcode) { - register_setting('wp_symfony_settings', 'shortcode_'.$shortcode->getName()); + register_setting('wp_symfony_settings', 'shortcode_' . $shortcode->getName()); } } register_setting('wp_symfony_settings', 'symfony2_path'); @@ -163,21 +166,21 @@ public function admin_init() public function menu_params() { - add_options_page( 'Symfony2 configuration','Symfony2','manage_options','options_symfony2', array( $this, 'settings_symfony2' ) ); + add_options_page('Symfony2 configuration', 'Symfony2', 'manage_options', 'options_symfony2', array($this, 'settings_symfony2')); //add_menu_page('Symfony2 configuration', 'Symfony2', 'manage_options', 'symfony2_options', array($this, 'menu_params_page'), plugins_url( 'sf2/images/icon.png' ), 6 ); } public function settings_symfony2() { - include(dirname(__FILE__).'/settings.php'); + include dirname(__FILE__) . '/settings.php'; } public function menu_params_page() { - if ($this->container!=null) { + if ($this->container != null) { $shortcodes = $this->getContainer()->get('wordpress.loader')->getShortcodes(); } - include(dirname(__FILE__).'/settings.php'); + include dirname(__FILE__) . '/settings.php'; } public function get($id) @@ -186,6 +189,4 @@ public function get($id) } } - - $sf2plugin = new Sf2Plugin();