protected function wp(Closure $cmd)
    {
        $cmd = new ReflectionFunction($cmd);
        $code = implode(array_slice(file($cmd->getFileName()), ($startLine = $cmd->getStartLine() - 1), $cmd->getEndLine() - $startLine));
        
        preg_match('/\\{(.*)\\}/s', $code, $body);
        
        $vars = $cmd->getStaticVariables();
        $cmd = trim(preg_replace_callback('/return(?:;|\s((?:[^;(]*(?:\(.*\))?)+);)/s', function ($matches) {
            if (! empty($matches[1])) {
                return "return print 'OUTPUT>>>' . serialize({$matches[1]});";
            }
            
            return "return print 'OUTPUT>>>' . serialize(null);";
        }, $body[1]));
        
        $config = [
            '__host' => env('DB_HOST', 'localhost'),
            '__name' => env('DB_NAME', 'homestead'),
            '__user' => env('DB_USER', 'homestead'),
            '__pass' => env('DB_PASS', 'secret'),
            '__abspath' => $this->plugin->getPublicDirectory() . '/wp/',
            '__wp' => dirname(__FILE__) . '/wordpress.php',
        ];
        
        $config = serialize($config);
        $vars = serialize($vars);
        
        $p = new PhpProcess("<?php
            extract(unserialize('$config'));
            
            try {
                \$db = new PDO('mysql:host=' . \$__host . ';dbname=' . \$__name, \$__user, \$__pass);
            } catch (PDOException \$e) {
                if (\$__host == 'localhost') {
                    \$__host = '127.0.0.1';
                }
                
                \$db = new PDO('mysql:host=' . \$__host . ';port=33060;dbname=' . \$__name, \$__user, \$__pass);
                
                \$__host = \$__host . ':33060';
            } catch (PDOException \$e) {
                return;
            }
            
            define('DB_HOST', \$__host);
            define('ABSPATH', \$__abspath);
            
            \$_SERVER = [
                'HTTP_HOST' => 'http://mysite.com',
                'SERVER_NAME' => 'http://mysite.com',
                'REQUEST_URI' => '/',
                'REQUEST_METHOD' => 'GET'
            ];
            
            //require the WP bootstrap
            require_once ABSPATH . '/wp-admin/includes/plugin.php';
            require_once ABSPATH . '/wp-load.php';
            
            extract(unserialize('$vars'));
            $cmd
            ");
        
        $p->run();
        
        if (preg_match('/OUTPUT>>>(.*)$/s', $p->getOutput(), $matches)) {
            return unserialize($matches[1]);
        }
    }
protected function wp(Closure $cmd)
    {
        $cmd = new ReflectionFunction($cmd);
        $code = implode(array_slice(file($cmd->getFileName()), ($startLine = $cmd->getStartLine() - 1), $cmd->getEndLine() - $startLine));
        
        preg_match('/\\{(.*)\\}/s', $code, $body);
        
        $vars = $cmd->getStaticVariables();
        $cmd = trim(preg_replace_callback('/return(?:;|\s((?:[^;(]*(?:\(.*\))?)+);)/s', function ($matches) {
            if (! empty($matches[1])) {
                return "return print 'OUTPUT>>>' . serialize({$matches[1]});";
            }
            
            return "return print 'OUTPUT>>>' . serialize(null);";
        }, $body[1]));
        
        $config = [
            '__host' => env('DB_HOST', 'localhost'),
            '__name' => env('DB_NAME', 'homestead'),
            '__user' => env('DB_USER', 'homestead'),
            '__pass' => env('DB_PASS', 'secret'),
            '__abspath' => $this->plugin->getPublicDirectory() . '/wp/',
            '__wp' => dirname(__FILE__) . '/wordpress.php',
        ];
        
        $config = serialize($config);
        $vars = serialize($vars);
        
        $p = new PhpProcess("<?php
            extract(unserialize('$config'));
            
            try {
                \$db = new PDO('mysql:host=' . \$__host . ';dbname=' . \$__name, \$__user, \$__pass);
            } catch (PDOException \$e) {
                if (\$__host == 'localhost') {
                    \$__host = '127.0.0.1';
                }
                
                \$db = new PDO('mysql:host=' . \$__host . ';port=33060;dbname=' . \$__name, \$__user, \$__pass);
                
                \$__host = \$__host . ':33060';
            } catch (PDOException \$e) {
                return;
            }
            
            define('DB_HOST', \$__host);
            define('ABSPATH', \$__abspath);
            
            \$_SERVER = [
                'HTTP_HOST' => 'http://mysite.com',
                'SERVER_NAME' => 'http://mysite.com',
                'REQUEST_URI' => '/',
                'REQUEST_METHOD' => 'GET'
            ];
            
            //require the WP bootstrap
            require_once ABSPATH . '/wp-admin/includes/plugin.php';
            require_once ABSPATH . '/wp-load.php';
            
            extract(unserialize('$vars'));
            $cmd
            ");
        
        $p->run();
        
        if (preg_match('/OUTPUT>>>(.*)$/s', $p->getOutput(), $matches)) {
            return unserialize($matches[1]);
        }
    }
protected function wp ( Closure $ cmd ) { $ cmd = new ReflectionFunction ( $ cmd ) ; $ code = implode ( array_slice ( file ( $ cmd -> getFileName ( ) ) , ( $ startLine = $ cmd -> getStartLine ( ) - 1 ) , $ cmd -> getEndLine ( ) - $ startLine ) ) ; preg_match ( '/\\{(.*)\\}/s' , $ code , $ body ) ; $ vars = $ cmd -> getStaticVariables ( ) ; $ cmd = trim ( preg_replace_callback ( '/return(?:;|\s((?:[^;(]*(?:\(.*\))?)+);)/s' , function ( $ matches ) { if ( ! empty ( $ matches [ 1 ] ) ) { return "return print 'OUTPUT>>>' . serialize({$matches[1]});" ; } return "return print 'OUTPUT>>>' . serialize(null);" ; } , $ body [ 1 ] ) ) ; $ config = [ '__host' => env ( 'DB_HOST' , 'localhost' ) , '__name' => env ( 'DB_NAME' , 'homestead' ) , '__user' => env ( 'DB_USER' , 'homestead' ) , '__pass' => env ( 'DB_PASS' , 'secret' ) , '__abspath' => $ this -> plugin -> getPublicDirectory ( ) . '/wp/' , '__wp' => dirname ( __FILE__ ) . '/wordpress.php' , ] ; $ config = serialize ( $ config ) ; $ vars = serialize ( $ vars ) ; $ p = new PhpProcess ( "<?php
            extract(unserialize('$config'));
            
            try {
                \$db = new PDO('mysql:host=' . \$__host . ';dbname=' . \$__name, \$__user, \$__pass);
            } catch (PDOException \$e) {
                if (\$__host == 'localhost') {
                    \$__host = '127.0.0.1';
                }
                
                \$db = new PDO('mysql:host=' . \$__host . ';port=33060;dbname=' . \$__name, \$__user, \$__pass);
                
                \$__host = \$__host . ':33060';
            } catch (PDOException \$e) {
                return;
            }
            
            define('DB_HOST', \$__host);
            define('ABSPATH', \$__abspath);
            
            \$_SERVER = [
                'HTTP_HOST' => 'http://mysite.com',
                'SERVER_NAME' => 'http://mysite.com',
                'REQUEST_URI' => '/',
                'REQUEST_METHOD' => 'GET'
            ];
            
            //require the WP bootstrap
            require_once ABSPATH . '/wp-admin/includes/plugin.php';
            require_once ABSPATH . '/wp-load.php';
            
            extract(unserialize('$vars'));
            $cmd
            " ) ; $ p -> run ( ) ; if ( preg_match ( '/OUTPUT>>>(.*)$/s' , $ p -> getOutput ( ) , $ matches ) ) { return unserialize ( $ matches [ 1 ] ) ; } }
Run a closure in the WordPress environment.

@param  closure  $cmd
@return mixed
Run a closure in the WordPress environment .