![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/vendor/knplabs/gaufrette/src/Gaufrette/Adapter/ |
<?php namespace Gaufrette\Adapter; use Gaufrette\Adapter; use Gaufrette\Util; use Doctrine\DBAL\Connection; /** * Doctrine DBAL adapter. * * @author Markus Bachmann <[email protected]> * @author Antoine Hérault <[email protected]> * @author Leszek Prabucki <[email protected]> */ class DoctrineDbal implements Adapter, ChecksumCalculator, ListKeysAware { protected $connection; protected $table; protected $columns = [ 'key' => 'key', 'content' => 'content', 'mtime' => 'mtime', 'checksum' => 'checksum', ]; /** * @param Connection $connection The DBAL connection * @param string $table The files table * @param array $columns The column names */ public function __construct(Connection $connection, $table, array $columns = []) { $this->connection = $connection; $this->table = $table; $this->columns = array_replace($this->columns, $columns); } /** * {@inheritdoc} */ public function keys() { $keys = []; $stmt = $this->connection->executeQuery(sprintf( 'SELECT %s FROM %s', $this->getQuotedColumn('key'), $this->getQuotedTable() )); return $stmt->fetchAll(\PDO::FETCH_COLUMN); } /** * {@inheritdoc} */ public function rename($sourceKey, $targetKey) { return (boolean) $this->connection->update( $this->table, [$this->getQuotedColumn('key') => $targetKey], [$this->getQuotedColumn('key') => $sourceKey] ); } /** * {@inheritdoc} */ public function mtime($key) { return $this->getColumnValue($key, 'mtime'); } /** * {@inheritdoc} */ public function checksum($key) { return $this->getColumnValue($key, 'checksum'); } /** * {@inheritdoc} */ public function exists($key) { return (boolean) $this->connection->fetchColumn( sprintf( 'SELECT COUNT(%s) FROM %s WHERE %s = :key', $this->getQuotedColumn('key'), $this->getQuotedTable(), $this->getQuotedColumn('key') ), ['key' => $key] ); } /** * {@inheritdoc} */ public function read($key) { return $this->getColumnValue($key, 'content'); } /** * {@inheritdoc} */ public function delete($key) { return (boolean) $this->connection->delete( $this->table, [$this->getQuotedColumn('key') => $key] ); } /** * {@inheritdoc} */ public function write($key, $content) { $values = [ $this->getQuotedColumn('content') => $content, $this->getQuotedColumn('mtime') => time(), $this->getQuotedColumn('checksum') => Util\Checksum::fromContent($content), ]; if ($this->exists($key)) { $this->connection->update( $this->table, $values, [$this->getQuotedColumn('key') => $key] ); } else { $values[$this->getQuotedColumn('key')] = $key; $this->connection->insert($this->table, $values); } return Util\Size::fromContent($content); } /** * {@inheritdoc} */ public function isDirectory($key) { return false; } private function getColumnValue($key, $column) { $value = $this->connection->fetchColumn( sprintf( 'SELECT %s FROM %s WHERE %s = :key', $this->getQuotedColumn($column), $this->getQuotedTable(), $this->getQuotedColumn('key') ), ['key' => $key] ); return $value; } /** * {@inheritdoc} */ public function listKeys($prefix = '') { $prefix = trim($prefix); $keys = $this->connection->fetchAll( sprintf( 'SELECT %s AS _key FROM %s WHERE %s LIKE :pattern', $this->getQuotedColumn('key'), $this->getQuotedTable(), $this->getQuotedColumn('key') ), ['pattern' => sprintf('%s%%', $prefix)] ); return [ 'dirs' => [], 'keys' => array_map(function ($value) { return $value['_key']; }, $keys), ]; } private function getQuotedTable() { return $this->connection->quoteIdentifier($this->table); } private function getQuotedColumn($column) { return $this->connection->quoteIdentifier($this->columns[$column]); } }