PHP code example of dreamcommerce / bugtracker-bundle
1. Go to this page and download the library: Download dreamcommerce/bugtracker-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dreamcommerce / bugtracker-bundle example snippets
use Psr\Log\LogLevel;
// use all collectors
try {
throw new RuntimeException();
} catch(Exception $exc) {
$this->get('bug_tracker')->handle($exc, LogLevel::ERROR, array('a' => 1, 'b' => 2, 'c' => 3, 'd' => new stdClass()));
}
// use only one collector
try {
throw new RuntimeException();
} catch(Exception $exc) {
$this->get('dream_commerce_bug_tracker.collector.custom_1')->handle($exc);
}
namespace AppBundle\Entity;
use DreamCommerce\Component\BugTracker\Model\Error;
class UserError extends Error
{
}
namespace AppBundle\BugTracker;
use DreamCommerce\Component\BugTracker\Collector\CollectorInterface;
use DreamCommerce\Component\Common\Model\ArrayableInterface;
use DreamCommerce\Component\Common\Model\ArrayableTrait;
use Psr\Log\LogLevel;
use Throwable;
class CustomCollector implements CollectorInterface, ArrayableInterface
{
use ArrayableTrait;
private $collected = false;
private $foo;
private $bar;
public function __construct(array $options = array())
{
$this->fromArray($options);
}
public function hasSupportException(Throwable $exception, string $level = LogLevel::WARNING, array $context = array()): bool
{
return is_object($exception) && $exception instanceof \RuntimeException;
}
public function handle(Throwable $exception, string $level = LogLevel::WARNING, array $context = array())
{
echo $exception->getMessage() . '; foo: ' . $this->foo . '; bar: ' . $this->bar;
$this->collected = true;
}
public function isCollected(): bool
{
return $this->collected;
}
public function setFoo($foo)
{
$this->foo = $foo;
}
public function setBar($bar)
{
$this->bar = $bar;
}
}
namespace AppBundle\BugTracker\Extension;
use DreamCommerce\Component\BugTracker\Collector\Extension\ContextCollectorExtensionInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\RequestStack;
class ContextCollectorExtension implements ContextCollectorExtensionInterface
{
/**
* @var RequestStack
*/
private $requestStack;
public function __construct(RequestStack $requestStack) {
$this->requestStack = $requestStack;
}
public function getAdditionalContext(\Throwable $throwable): array
{
if ($throwable instanceof HttpException) {
$request = $this->requestStack->getMasterRequest();
if ($request === null) {
return [];
}
return [
'query' => serialize($request->query->all()),
'client_ip' => $request->server->get('REMOTE_ADDR')
];
}
return [];
}
}
php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new DreamCommerce\Bundle\CommonBundle\DreamCommerceCommonBundle(),
new DreamCommerce\Bundle\BugTrackerBundle\DreamCommerceBugTrackerBundle(),
//...
);
return $bundles;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.