@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $handle = @fopen($configuration_path, 'r'); |
| 9 | 9 | if ($handle === false) { |
| 10 | - throw new RuntimeException("Could not load configuration"); |
|
| 10 | + throw new RuntimeException("Could not load configuration"); |
|
| 11 | 11 | } |
| 12 | 12 | $configuration = fread($handle, filesize($configuration_path)); |
| 13 | 13 | fclose($handle); |
@@ -15,40 +15,40 @@ discard block |
||
| 15 | 15 | $configuration = json_decode($configuration); |
| 16 | 16 | $last_json_error = json_last_error(); |
| 17 | 17 | if ($last_json_error !== JSON_ERROR_NONE) { |
| 18 | - throw new RuntimeException("Could not parse configuration - JSON error detected"); |
|
| 18 | + throw new RuntimeException("Could not parse configuration - JSON error detected"); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // configure the db connections holder |
| 22 | 22 | $db_connections = new Aura\Sql\ConnectionLocator(); |
| 23 | 23 | $db_connections->setDefault(function () use ($configuration) { |
| 24 | - $connection = $configuration->database->slave; |
|
| 25 | - return new Aura\Sql\ExtendedPdo( |
|
| 26 | - "mysql:host={$connection->host}", |
|
| 27 | - $connection->user, |
|
| 28 | - $connection->password |
|
| 29 | - ); |
|
| 24 | + $connection = $configuration->database->slave; |
|
| 25 | + return new Aura\Sql\ExtendedPdo( |
|
| 26 | + "mysql:host={$connection->host}", |
|
| 27 | + $connection->user, |
|
| 28 | + $connection->password |
|
| 29 | + ); |
|
| 30 | 30 | }); |
| 31 | 31 | $db_connections->setWrite('master', function () use ($configuration) { |
| 32 | - $connection = $configuration->database->master; |
|
| 33 | - return new Aura\Sql\ExtendedPdo( |
|
| 34 | - "mysql:host={$connection->host}", |
|
| 35 | - $connection->user, |
|
| 36 | - $connection->password |
|
| 37 | - ); |
|
| 32 | + $connection = $configuration->database->master; |
|
| 33 | + return new Aura\Sql\ExtendedPdo( |
|
| 34 | + "mysql:host={$connection->host}", |
|
| 35 | + $connection->user, |
|
| 36 | + $connection->password |
|
| 37 | + ); |
|
| 38 | 38 | }); |
| 39 | 39 | $db_connections->setRead('slave', function () use ($configuration) { |
| 40 | - $connection = $configuration->database->slave; |
|
| 41 | - $pdo = new Aura\Sql\ExtendedPdo( |
|
| 42 | - "mysql:host={$connection->host}", |
|
| 43 | - $connection->user, |
|
| 44 | - $connection->password |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - $profiler = new Aura\Sql\Profiler(); |
|
| 48 | - $profiler->setActive(true); |
|
| 49 | - $pdo->setProfiler($profiler); |
|
| 50 | - |
|
| 51 | - return $pdo; |
|
| 40 | + $connection = $configuration->database->slave; |
|
| 41 | + $pdo = new Aura\Sql\ExtendedPdo( |
|
| 42 | + "mysql:host={$connection->host}", |
|
| 43 | + $connection->user, |
|
| 44 | + $connection->password |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + $profiler = new Aura\Sql\Profiler(); |
|
| 48 | + $profiler->setActive(true); |
|
| 49 | + $pdo->setProfiler($profiler); |
|
| 50 | + |
|
| 51 | + return $pdo; |
|
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | 54 | // setup the service locator |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | private function __construct() |
| 19 | 19 | {
|
| 20 | 20 | $this->console = new Console(); |
| 21 | - $this->profiler = new PhpQuickProfiler(); |
|
| 22 | - $this->profiler->setConsole($this->console); |
|
| 21 | + $this->profiler = new PhpQuickProfiler(); |
|
| 22 | + $this->profiler->setConsole($this->console); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function instance() |
@@ -82,25 +82,25 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public static function display() |
| 84 | 84 | {
|
| 85 | - if ($_COOKIE['debugger'] == 'display' && self::instance()->display) {
|
|
| 86 | - $pdo = ''; |
|
| 87 | - if (!empty($pdo)) {
|
|
| 88 | - $profiles = $pdo->getProfiler()->getProfiles(); |
|
| 89 | - $profiles = array_filter($profiles, function ($profile) {
|
|
| 90 | - return $profile['function'] == 'perform'; |
|
| 91 | - }); |
|
| 92 | - $profiles = array_map(function ($profile) {
|
|
| 93 | - return array( |
|
| 94 | - 'sql' => $profile['statement'], |
|
| 95 | - 'parameters' => $profile['bind_values'], |
|
| 96 | - 'time' => $profile['duration'] |
|
| 97 | - ); |
|
| 98 | - }, $profiles); |
|
| 99 | - self::instance()->profiler->setProfiledQueries($profiles); |
|
| 100 | - } |
|
| 101 | - self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
| 102 | - self::instance()->profiler->display($pdo); |
|
| 103 | - } |
|
| 85 | + if ($_COOKIE['debugger'] == 'display' && self::instance()->display) {
|
|
| 86 | + $pdo = ''; |
|
| 87 | + if (!empty($pdo)) {
|
|
| 88 | + $profiles = $pdo->getProfiler()->getProfiles(); |
|
| 89 | + $profiles = array_filter($profiles, function ($profile) {
|
|
| 90 | + return $profile['function'] == 'perform'; |
|
| 91 | + }); |
|
| 92 | + $profiles = array_map(function ($profile) {
|
|
| 93 | + return array( |
|
| 94 | + 'sql' => $profile['statement'], |
|
| 95 | + 'parameters' => $profile['bind_values'], |
|
| 96 | + 'time' => $profile['duration'] |
|
| 97 | + ); |
|
| 98 | + }, $profiles); |
|
| 99 | + self::instance()->profiler->setProfiledQueries($profiles); |
|
| 100 | + } |
|
| 101 | + self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
| 102 | + self::instance()->profiler->display($pdo); |
|
| 103 | + } |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | } |