Here is a code playground file I use to quickly test my code.

In playground.php (in your public folder)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

require __DIR__ . '/app/bootstrap.php';

class PlaygroundApp
    extends \Magento\Framework\App\Http
    implements \Magento\Framework\AppInterface
{
    public function launch()
    {
        // test code here   
        // must return the response
        return $this->_response;
    }

    public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
    {
        return false;
    }
}

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('PlaygroundApp');
$bootstrap->run($app);

Any class app that implements the AppInterface must implement both the launch() and catchException() functions.

The launch function must also return an object that implements the ResponseInterface (Line 13). Failing to do so will cause a fatal exception from the App/Bootstrap.php class within the run() function.

Specifically because it is the responsibility of the run() function to gather the response and then send that response to the browser.

Put your test code inside the launch() function.

Run it with php playground.php Enjoy.

Looking for a playground file for Magento 1?

<?php

require 'app/Mage.php';

if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

Mage::app('admin');

// your code here
  • magento2

Like this post? Share it :)


Related Posts

Back