Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
SqliteProfilerStorage.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel\Profiler;
013
014 /**
015 * SqliteProfilerStorage stores profiling information in a SQLite database.
016 *
017 * @author Fabien Potencier <fabien@symfony.com>
018 */
019 class SqliteProfilerStorage extends PdoProfilerStorage
020 {
021 /**
022 * @throws \RuntimeException When neither of SQLite3 or PDO_SQLite extension is enabled
023 */
024 protected function initDb()
025 {
026 if (null === $this->db || $this->db instanceof \SQLite3) {
027 if (0 !== strpos($this->dsn, 'sqlite')) {
028 throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Sqlite with an invalid dsn "%s". The expected format is "sqlite:/path/to/the/db/file".', $this->dsn));
029 }
030 if (class_exists('SQLite3')) {
031 $db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE);
032 if (method_exists($db, 'busyTimeout')) {
033 // busyTimeout only exists for PHP >= 5.3.3
034 $db->busyTimeout(1000);
035 }
036 } elseif (class_exists('PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) {
037 $db = new \PDO($this->dsn);
038 } else {
039 throw new \RuntimeException('You need to enable either the SQLite3 or PDO_SQLite extension for the profiler to run properly.');
040 }
041
042 $db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
043 $db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)');
044 $db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)');
045 $db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)');
046 $db->exec('CREATE INDEX IF NOT EXISTS data_method ON sf_profiler_data (method)');
047 $db->exec('CREATE INDEX IF NOT EXISTS data_url ON sf_profiler_data (url)');
048 $db->exec('CREATE INDEX IF NOT EXISTS data_parent ON sf_profiler_data (parent)');
049 $db->exec('CREATE UNIQUE INDEX IF NOT EXISTS data_token ON sf_profiler_data (token)');
050
051 $this->db = $db;
052 }
053
054 return $this->db;
055 }
056
057 protected function exec($db, $query, array $args = array())
058 {
059 if ($db instanceof \SQLite3) {
060 $stmt = $this->prepareStatement($db, $query);
061 foreach ($args as $arg => $val) {
062 $stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
063 }
064
065 $res = $stmt->execute();
066 if (false === $res) {
067 throw new \RuntimeException(sprintf('Error executing SQLite query "%s"', $query));
068 }
069 $res->finalize();
070 } else {
071 parent::exec($db, $query, $args);
072 }
073 }
074
075 protected function fetch($db, $query, array $args = array())
076 {
077 $return = array();
078
079 if ($db instanceof \SQLite3) {
080 $stmt = $this->prepareStatement($db, $query, true);
081 foreach ($args as $arg => $val) {
082 $stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
083 }
084 $res = $stmt->execute();
085 while ($row = $res->fetchArray(\SQLITE3_ASSOC)) {
086 $return[] = $row;
087 }
088 $res->finalize();
089 $stmt->close();
090 } else {
091 $return = parent::fetch($db, $query, $args);
092 }
093
094 return $return;
095 }
096
097 /**
098 * {@inheritdoc}
099 */
100 protected function buildCriteria($ip, $url, $start, $end, $limit, $method)
101 {
102 $criteria = array();
103 $args = array();
104
105 if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
106 $criteria[] = 'ip LIKE :ip';
107 $args[':ip'] = '%'.$ip.'%';
108 }
109
110 if ($url) {
111 $criteria[] = 'url LIKE :url ESCAPE "\"';
112 $args[':url'] = '%'.addcslashes($url, '%_\\').'%';
113 }
114
115 if ($method) {
116 $criteria[] = 'method = :method';
117 $args[':method'] = $method;
118 }
119
120 if (!empty($start)) {
121 $criteria[] = 'time >= :start';
122 $args[':start'] = $start;
123 }
124
125 if (!empty($end)) {
126 $criteria[] = 'time <= :end';
127 $args[':end'] = $end;
128 }
129
130 return array($criteria, $args);
131 }
132
133 protected function close($db)
134 {
135 if ($db instanceof \SQLite3) {
136 $db->close();
137 }
138 }
139 }
140