Skip to content

Commit

Permalink
First official release
Browse files Browse the repository at this point in the history
Some parts are still missing:

- Complete test coverage (although it is quite far along)
- Sensible documentation
- There might still be some errors in existing class
  documentation, as things were hurried a bit to finally have
  an official release

That is why this is a 0.2 release, meaning we are not sure yet
if everything will stay exactly the same.
  • Loading branch information
iquito committed Apr 23, 2019
0 parents commit ffd60e8
Show file tree
Hide file tree
Showing 61 changed files with 10,781 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml export-ignore
/phpcs.xml export-ignore
/captainhook.json export-ignore
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.idea
/composer.lock
/vendor
/.phpunit*
/tests/_output
/tests/_reports
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Andreas Leathley

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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Squirrel Entities Component
===========================

Simple, safe and flexible implementation of handling SQL entities and repositories as well as multi-table SQL queries while staying lightweight and easy to understand and use.

This package is still not 100% finished - some tests are missing (although the most important parts have test coverage) and the documentation will be a challenge. For now it is released so it can be used as-is and improved over time.
60 changes: 60 additions & 0 deletions captainhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams",
"options": {
"subjectLength": 50,
"bodyLineLength": 72
},
"conditions": []
}
]
},
"pre-push": {
"enabled": false,
"actions": []
},
"pre-commit": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting",
"options": [],
"conditions": []
},
{
"action": "vendor/bin/phpunit",
"options": [],
"conditions": []
},
{
"action": "vendor/bin/phpstan analyse src --level=7",
"options": [],
"conditions": []
},
{
"action": "vendor/bin/phpcs --standard=psr2 --extensions=php src tests",
"options": [],
"conditions": []
}
]
},
"prepare-commit-msg": {
"enabled": false,
"actions": []
},
"post-commit": {
"enabled": false,
"actions": []
},
"post-merge": {
"enabled": false,
"actions": []
},
"post-checkout": {
"enabled": false,
"actions": []
}
}
62 changes: 62 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "squirrelphp/entities",
"type": "library",
"description": "Simple, safe and flexible implementation of handling SQL entities and repositories as well as multi-table SQL queries while staying lightweight and straightforward.",
"keywords": [
"php",
"mysql",
"pgsql",
"sqlite",
"database",
"entities",
"repositories"
],
"homepage": "https://github.com/squirrelphp/entities",
"license": "MIT",
"authors": [
{
"name": "Andreas Leathley",
"email": "[email protected]"
}
],
"require": {
"php": "^7.2",
"symfony/console": "^4.0",
"symfony/finder": "^4.0",
"doctrine/annotations": "^1.4",
"squirrelphp/queries": "^0.5.4"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpstan/phpstan": "^0.11.5",
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.0",
"captainhook/plugin-composer": "^4.0"
},
"suggest": {
"squirrelphp/queries-bundle": "Symfony integration of squirrel/queries - automatic assembling of decorated connections",
"squirrelphp/entities-bundle": "Automatic integration of squirrel/entities in Symfony"
},
"config": {
"sort-packages": true
},
"bin": [
"squirrel_repositories_generate"
],
"autoload": {
"psr-4": {
"Squirrel\\Entities\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Squirrel\\Entities\\Tests\\": "tests/"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse src --level=7",
"phpunit": "vendor/bin/phpunit --colors=always",
"phpcs": "vendor/bin/phpcs --standard=psr2 --extensions=php src tests",
"codecoverage": "vendor/bin/phpunit --coverage-html tests/_reports"
}
}
21 changes: 21 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
49 changes: 49 additions & 0 deletions squirrel_repositories_generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env php
<?php

use Composer\Autoload\ClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

foreach ([
__DIR__ . '/../autoload.php',
__DIR__ . '/../../autoload.php',
__DIR__ . '/vendor/autoload.php',
] as $file) {
if (file_exists($file)) {
/**
* @var ClassLoader $loader
*/
$loader = require $file;

break;
}
}

// Needed so annotation classes are loaded, but will be removed in doctrine/annotations 2.0,
// so we might need to change this to make it work for that version when it is released
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

// Define the necessary command line options and defaults
$inputDefinition = new InputDefinition();
$inputDefinition->addOption(new InputOption(
'source-dir',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Source directories (relative to current directory) where entities will be searched recursively'
));

$input = new ArgvInput(null, $inputDefinition);
$srcDirectories = $input->getOption('source-dir');

// Execute command to generate repositories
$cmd = new \Squirrel\Entities\Generate\RepositoriesGenerateCommand($srcDirectories);
$log = $cmd();

// Add summary of processed entities
$log[] = "\n" . count($log) . ' entities found for which repositories were generated.' . "\n";

// Show log
echo implode("\n", $log);
10 changes: 10 additions & 0 deletions src/Action/ActionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Squirrel\Entities\Action;

/**
* Marker for repository actions so an exception can reference the right origin (higher up in stack trace)
*/
interface ActionInterface
{
}
51 changes: 51 additions & 0 deletions src/Action/CountEntries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Squirrel\Entities\Action;

use Squirrel\Entities\RepositoryReadOnlyInterface;

/**
* Count query builder as a fluent object - build query and return number
*/
class CountEntries implements ActionInterface
{
/**
* @var RepositoryReadOnlyInterface Repository we call to execute the built query
*/
private $repository;

/**
* @var array WHERE restrictions in query
*/
private $where = [];

/**
* @var bool Whether the SELECT query should block the scanned entries
*/
private $blocking = false;

public function __construct(RepositoryReadOnlyInterface $repository)
{
$this->repository = $repository;
}

public function where(array $whereClauses): self
{
$this->where = $whereClauses;
return $this;
}

public function blocking(bool $active = true): self
{
$this->blocking = $active;
return $this;
}

public function getNumber(): int
{
return $this->repository->count([
'where' => $this->where,
'lock' => $this->blocking,
]);
}
}
50 changes: 50 additions & 0 deletions src/Action/DeleteEntries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Squirrel\Entities\Action;

use Squirrel\Entities\RepositoryWriteableInterface;

/**
* Delete query builder as a fluent object - build query and execute it
*/
class DeleteEntries implements ActionInterface
{
/**
* @var RepositoryWriteableInterface Repository we call to execute the built query
*/
private $repository;

/**
* @var array WHERE restrictions in query
*/
private $where = [];

public function __construct(RepositoryWriteableInterface $repository)
{
$this->repository = $repository;
}

public function where(array $whereClauses): self
{
$this->where = $whereClauses;
return $this;
}

/**
* Write changes to database
*/
public function write(): void
{
$this->repository->delete($this->where);
}

/**
* Write changes to database and return affected entries number
*
* @return int Number of affected entries in database
*/
public function writeAndReturnAffectedNumber(): int
{
return $this->repository->delete($this->where);
}
}
Loading

0 comments on commit ffd60e8

Please sign in to comment.