-
-
Notifications
You must be signed in to change notification settings - Fork 71
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 41e9b10
Showing
37 changed files
with
2,955 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,4 @@ | ||
/coverage/ | ||
/vendor/ | ||
/node_modules/ | ||
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,7 @@ | ||
tools: | ||
php_sim: true | ||
php_pdepend: true | ||
php_analyzer: true | ||
filter: | ||
excluded_paths: | ||
- '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,20 @@ | ||
language: php | ||
|
||
php: | ||
- 7.0 | ||
- 7.1 | ||
|
||
install: | ||
- travis_retry composer require satooshi/php-coveralls:~0.6@stable | ||
|
||
before_script: | ||
- mkdir -p build/logs | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: | ||
- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
- ./vendor/bin/phpcs src --standard=psr2 | ||
|
||
after_success: | ||
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' |
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) 2015-2017 Jarek Tkaczyk <[email protected]> | ||
|
||
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,35 @@ | ||
# Sofa/Eloquence | ||
|
||
[![Build Status](https://travis-ci.org/jarektkaczyk/eloquence-base.svg)](https://travis-ci.org/jarektkaczyk/eloquence-base) [![Coverage Status](https://coveralls.io/repos/jarektkaczyk/eloquence-base/badge.svg)](https://coveralls.io/r/jarektkaczyk/eloquence-base) [![Code Quality](https://scrutinizer-ci.com/g/jarektkaczyk/eloquence-base/badges/quality-score.png)](https://scrutinizer-ci.com/g/jarektkaczyk/eloquence-base) [![Downloads](https://poser.pugx.org/sofa/eloquence-base/downloads)](https://packagist.org/packages/sofa/eloquence-base) [![stable](https://poser.pugx.org/sofa/eloquence-base/v/stable.svg)](https://packagist.org/packages/sofa/eloquence-base) | ||
|
||
Easy and flexible extensions for the [Eloquent ORM](https://laravel.com/docs/eloquent). | ||
|
||
**If I'm saving you some time with my work, you can back me up on [Patreon page](https://patreon.com/jarektkaczyk).** | ||
|
||
Currently available extensions: | ||
|
||
1. [Base - Searchable](https://github.com/jarektkaczyk/eloquence-base) query - crazy-simple fulltext search through any related model | ||
1. [Validable](https://github.com/jarektkaczyk/eloquence-validable) - self-validating models | ||
2. [Mappable](https://github.com/jarektkaczyk/eloquence-mappable) -map attributes to table fields and/or related models | ||
3. [Metable](https://github.com/jarektkaczyk/eloquence-metable) - meta attributes made easy | ||
4. [Mutable](https://github.com/jarektkaczyk/eloquence-mutable) - flexible attribute get/set mutators with quick setup | ||
5. [Mutator](https://github.com/jarektkaczyk/eloquence-mutable) - pipe-based mutating | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require sofa/eloquence-base | ||
``` | ||
|
||
**Check the [documentation](https://github.com/jarektkaczyk/eloquence/wiki) for installation and usage info, [website](http://softonsofa.com/tag/eloquence/) for examples and [API reference](http://jarektkaczyk.github.io/eloquence-api)** | ||
|
||
## Contribution | ||
|
||
Shout out to all the Contributors! | ||
|
||
All contributions are welcome, PRs must be **tested** and **PSR-2 compliant**. | ||
|
||
To validate your builds before committing use the following composer command: | ||
```bash | ||
composer test | ||
``` |
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,60 @@ | ||
{ | ||
"name": "sofa/eloquence-base", | ||
"description": "Flexible Searchable, Mappable, Metable, Validation and more extensions for Laravel Eloquent ORM.", | ||
"license": "MIT", | ||
"support": { | ||
"issues": "https://github.com/jarektkaczyk/eloquence-base/issues", | ||
"source": "https://github.com/jarektkaczyk/eloquence-base" | ||
}, | ||
"keywords": [ | ||
"laravel", | ||
"eloquent", | ||
"metable", | ||
"searchable", | ||
"mappable", | ||
"mutable" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Jarek Tkaczyk", | ||
"email": "[email protected]", | ||
"homepage": "https://softonsofa.com/", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0.0", | ||
"sofa/hookable": "5.5.*", | ||
"illuminate/database": "5.5.*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "4.5.0", | ||
"squizlabs/php_codesniffer": "2.3.3", | ||
"mockery/mockery": "0.9.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Sofa\\Eloquence\\": "src" | ||
}, | ||
"files": [ | ||
"src/helpers.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Sofa\\Eloquence\\Tests\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Sofa\\Eloquence\\BaseServiceProvider" | ||
] | ||
} | ||
}, | ||
"minimum-stability": "stable", | ||
"scripts": { | ||
"test": "phpunit && ./vendor/bin/phpcs src --standard=psr2 --report=diff --colors", | ||
"phpcs": "./vendor/bin/phpcs src --standard=psr2 --report=diff --colors" | ||
} | ||
} |
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 backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false"> | ||
<testsuites> | ||
<testsuite name="Eloquence"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</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,38 @@ | ||
<?php | ||
|
||
namespace Sofa\Eloquence\AttributeCleaner; | ||
|
||
use Sofa\Eloquence\Contracts\CleansAttributes; | ||
|
||
class Observer | ||
{ | ||
/** | ||
* Saving event handler. | ||
* | ||
* @param mixed $model | ||
* @return void | ||
*/ | ||
public function saving($model) | ||
{ | ||
if ($model instanceof CleansAttributes) { | ||
$this->cleanAttributes($model); | ||
} | ||
} | ||
|
||
/** | ||
* Get rid of attributes that are not correct columns on this model's table. | ||
* | ||
* @param \Sofa\Eloquence\Contracts\CleansAttributes $model | ||
* @return void | ||
*/ | ||
protected function cleanAttributes(CleansAttributes $model) | ||
{ | ||
$dirty = array_keys($model->getDirty()); | ||
|
||
$invalidColumns = array_diff($dirty, $model->getColumnListing()); | ||
|
||
foreach ($invalidColumns as $column) { | ||
unset($model->{$column}); | ||
} | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace Sofa\Eloquence; | ||
|
||
use Sofa\Eloquence\Builder; | ||
use Sofa\Eloquence\Relations\JoinerFactory; | ||
use Sofa\Eloquence\Searchable\ParserFactory; | ||
use Illuminate\Support\ServiceProvider as BaseProvider; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class BaseServiceProvider extends BaseProvider | ||
{ | ||
public function boot() | ||
{ | ||
Builder::setJoinerFactory(new JoinerFactory); | ||
|
||
Builder::setParserFactory(new ParserFactory); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->registerJoiner(); | ||
$this->registerParser(); | ||
} | ||
|
||
/** | ||
* Register relation joiner factory. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerJoiner() | ||
{ | ||
$this->app->singleton('eloquence.joiner', function () { | ||
return new JoinerFactory; | ||
}); | ||
|
||
$this->app->alias('eloquence.joiner', 'Sofa\Eloquence\Contracts\Relations\JoinerFactory'); | ||
} | ||
|
||
/** | ||
* Register serachable parser factory. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerParser() | ||
{ | ||
$this->app->singleton('eloquence.parser', function () { | ||
return new ParserFactory; | ||
}); | ||
|
||
$this->app->alias('eloquence.parser', 'Sofa\Eloquence\Contracts\Relations\ParserFactory'); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return ['eloquence.joiner', 'eloquence.parser']; | ||
} | ||
} |
Oops, something went wrong.