PdoAdapter.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Adapter;
  11. use Doctrine\DBAL\Connection;
  12. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  13. use Symfony\Component\Cache\Marshaller\MarshallerInterface;
  14. use Symfony\Component\Cache\PruneableInterface;
  15. use Symfony\Component\Cache\Traits\PdoTrait;
  16. class PdoAdapter extends AbstractAdapter implements PruneableInterface
  17. {
  18. use PdoTrait;
  19. protected $maxIdLength = 255;
  20. /**
  21. * You can either pass an existing database connection as PDO instance or
  22. * a Doctrine DBAL Connection or a DSN string that will be used to
  23. * lazy-connect to the database when the cache is actually used.
  24. *
  25. * When a Doctrine DBAL Connection is passed, the cache table is created
  26. * automatically when possible. Otherwise, use the createTable() method.
  27. *
  28. * List of available options:
  29. * * db_table: The name of the table [default: cache_items]
  30. * * db_id_col: The column where to store the cache id [default: item_id]
  31. * * db_data_col: The column where to store the cache data [default: item_data]
  32. * * db_lifetime_col: The column where to store the lifetime [default: item_lifetime]
  33. * * db_time_col: The column where to store the timestamp [default: item_time]
  34. * * db_username: The username when lazy-connect [default: '']
  35. * * db_password: The password when lazy-connect [default: '']
  36. * * db_connection_options: An array of driver-specific connection options [default: []]
  37. *
  38. * @param \PDO|Connection|string $connOrDsn a \PDO or Connection instance or DSN string or null
  39. *
  40. * @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
  41. * @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
  42. * @throws InvalidArgumentException When namespace contains invalid characters
  43. */
  44. public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
  45. {
  46. $this->init($connOrDsn, $namespace, $defaultLifetime, $options, $marshaller);
  47. }
  48. }