<?php

namespace KupShop\DevelopmentBundle\Query;

use Doctrine\DBAL\Connection;

class QueryBuilder extends \Query\QueryBuilder
{
    protected static $qb = [];

    public function __construct(Connection $connection)
    {
        self::$qb[] = $this;

        parent::__construct($connection);
    }

    public static function getPendingQueryBuilders()
    {
        return self::$qb;
    }

    public function getSQL()
    {
        $this->markExecuted();

        return parent::getSQL();
    }

    protected function markExecuted()
    {
        $found = array_search($this, self::$qb);

        if ($found === false) {
            return;
        }

        unset(self::$qb[$found]);
    }
}
