maximebf / php-debugbar

Debug bar for PHP
phpdebugbar.com
MIT License
4.2k stars 401 forks source link

Cannot use mb_check_encoding() #189

Open OzanKurt opened 9 years ago

OzanKurt commented 9 years ago

What can I do to make this function work on my centos 6.2 machine?

I have tried to install it using yum but it didn't work.

GrahamCampbell commented 9 years ago

We shouldn't be assuming you have the mbstring extension anyway. This is a bug.

barryvdh commented 9 years ago

Did you follow http://php.net/manual/en/mbstring.installation.php ? Or you could use https://github.com/tchwork/utf8 But we should probably either require this with composer (which means people get stuck on an older version which doesn't work either) or should use a non-mbstring check.

Perhaps something like:

function isUTF8($str)
{
    return preg_match('//u', $str);
}

function toUTF8($str)
{
    return iconv('UTF-8', 'UTF-8//IGNORE', $str);
}
GrahamCampbell commented 9 years ago

@barryvdh That's my point. If we need the function, we absolutely must require the extension. That's the "bug" here.

GrahamCampbell commented 9 years ago

Or rather, check the function exists, which would allow the solution you suggested.

barryvdh commented 9 years ago

Yes I understood that ;)

I'll create a 'Util' class to provide some common checks etc.

GrahamCampbell commented 9 years ago

:beers: great

OzanKurt commented 9 years ago

I tried everything I could find in internet and also the thing you said. :cry: I am so sorry because it doesn't work.

require('includes/config.php');
require('includes/dbtables.php');

require 'vendor/autoload.php';

use DebugBar\StandardDebugBar;
use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => $database['host'],
    'database'  => $database['databasename'],
    'username'  => $database['user'],
    'password'  => $database['userpw'],
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => $database['tableprefix'],
]);

use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));

$capsule->setAsGlobal();

$capsule->bootEloquent();

$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();

$pdoRead  = new DebugBar\DataCollector\PDO\TraceablePDO(Capsule::connection()->getPdo());
$pdoWrite = new DebugBar\DataCollector\PDO\TraceablePDO(Capsule::connection()->getPdo());

$pdoCollector = new DebugBar\DataCollector\PDO\PDOCollector();
$pdoCollector->addConnection($pdoRead, 'read-db');
$pdoCollector->addConnection($pdoWrite, 'write-db');

$debugbar["messages"]->addMessage("hello world!");

This doesn't work for query logging. :sob:

barryvdh commented 9 years ago

You still have to add the collector to the Debugbar Something like $debugbar->addCollector($pdoCollector);

barryvdh commented 9 years ago

I've created those helper functions, hope this helps: #190

Also, if you are using Eloquent you might find https://github.com/barryvdh/laravel-debugbar/blob/master/src/DataCollector/QueryCollector.php useful, but I should probably reduce some dependencies (instead of requiring the framework)..