-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florian Eckerstorfer
committed
Apr 21, 2014
0 parents
commit 0b52327
Showing
12 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/build/logs/ | ||
/vendor/ | ||
/*.sublime-project | ||
/*.sublime-workspace | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test: test-unit | ||
|
||
test-unit: | ||
./vendor/bin/phpunit -c . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) [ | ||
|
||
- [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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.