-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 255dd4b
Showing
20 changed files
with
1,764 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,16 @@ | ||
# Temporary files | ||
.DS_Store | ||
*~ | ||
*.sw[aop] | ||
|
||
# Deployment dependencies | ||
vendor | ||
composer.lock | ||
phpunit.xml | ||
|
||
# IDE project settings | ||
.project | ||
.settings | ||
.idea | ||
*.sublime-workspace | ||
*.sublime-project |
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,125 @@ | ||
<?php | ||
|
||
use \Phan\Config; | ||
|
||
/** | ||
* This configuration will be read and overlayed on top of the | ||
* default configuration. Command line arguments will be applied | ||
* after this file is read. | ||
* | ||
* @see src/Phan/Config.php | ||
* See Config for all configurable options. | ||
* | ||
* A Note About Paths | ||
* ================== | ||
* | ||
* Files referenced from this file should be defined as | ||
* | ||
* ``` | ||
* Config::projectPath('relative_path/to/file') | ||
* ``` | ||
* | ||
* where the relative path is relative to the root of the | ||
* project which is defined as either the working directory | ||
* of the phan executable or a path passed in via the CLI | ||
* '-d' flag. | ||
*/ | ||
return [ | ||
// If true, missing properties will be created when | ||
// they are first seen. If false, we'll report an | ||
// error message. | ||
"allow_missing_properties" => true, | ||
|
||
// Allow null to be cast as any type and for any | ||
// type to be cast to null. | ||
"null_casts_as_any_type" => true, | ||
|
||
// Allow null to be cast as any array-like type | ||
// This is an incremental step in migrating away from null_casts_as_any_type. | ||
// If null_casts_as_any_type is true, this has no effect. | ||
'null_casts_as_array' => true, | ||
|
||
// Allow any array-like type to be cast to null. | ||
// This is an incremental step in migrating away from null_casts_as_any_type. | ||
// If null_casts_as_any_type is true, this has no effect. | ||
'array_casts_as_null' => true, | ||
|
||
// If this has entries, scalars (int, float, bool, string, null) | ||
// are allowed to perform the casts listed. | ||
// E.g. ['int' => ['float', 'string'], 'float' => ['int'], 'string' => ['int'], 'null' => ['string']] | ||
// allows casting null to a string, but not vice versa. | ||
// (subset of scalar_implicit_cast) | ||
'scalar_implicit_partial' => [ | ||
'int' => ['float', 'string'], | ||
'float' => ['int'], | ||
'string' => ['int'], | ||
'null' => ['string', 'bool'], | ||
'bool' => ['null'], | ||
], | ||
|
||
// Backwards Compatibility Checking | ||
'backward_compatibility_checks' => false, | ||
|
||
// Run a quick version of checks that takes less | ||
// time | ||
"quick_mode" => true, | ||
|
||
// Only emit critical issues | ||
"minimum_severity" => 0, | ||
|
||
// A set of fully qualified class-names for which | ||
// a call to parent::__construct() is required | ||
'parent_constructor_required' => [ | ||
], | ||
|
||
// Add any issue types (such as 'PhanUndeclaredMethod') | ||
// here to inhibit them from being reported | ||
'suppress_issue_types' => [ | ||
// These report false positives in libraries due | ||
// to them not being used by any of the other | ||
// library code. | ||
'PhanUnreferencedPublicClassConstant', | ||
'PhanWriteOnlyProtectedProperty', | ||
'PhanUnreferencedPublicMethod', | ||
'PhanUnreferencedUseNormal', | ||
'PhanUnreferencedProtectedMethod', | ||
'PhanUnreferencedProtectedProperty', | ||
|
||
], | ||
|
||
// A list of directories that should be parsed for class and | ||
// method information. After excluding the directories | ||
// defined in exclude_analysis_directory_list, the remaining | ||
// files will be statically analyzed for errors. | ||
// | ||
// Thus, both first-party and third-party code being used by | ||
// your application should be included in this list. | ||
'directory_list' => [ | ||
'src', | ||
'vendor', | ||
'tests', | ||
], | ||
|
||
// A list of directories holding code that we want | ||
// to parse, but not analyze | ||
"exclude_analysis_directory_list" => [ | ||
"vendor", | ||
], | ||
|
||
// A file list that defines files that will be excluded | ||
// from parsing and analysis and will not be read at all. | ||
// | ||
// This is useful for excluding hopelessly unanalyzable | ||
// files that can't be removed for whatever reason. | ||
'exclude_file_list' => [ | ||
], | ||
|
||
// Set to true in order to attempt to detect dead | ||
// (unreferenced) code. Keep in mind that the | ||
// results will only be a guess given that classes, | ||
// properties, constants and methods can be referenced | ||
// as variables (like `$class->$property` or | ||
// `$class->$method()`) in ways that we're unable | ||
// to make sense of. | ||
'dead_code_detection' => true, | ||
]; |
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,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2019, DealNews | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,104 @@ | ||
# DealNews Datbase Library | ||
|
||
## Factory | ||
|
||
The factory creates PDO objects using \DealNews\GetConfigto | ||
read database settings and create a PDO database connection. | ||
|
||
### Supported Settings | ||
|
||
| Setting | Description | | ||
|---------|--------------------------------------------------------------------------------------| | ||
| type | This may be one of `pdo`, `mysql`, or `pgsql`. All types return PDO connections. | | ||
| dsn | A valid PDO DSN. See each driver for specifics | | ||
| db | The name of the database. For PDO, this is usually in the DSN. | | ||
| server | One of more comma separated servers names. Not used by the `pdo` type. | | ||
| port | Server port. Not used by the `pdo` type. | | ||
| user | Database user name. Not all PDO drivers require one. | | ||
| pass | Database password. Not all PDO drivers require one. | | ||
| charset | Character set to use for `mysql` connections. The default is `utf8mb4`. | | ||
| options | A JSON encoded array of options to pass to the PDO constructor. These vary by driver | | ||
|
||
### Usage | ||
|
||
Example: | ||
|
||
``` | ||
$mydb = \DealNews\DB\Factory::init("mydb"); | ||
``` | ||
|
||
## CRUD | ||
|
||
The `CRUD` class is a helper that wraps up common PDO logic for CRUD operations. | ||
|
||
### Basic Usage | ||
|
||
``` | ||
$mydb = \DealNews\DB\Factory::init("mydb"); | ||
$crud = new \DealNews\DB\CRUD($mydb); | ||
// Create | ||
$result = $crud->create( | ||
// table name | ||
"test", | ||
// data to add | ||
[ | ||
"name" => $name, | ||
"description" => $description, | ||
] | ||
); | ||
// Read | ||
$rows = $crud->read( | ||
// table name | ||
"test", | ||
// where clause data | ||
["id" => $id] | ||
); | ||
// Update | ||
$result = $crud->update( | ||
// table name | ||
"test", | ||
// data to update | ||
["name" => "Test"], | ||
// where clause data | ||
["id" => $id] | ||
); | ||
// Delete | ||
$result = $crud->delete( | ||
// table name | ||
"test", | ||
// where clause data | ||
["id" => $row["id"]] | ||
); | ||
``` | ||
|
||
### Advanced Usage | ||
|
||
The class also exposes a `run` method which is used internally by the other | ||
methods. Complex queries can be run using this method by providing an SQL | ||
query and a parameter array which will be mapped to the prepared query. It | ||
returns a PDOStatement object. | ||
|
||
``` | ||
// Run a select with no parameters | ||
$stmt = $crud->run("select * from table limit 10"); | ||
// Run a select query with paramters | ||
$stmt = $crud->run( | ||
"select * from table where foo = :foo" | ||
[ | ||
":foo" => $foo | ||
] | ||
); | ||
``` | ||
|
||
## Testing | ||
|
||
By default, only unit tests are run. To run the functional tests the host | ||
machine will need to be a docker host. Also, the pdo_pgsql, pdo_mysql, and | ||
pdo_sqlite extensions must be installed on the host machine. PHPUnit will | ||
start and stop docker containers to test the MySQL and Postgres connections. | ||
Use `--group functional` when running PHPUnit to run these tests. |
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,23 @@ | ||
{ | ||
"name": "dealnews/db", | ||
"type": "library", | ||
"license": "BSD-3-Clause", | ||
"description": "Database Library providing a PDO factory and CRUD operations", | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.5" | ||
}, | ||
"require": { | ||
"php": ">=7.1.0", | ||
"dealnews/get-config": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"DealNews\\DB\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"DealNews\\DB\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<groups> | ||
<exclude> | ||
<group>functional</group> | ||
</exclude> | ||
</groups> | ||
<filter> | ||
<whitelist> | ||
<directory suffix="Test.php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<env name="DN_INI_FILE" value="./tests/test.ini"/> | ||
</php> | ||
</phpunit> |
Oops, something went wrong.