Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Eckerstorfer committed Apr 21, 2014
0 parents commit 0b52327
Show file tree
Hide file tree
Showing 12 changed files with 668 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build/logs/
/vendor/
/*.sublime-project
/*.sublime-workspace
/composer.lock
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar --prefer-source --dev install
- cp phpunit.xml.dist phpunit.xml

script:
- mkdir -p build/logs
- ./vendor/bin/phpunit -c ./

after_script:
- php vendor/bin/coveralls -v
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Florian Eckerstorfer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test: test-unit

test-unit:
./vendor/bin/phpunit -c .
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cocur/nqm
=========

> Named Query Manager

Features
--------


Installation
------------


Usage
-----


Changelog
---------


Author
------

### [Florian Eckerstorfer](http://florian.ec) [![Support Florian](http://img.shields.io/gittip/florianeckerstorfer.svg)

- [Twitter](http://twitter.com/Florian_)
- [App.net](http://app.net/florian)


License
-------

The MIT license applies to `cocur/nqm`. For the full copyright and license information, please view the LICENSE file distributed with this source code.
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "cocur/nqm",
"type": "library",
"description": "Named Query Manager helps you organise queries in files.",
"keywords": ["database", "queery", "pdo"],
"license": "MIT",
"authors": [
{
"name": "Florian Eckerstorfer",
"email": "florian@eckerstorfer.co",
"homepage": "http://florian.ec"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/florianeckerstorfer/pseudo"
}
],
"require": {
"php": ">=5.4",
"mikey179/vfsStream": "~1.2",
"jimbojsb/pseudo": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-4": {
"Cocur\\NQM\\": "src"
}
}
}
19 changes: 19 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="cocur/nqm Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
25 changes: 25 additions & 0 deletions src/Exception/QueryNotExistsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* This file is part of cocur/nqm.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cocur\NQM\Exception;

/**
* QueryNotExistsException
*
* @category exception
* @package cocur/nqm
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
*/
class QueryNotExistsException extends \Exception
{
}
133 changes: 133 additions & 0 deletions src/NQM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

/**
* This file is part of cocur/nqm.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cocur\NQM;

/**
* NQM
*
* @package cocur/nqm
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
*/
class NQM
{
/** @var \PDO */
private $pdo;

/** @var QueryLoader */
private $queryLoader;

/**
* Constructor.
*
* @param PDO $pdo
* @param QueryLoader $queryLoader
*/
public function __construct(\PDO $pdo, QueryLoader $queryLoader)
{
$this->pdo = $pdo;
$this->queryLoader = $queryLoader;
}

/**
* Sets the PDO connection.
*
* @param \PDO $pdo PDO connection
*
* @return NQM
*/
public function setPdo(\PDO $pdo)
{
$this->pdo = $pdo;

return $this;
}

/**
* Returns the PDO connection.
*
* @return \PDO PDO connection.
*/
public function getPdo()
{
return $this->pdo;
}

/**
* Sets the query loader.
*
* @param QueryLoader $queryLoader The query loader
*
* @return NQM
*/
public function setQueryLoader(QueryLoader $queryLoader)
{
$this->queryLoader = $queryLoader;

return $this;
}

/**
* Returns the query loader.
*
* @return QueryLoader The query loader.
*/
public function getQueryLoader()
{
return $this->queryLoader;
}

/**
* Returns the query with the given name.
*
* @param string $name Name of a query.
*
* @return string SQL code of the query with the given name.
*
* @throws QueryNotExistsException if no query with the given name exists.
*/
public function getQuery($name)
{
return $this->queryLoader->getQuery($name);
}

/**
* Prepares a named query for execution.
*
* @param string $name Name of a query.
* @param array $options Options, will be used to call `\PDO::prepare()`.
*
* @return \PDOStatement
*/
public function prepare($name, $options = null)
{
return $this->pdo->prepare($this->getQuery($name), $options);
}

/**
* Executes the named query with the given parameters.
*
* @param string $name Name of query.
* @param array $parameters List of parameters to bind to the statement.
* @param array $options Options, will be used to call `\PDO::prepare()`.
*
* @return \PDOStatement
*/
public function execute($name, $parameters = null, $options = null)
{
$stmt = $this->prepare($name, $options);
$stmt->execute($parameters);

return $stmt;
}
}
Loading

0 comments on commit 0b52327

Please sign in to comment.