Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 15, 2020
1 parent ad8fb72 commit 438b1e9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <rodolfo@chevereto.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Components\ExceptionHandler\Tests;

use Chevere\Components\ExceptionHandler\ExceptionHandler;
use LogicException;
use PHPUnit\Framework\TestCase;
use TypeError;

final class ExceptionHandlerTest extends TestCase
{
public function testConstruct(): void
{
// set_exception_handler('Chevere\Components\ExceptionHandler\ExceptionHandler::exception');
// throw new LogicException('yeaaaaaah', 1313);
// die();
// new ExceptionHandler(1, 'Test Exception', __FILE__, __LINE__, new TypeError('upsi'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Chevere\Components\Data\Traits\DataMethodTrait;
use Chevere\Components\ExceptionHandler\ExceptionHandler;
use Chevere\Components\VarDump\Dumpers\PlainDumper;
use Chevere\Components\VarDump\Formatters\DumperFormatter;
use Chevere\Components\VarDump\Formatters\PlainFormatter;
use Chevere\Components\VarDump\VarDump;
Expand Down Expand Up @@ -146,8 +147,8 @@ private function setServerProperties()
'serverHost' => $request->getHeaderLine('Host'),
'requestMethod' => $request->getMethod(),
'serverProtocol' => $request->protocolString(),
'serverSoftware' => $request->globals()->server()['SERVER_SOFTWARE'],
'clientIp' => $request->globals()->server()['REMOTE_ADDR'],
// 'serverSoftware' => $request->globals()->server()['SERVER_SOFTWARE'],
// 'clientIp' => $request->globals()->server()['REMOTE_ADDR'],
]);
}
}
Expand Down Expand Up @@ -235,14 +236,13 @@ private function handleSetConsoleStackSection(string $key, array &$value)

private function processContentGlobals()
{
$dumperVarDump = new VarDump(new DumperFormatter());
$plainVarDump = new VarDump(new PlainFormatter());
$globals = $this->exceptionHandler->request()->globals()->globals();
// $globals = $this->exceptionHandler->request()->globals()->globals();
$globals = $GLOBALS;
foreach (['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'] as $global) {
$val = $globals[$global] ?? null;
if (!empty($val)) {
$dumperVarDump = $dumperVarDump->withVar($val)->process();
$plainVarDump = $plainVarDump->withVar($val)->process();
$dumperVarDump = (new VarDump($val, new DumperFormatter()))->process();
$plainVarDump = (new VarDump($val, new PlainFormatter()))->process();
$wrapped = $dumperVarDump->toString();
if (!BootstrapInstance::get()->isCli()) {
$wrapped = '<pre>' . $wrapped . '</pre>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,15 @@ private function handleSetEntryArguments()

private function setFrameArguments()
{
$plainVarDump = (new VarDump(new PlainFormatter()))
->withDontDump(App::class);
$richVarDump = (new VarDump(new DumperFormatter()))
->withDontDump(App::class);
$this->plainArgs = "\n";
$this->richArgs = "\n";
foreach ($this->entry['args'] as $pos => $var) {
$aux = 'Arg#' . ($pos + 1) . ' ';
$plainVarDump = $plainVarDump
->withVar($var)
$plainVarDump = (new VarDump($var, new PlainFormatter()))
->withDontDump(App::class)
->process();
$richVarDump = $richVarDump
->withVar($var)
$richVarDump = (new VarDump($var, new DumperFormatter()))
->withDontDump(App::class)
->process();
$this->plainArgs .= $aux . $plainVarDump->toString() . "\n";
$this->richArgs .= $aux . $richVarDump->toString() . "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ private function assertArgument(): void
$accepted = mb_list_encodings();
if (!in_array($this->value, $accepted)) {
throw new InvalidArgumentException(
(new Message('Invalid value %value% provided, expecting one of the accepted encodings: %accepted%'))
(new Message('Invalid value %value% provided for %className%, expecting one of the accepted encodings: %accepted%'))
->code('%className%', __CLASS__)
->code('%value%', $this->value)
->code('%accepted%', implode(', ', $accepted))
->strtr('%accepted%', '[' . implode(', ', $accepted) . ']')
->toString()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class DumperFormatter implements FormatterInterface

public function __construct()
{
$this->formatter = BootstrapInstance::get()->isCli() ? new ConsoleFormatter() : new PlainFormatter();
$this->formatter = BootstrapInstance::get()->isCli() ? new ConsoleFormatter() : new HtmlFormatter();
}

public function applyWrap(string $key, string $dump): string
Expand Down
3 changes: 0 additions & 3 deletions Chevereto-Chevere/phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@
->withDev(false)
->withAppAutoloader('Chevere\\TestApp\\App')
);

// define('Chevere\DOCUMENT_ROOT', __DIR__ . '/Chevere/TestApp/');
// define('Chevere\ROOT_PATH', rtrim(str_replace('\\', '/', DOCUMENT_ROOT), '/') . '/');
2 changes: 1 addition & 1 deletion Chevereto-Chevere/runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
new SetErrorHandler('Chevere\Components\ExceptionHandler\ErrorHandler::error'),
new SetExceptionHandler('Chevere\Components\ExceptionHandler\ExceptionHandler::exception'),
new SetLocale('en_US.UTF8'),
new SetDefaultCharset('utf-8'),
new SetDefaultCharset('UTF-8'),
new SetPrecision('16'),
new SetUriScheme('https'),
new SetTimeZone('UTC')
Expand Down
3 changes: 3 additions & 0 deletions app/src/Controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
use Chevere\Components\Controller\Traits\JsonApiTrait;
use Chevere\Components\JsonApi\EncodedDocument;
use Chevere\Components\Time\TimeHr;
use Exception;
use JsonApiPhp\JsonApi\Attribute;
use JsonApiPhp\JsonApi\DataDocument;
use JsonApiPhp\JsonApi\JsonApi;
use JsonApiPhp\JsonApi\Link\SelfLink;
use JsonApiPhp\JsonApi\ResourceCollection;
use JsonApiPhp\JsonApi\ResourceObject;
use LogicException;

class Index extends Controller implements JsonApiInterface
{
Expand All @@ -38,6 +40,7 @@ class Index extends Controller implements JsonApiInterface

public function __invoke(): void
{
throw new LogicException('deeeeznuts');
$took = hrtime(true);
$arr = ['aaa', $this, (new TimeHr($took - BootstrapInstance::get()->hrTime()))->toReadMs()];
xdd($arr);
Expand Down

0 comments on commit 438b1e9

Please sign in to comment.