PdoPruneableTrait.php 964 B

12345678910111213141516171819202122232425262728293031323334
  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\Tests\Traits;
  11. trait PdoPruneableTrait
  12. {
  13. protected function isPruned($cache, $name)
  14. {
  15. $o = new \ReflectionObject($cache);
  16. if (!$o->hasMethod('getConnection')) {
  17. self::fail('Cache does not have "getConnection()" method.');
  18. }
  19. $getPdoConn = $o->getMethod('getConnection');
  20. $getPdoConn->setAccessible(true);
  21. /** @var \Doctrine\DBAL\Statement $select */
  22. $select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
  23. $select->bindValue(':id', sprintf('%%%s', $name));
  24. $select->execute();
  25. return 0 === \count($select->fetchAll(\PDO::FETCH_COLUMN));
  26. }
  27. }