phalcon-debugbar
phalcon-debugbar copied to clipboard
Unable to get to work with simple service provider example
I can't get the bar to work with a simple service provider example. Actually it's not entirely based on simple service provider example, but its similar, just some folder structures changed. First I tried by creating a class called DebugBarServiceProvider like so:
<?php
namespace Bootstrap\Providers;
use Snowair\Debugbar\ServiceProvider as DebugBar;
use Snowair\Debugbar\Whoops\WhoopsServiceProvider as Whoops;
/**
* \App\Providers\MvcDispatcherServiceProvider
*
* @package App\Providers
*/
class DebugBarServiceProvider extends AbstractServiceProvider
{
/**
* The Service name.
* @var string
*/
protected $serviceName = 'debugBar';
/**
* Register application service.
*
* @return void
*/
public function register()
{
error_reporting(E_ALL);
$this->di->setShared($this->serviceName, function () {
$debugBar = new DebugBar();
$debugBar->start();
new Whoops($this->di);
return $debugBar;
}
);
}
}
I have a boostrap class like that and I make sure the DI and application is setted before the debug bar
<?php
namespace Bootstrap;
use Phalcon\Config;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\DiInterface;
use Phalcon\Mvc\Application;
use Bootstrap\Providers\ServiceProviderInterface;
use Bootstrap\Providers\EventManagerServiceProvider as EventManager;
use Bootstrap\Providers\DebugBarServiceProvider;
use Snowair\Debugbar\ServiceProvider as DebugBar;
use Snowair\Debugbar\Whoops\WhoopsServiceProvider as Whoops;
class BootstrapApplication
{
/**
* The Dependency Injector.
* @var DiInterface
*/
protected $di;
/**
* The Service Providers.
* @var ServiceProviderInterface[]
*/
protected $serviceProviders = [];
/**
* The Application.
* @var Application
*/
protected $app;
/**
* Bootstrap constructor.
*
* @param $appPath
*/
public function __construct(Config $config=null)
{
$this->di = new FactoryDefault();
Di::setDefault($this->di);
$this->di->setShared('bootstrapApp', $this);
if($config) $this->di->setShared("config", $config);
$providers = include APP_PATH . '/config/providers.php';
$application = new Application($this->di);
$this->di->setShared("app", $application);
if($config->application->mode == "developtment") {
$this->initializeService(new DebugBarServiceProvider($this->di));
} elseif($config->application->mode == "maintenance") {
header("location: assets/html/maintenance.html");
exit;
}
if (is_array($providers)) {
$this->initializeServices($providers);
}
if(!array_key_exists("eventsManager", $this->di)) {
$this->initializeService(new EventManager($this->di));
$application->setEventsManager($this->di->getShared("eventsManager"));
}
$this->app = $application;
}
/**
* Gets the Dependency Injector.
*
* @return Di
*/
public function getDi()
{
return $this->di;
}
public function getContent($pathInfo=null)
{
return $this->handle($pathInfo)->getContent();
}
/**
* Runs the Application
*
* @return string
*/
public function run($pathInfo=null)
{
echo $this->handle($pathInfo)->getContent();
}
public function runAndSend($pathInfo=null)
{
$this->handle($pathInfo)->send();
}
public function handle($pathInfo=null)
{
return $this->app->handle($pathInfo);
}
/**
* Initialize Services in the Dependency Injector Container.
*
* @param string[] $providers
*/
protected function initializeServices(array $providers)
{
foreach ($providers as $name => $class) {
if(!$class instanceof DebugBarServiceProvider) {
$this->initializeService(new $class($this->di));
}
}
}
/**
* Initialize the Service in the Dependency Injector Container.
*
* @param ServiceProviderInterface $serviceProvider
*
* @return $this
*/
protected function initializeService(ServiceProviderInterface $serviceProvider)
{
$serviceProvider->register();
$this->serviceProviders[$serviceProvider->getName()] = $serviceProvider;
}
}
My issue is that nothing happens and I included the Whoops and also don't work. I setted multiple providers and most of them are the same of simple service provider, except Database and MvcDispatcherServiceProvider. After trying to initialize the debug bar as a service provider I tried to initialize directly on BootstrapApplication class and I get the following error:
Uncaught Error: Call to a member function detachAll() on null in vendor\snowair\phalcon-debugbar\src\Whoops\WhoopsServiceProvider.php:36
So I removed the Whoops temporarilly and my baseUri it's messed up. I defined a UrlServiceProvider just link simple servide provider, and my baseUri it's resolve to something like: http://mydomain.com/idr_report/, but using debugbar my uri is now public/.
I also tried to use de config/debugbar.php withou success. I checked everything else I just don't work for me. Below my environtment settings:
- PHP 7.1.5
- Phalcon 3.3.2
- IIS 8.5
- Windows Server 2012
Just to be clear past to use the debugbar I was using Whoops and everything was working fine.