File: src/query/AbstractQuery.php

Recommend this page to a friend!
  Classes of Vitaly  >  Queasy DB  >  src/query/AbstractQuery.php  >  Download  
File: src/query/AbstractQuery.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Queasy DB
Execute queries by accessing class variables
Author: By
Last change:
Date: 6 months ago
Size: 1,529 bytes
 

Contents

Class file image Download
<?php

namespace queasy\db\query;

use
PDO;

use
Psr\Log\NullLogger;
use
Psr\Log\LoggerInterface;
use
Psr\Log\LoggerAwareInterface;

use
queasy\db\DbException;

abstract class
AbstractQuery implements QueryInterface, LoggerAwareInterface
{
    private
$pdo;

    private
$sql;

   
/**
     * Logger instance.
     *
     * @var LoggerInterface
     */
   
protected $logger;

   
/**
     * Constructor.
     *
     * @param PDO $pdo PDO instance
     * @param string $query Query string
     *
     * @throws DbException When query can't be prepared
     */
   
public function __construct(PDO $pdo, $sql = null)
    {
       
$this->logger = new NullLogger();

       
$this->pdo = $pdo;
       
$this->setSql($sql);
    }

    abstract public function
run(array $params = array(), array $options = array());

    public function
__invoke(array $params = array(), array $options = array())
    {
        return
$this->run($params, $options);
    }

   
/**
     * Set a logger.
     *
     * @param LoggerInterface $logger
     */
   
public function setLogger(LoggerInterface $logger)
    {
       
$this->logger = $logger;
    }

    protected function
logger()
    {
        return
$this->logger;
    }

    protected function
pdo()
    {
        return
$this->pdo;
    }

    protected function
sql()
    {
        if (empty(
$this->sql)) {
            throw new
DbException('SQL string is empty.');
        }

        return
$this->sql;
    }

    protected function
setSql($sql)
    {
       
$this->sql = $sql;
    }
}


For more information send a message to info at phpclasses dot org.