|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Component\HttpKernel\Profiler; |
|
13 |
|
14 /** |
|
15 * A ProfilerStorage for Mysql |
|
16 * |
|
17 * @author Jan Schumann <js@schumann-it.com> |
|
18 */ |
|
19 class MysqlProfilerStorage extends PdoProfilerStorage |
|
20 { |
|
21 /** |
|
22 * {@inheritdoc} |
|
23 */ |
|
24 protected function initDb() |
|
25 { |
|
26 if (null === $this->db) { |
|
27 if ('mysql' !== substr($this->dsn, 0, 5)) { |
|
28 throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "'.$this->dsn.'"'); |
|
29 } |
|
30 |
|
31 if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) { |
|
32 throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.'); |
|
33 } |
|
34 |
|
35 $db = new \PDO($this->dsn, $this->username, $this->password); |
|
36 $db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, KEY (created_at), KEY (ip), KEY (url), KEY (parent))'); |
|
37 |
|
38 $this->db = $db; |
|
39 } |
|
40 |
|
41 return $this->db; |
|
42 } |
|
43 |
|
44 /** |
|
45 * {@inheritdoc} |
|
46 */ |
|
47 protected function buildCriteria($ip, $url, $limit) |
|
48 { |
|
49 $criteria = array(); |
|
50 $args = array(); |
|
51 |
|
52 if ($ip = preg_replace('/[^\d\.]/', '', $ip)) { |
|
53 $criteria[] = 'ip LIKE :ip'; |
|
54 $args[':ip'] = '%'.$ip.'%'; |
|
55 } |
|
56 |
|
57 if ($url) { |
|
58 $criteria[] = 'url LIKE :url'; |
|
59 $args[':url'] = '%'.addcslashes($url, '%_\\').'%'; |
|
60 } |
|
61 |
|
62 return array($criteria, $args); |
|
63 } |
|
64 } |