-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of eloquent sentiment package
- Loading branch information
Paul Dixon
committed
Feb 21, 2016
0 parents
commit a91ca0a
Showing
20 changed files
with
694 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 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
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,3 @@ | ||
build | ||
composer.lock | ||
vendor |
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,2 @@ | ||
tools: | ||
external_code_coverage: 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,22 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
matrix: | ||
include: | ||
- php: 5.5 | ||
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source | ||
|
||
script: | ||
- php vendor/bin/phpunit -c phpunit.xml | ||
|
||
after_script: | ||
- php vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml |
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,9 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## [Unreleased] | ||
|
||
## 0.0.1 - 2015-02-21 | ||
### Added | ||
- Initial implementation for adding sentiment to eloquent models. |
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,31 @@ | ||
# CONTRIBUTING | ||
|
||
Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests. | ||
|
||
## Guidelines | ||
|
||
* Please follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) and [PHP-FIG Naming Conventions](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md). | ||
* Ensure that the current tests pass, and if you've added something new, add the tests where relevant. | ||
* Remember that we follow [SemVer](http://semver.org). If you are changing the behaviour, or the public api, you may need to update the docs. | ||
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash](http://git-scm.com/book/en/Git-Tools-Rewriting-History) them before submitting. | ||
* You may also need to [rebase](http://git-scm.com/book/en/Git-Branching-Rebasing) to avoid merge conflicts. | ||
|
||
## Running Tests | ||
|
||
You will need an install of [Composer](https://getcomposer.org) before continuing. | ||
|
||
First, install the dependencies: | ||
|
||
```bash | ||
$ composer install | ||
``` | ||
|
||
Then run phpunit: | ||
|
||
```bash | ||
$ vendor/bin/phpunit | ||
``` | ||
|
||
If the test suite passes on your local machine you should be good to go. | ||
|
||
When you make a pull request, the tests will automatically be run again by [Travis CI](https://travis-ci.org/) on multiple php versions and |
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 Paul Dixon <[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,73 @@ | ||
# Eloquent Sentiment | ||
|
||
Laravel 5 package for adding sentiment to eloquent models. | ||
|
||
## Installation | ||
|
||
This package can be installed through Composer. | ||
```bash | ||
composer require mintbridge/eloquent-sentiment | ||
``` | ||
|
||
Once installed add the service provider and facade to your app config | ||
```php | ||
// config/app.php | ||
|
||
'providers' => [ | ||
'...', | ||
'Mintbridge\EloquentSentiment\SentimentServiceProvider', | ||
]; | ||
|
||
'aliases' => [ | ||
'...', | ||
'Sentiment' => 'Mintbridge\EloquentSentiment\SentimentFacade', | ||
]; | ||
``` | ||
|
||
You'll also need to publish and run the migration in order to create the database table. | ||
``` | ||
php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="config" | ||
php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="migrations" | ||
php artisan migrate | ||
``` | ||
|
||
The configuration will be written to ```config/eloquent-sentiment.php```. The options have sensible defaults but you should change the user model to match the one used in your application. | ||
|
||
## Usage | ||
|
||
This package will allow your users to add sentiment to models used in your application. To do so the models that you would like to be sentimentable must use the `Sentimentable` trait and implement `SentimentableInterface`. | ||
|
||
```php | ||
use Mintbridge\EloquentSentiment\Sentimentable; | ||
use Mintbridge\EloquentSentiment\SentimentableInterface; | ||
|
||
class Article extends Eloquent implements SentimentableInterface { | ||
|
||
use Sentimentable; | ||
... | ||
} | ||
``` | ||
|
||
Sentiment can be added to models by using the `SentimentManager` or more easily with the Sentiment facade: | ||
|
||
```php | ||
$article = Article::find(1); | ||
|
||
// add article as a favourite | ||
Sentiment::add('like', $article); | ||
|
||
// remove article from by a favourite | ||
Sentiment::remove('like', $article); | ||
|
||
// toggle article as being a favourite | ||
Sentiment::toggle('like', $article); | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. | ||
|
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,37 @@ | ||
{ | ||
"name": "mintbridge/eloquent-sentiment", | ||
"description": "An eloquent package for adding sentiment to eloquent models.", | ||
"keywords": ["eloquent", "sentiment", "emoticon", "laravel"], | ||
"license": "MIT", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Paul Dixon", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/database": "5.*", | ||
"illuminate/support": "5.*" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "^0.9.4", | ||
"phpunit/phpunit": "4.2.*", | ||
"scrutinizer/ocular": "^1.1" | ||
}, | ||
"suggest": { | ||
"illuminate/support": "Required for Laravel support" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Mintbridge\\EloquentSentiment\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Mintbridge\\EloquentSentiment\\Test\\": "tests/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Eloquent Sentiment Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-text" target="php://stdout" /> | ||
<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,69 @@ | ||
<?php | ||
|
||
namespace Mintbridge\EloquentSentiment; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Config; | ||
|
||
class Sentiment extends Model | ||
{ | ||
const ATTR_ID = 'id'; | ||
const ATTR_SENTIMENTABLE_ID = 'sentimentable_id'; | ||
const ATTR_SENTIMENTABLE_TYPE = 'sentimentable_type'; | ||
const ATTR_USER_ID = 'user_id'; | ||
const ATTR_SENTIMENT = 'sentiment'; | ||
const ATTR_CREATED_AT = 'created_at'; | ||
const ATTR_UPDATED_AT = 'updated_at'; | ||
|
||
/** | ||
* The database table used by the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'sentiments'; | ||
|
||
/** | ||
* The attributes that should be mutated to dates. | ||
* | ||
* @var array | ||
*/ | ||
protected $dates = [ | ||
self::ATTR_CREATED_AT, | ||
self::ATTR_UPDATED_AT, | ||
]; | ||
|
||
/** | ||
* The attributes that should be casted to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
]; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
self::ATTR_SENTIMENT, | ||
]; | ||
|
||
/** | ||
* Get the user that the perform the action. | ||
* | ||
* @return object | ||
*/ | ||
public function user() | ||
{ | ||
return $this->belongsTo(Config::get('eloquent-sentiment.user'), self::ATTR_USER_ID); | ||
} | ||
|
||
/** | ||
* Get all of the owning sentimentable models. | ||
*/ | ||
public function sentimentable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Mintbridge\EloquentSentiment; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class SentimentFacade extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'sentiments'; | ||
} | ||
} |
Oops, something went wrong.