Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
- lock to KnpLabs\DoctrineBehaviors stable version v1.0.2
- bump min version to PHP 5.5
- Zenify\CodingStandard updated to v2.0
- nicer badges + code quality badge added
  • Loading branch information
Tomas Votruba committed Dec 9, 2014
1 parent 8796a77 commit c9d1eb1
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 146 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- hhvm
Expand All @@ -17,10 +16,9 @@ before_script:

script:
- vendor/bin/tester -c tests/php.ini-unix tests -s
- vendor/bin/phpcs src --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/ruleset.xml
- vendor/bin/phpcs src --standard=vendor/mikulas/code-sniffs/cs/ruleset.xml --sniffs=cs.Debug.DebugFunctionCall,cs.Formatting.UseInAlphabeticalOrder,cs.Formatting.UseWithoutStartingSeparator
- vendor/bin/phpcs tests/ZenifyTests/DoctrineBehaviors --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/ruleset.xml
- vendor/bin/phpcs tests/ZenifyTests/DoctrineBehaviors --standard=vendor/mikulas/code-sniffs/cs/ruleset.xml --sniffs=cs.Debug.DebugFunctionCall,cs.Formatting.UseInAlphabeticalOrder,cs.Formatting.UseWithoutStartingSeparator
# php code sniffer
- vendor/bin/phpcs src --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/code-sniffer-ruleset.xml
- vendor/bin/phpcs tests/ZenifyTests/DoctrineBehaviors --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/code-sniffer-ruleset.xml

after_failure:
- 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'
23 changes: 11 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
{ "name": "Tomáš Votruba", "homepage": "http://tomasvotruba.cz" }
],
"require": {
"php": ">=5.4",
"knplabs/doctrine-behaviors": "~1.1@dev",
"php": ">=5.5",
"knplabs/doctrine-behaviors": "~1.0.2",
"kdyby/events": "~2.0"
},
"require-dev": {
"kdyby/doctrine": "~2.0",
"nette/bootstrap": "~2.0",
"nette/di": "~2.0",
"nette/http": "~2.0",
"nette/mail": "~2.0",
"nette/robot-loader": "~2.0",
"nette/safe-stream": "~2.0",
"nette/security": "~2.0",
"nette/utils": "~2.0",
"nette/tester": "~1.2",
"nette/bootstrap": "~2.2",
"nette/di": "~2.2",
"nette/http": "~2.2",
"nette/mail": "~2.2",
"nette/safe-stream": "~2.2",
"nette/security": "~2.2",
"nette/utils": "~2.2",
"nette/tester": "~1.3",
"tracy/tracy": "~2.0",
"zenify/coding-standard": "~1.0",
"zenify/coding-standard": "~2.0",
"jakub-onderka/php-parallel-lint": "~0.8"
},
"autoload": {
Expand Down
15 changes: 9 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Zenify/DoctrineBehaviors

[![Build Status](https://travis-ci.org/Zenify/DoctrineBehaviors.svg?branch=master)](https://travis-ci.org/Zenify/DoctrineBehaviors)
[![Downloads this Month](https://img.shields.io/packagist/dm/zenify/doctrine-behaviors.svg)](https://packagist.org/packages/zenify/doctrine-behaviors)
[![Latest stable](https://img.shields.io/packagist/v/zenify/doctrine-behaviors.svg)](https://packagist.org/packages/zenify/doctrine-behaviors)
[![Build Status](https://img.shields.io/travis/Zenify/DoctrineBehaviors.svg?style=flat-square)](https://travis-ci.org/Zenify/DoctrineBehaviors)
[![Quality Score](https://img.shields.io/scrutinizer/g/Zenify/DoctrineBehaviors.svg?style=flat-square)](https://scrutinizer-ci.com/g/Zenify/DoctrineBehaviors)
[![Downloads this Month](https://img.shields.io/packagist/dm/zenify/doctrine-behaviors.svg?style=flat-square)](https://packagist.org/packages/zenify/doctrine-behaviors)
[![Latest stable](https://img.shields.io/packagist/v/zenify/doctrine-behaviors.svg?style=flat-square)](https://packagist.org/packages/zenify/doctrine-behaviors)


Port of [KnpLabs/DoctrineBehaviors](https://github.com/KnpLabs/DoctrineBehaviors) to Nette
Expand All @@ -22,10 +23,9 @@ For implementation to entities, check [tests](https://github.com/KnpLabs/Doctrin

## Installation

To get the lastest version run [Composer](http://getcomposer.org/) commands:
Install the latest version via Composer:

```sh
$ composer require "knplabs/doctrine-behaviors:@dev"
$ composer require zenify/doctrine-behaviors
```

Expand All @@ -52,18 +52,20 @@ Place trait to your entity:
```php
class Article
{

use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
// returns translated property for $article->getTitle() or $article->title
use Zenify\DoctrineBehaviors\Entities\Attributes\Translatable;

}
```

And it's translation entity:
And its translation entity:

```php
class ArticleTranslation
{

use Knp\DoctrineBehaviors\Model\Translatable\Translation;

/**
Expand All @@ -89,6 +91,7 @@ Place trait to your entity to ad `$createdAt` and `$updatedAt` properties:
```php
class Article
{

use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;

}
Expand Down
9 changes: 4 additions & 5 deletions src/DI/BehaviorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Zenify\DoctrineBehaviors\DI;

use Knp\DoctrineBehaviors\Reflection\ClassAnalyzer;
use Nette\DI\Compiler;
use Nette\DI\CompilerExtension;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceDefinition;
use Nette\DI\Statement;

Expand All @@ -22,15 +22,14 @@ abstract class BehaviorExtension extends CompilerExtension
*/
protected function getClassAnalyzer()
{
/** @var ContainerBuilder $builder */
$builder = $this->getContainerBuilder();

if ($builder->hasDefinition('knp.classAnalyzer')) {
return $builder->getDefinition('knp.classAnalyzer');
}

return $builder->addDefinition('knp.classAnalyzer')
->setClass('Knp\DoctrineBehaviors\Reflection\ClassAnalyzer');
->setClass(ClassAnalyzer::class);
}


Expand All @@ -47,9 +46,9 @@ protected function buildDefinition($value)
$builder = $this->getContainerBuilder();
$definition = $builder->addDefinition($this->prefix(md5($value)));

list($definition->factory) = Compiler::filterArguments(array(
list($definition->factory) = Compiler::filterArguments([
is_string($value) ? new Statement($value) : $value
));
]);

list($resolverClass) = (array) $builder->normalizeEntity($definition->getFactory()->getEntity());
if (class_exists($resolverClass)) {
Expand Down
13 changes: 8 additions & 5 deletions src/DI/BlameableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\Model\Blameable\Blameable;
use Knp\DoctrineBehaviors\ORM\Blameable\BlameableListener;
use Nette;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;
use Zenify\DoctrineBehaviors\Blameable\UserCallable;


class BlameableExtension extends BehaviorExtension
Expand All @@ -19,10 +22,10 @@ class BlameableExtension extends BehaviorExtension
/**
* @var array
*/
protected $default = [
private $default = [
'isRecursive' => TRUE,
'trait' => 'Knp\DoctrineBehaviors\Model\Blameable\Blameable',
'userCallable' => 'Zenify\DoctrineBehaviors\Blameable\UserCallable',
'trait' => Blameable::class,
'userCallable' => UserCallable::class,
'userEntity' => NULL
];

Expand All @@ -36,7 +39,7 @@ public function loadConfiguration()
$userCallable = $this->buildDefinition($config['userCallable']);

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\Blameable\BlameableSubscriber', [
->setClass(BlameableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
$config['trait'],
Expand All @@ -51,7 +54,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'trait', 'type');
Expand Down
10 changes: 6 additions & 4 deletions src/DI/GeocodableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\Model\Geocodable\Geocodable;
use Knp\DoctrineBehaviors\ORM\Geocodable\GeocodableListener;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;

Expand All @@ -18,9 +20,9 @@ class GeocodableExtension extends BehaviorExtension
/**
* @var array
*/
protected $default = [
private $default = [
'isRecursive' => TRUE,
'trait' => 'Knp\DoctrineBehaviors\Model\Geocodable\Geocodable',
'trait' => Geocodable::class,
'geolocationCallable' => NULL
];

Expand All @@ -34,7 +36,7 @@ public function loadConfiguration()
$geolocationCallable = $this->buildDefinition($config['geolocationCallable']);

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\Geocodable\GeocodableSubscriber', [
->setClass(GeocodableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
$config['trait'],
Expand All @@ -48,7 +50,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'trait', 'type');
Expand Down
10 changes: 6 additions & 4 deletions src/DI/LoggableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\ORM\Loggable\LoggableListener;
use Nette;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;
use Zenify\DoctrineBehaviors\Loggable\LoggerCallable;


class LoggableExtension extends BehaviorExtension
Expand All @@ -19,9 +21,9 @@ class LoggableExtension extends BehaviorExtension
/**
* @var array
*/
protected $default = [
private $default = [
'isRecursive' => TRUE,
'loggerCallable' => 'Zenify\DoctrineBehaviors\Loggable\LoggerCallable'
'loggerCallable' => LoggerCallable::class
];


Expand All @@ -34,7 +36,7 @@ public function loadConfiguration()
$loggerCallable = $this->buildDefinition($config['loggerCallable']);

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\Loggable\LoggableSubscriber', [
->setClass(LoggableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
'@' . $loggerCallable->getClass()
Expand All @@ -47,7 +49,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'loggerCallable', 'type');
Expand Down
8 changes: 5 additions & 3 deletions src/DI/SluggableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\Model\Sluggable\Sluggable;
use Knp\DoctrineBehaviors\ORM\Sluggable\SluggableListener;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;

Expand All @@ -20,7 +22,7 @@ class SluggableExtension extends BehaviorExtension
*/
protected $default = [
'isRecursive' => TRUE,
'trait' => 'Knp\DoctrineBehaviors\Model\Sluggable\Sluggable'
'trait' => Sluggable::class
];


Expand All @@ -31,7 +33,7 @@ public function loadConfiguration()
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\Sluggable\SluggableSubscriber', [
->setClass(SluggableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
$config['trait']
Expand All @@ -44,7 +46,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'trait', 'type');
Expand Down
10 changes: 6 additions & 4 deletions src/DI/SoftDeletableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletable;
use Knp\DoctrineBehaviors\ORM\SoftDeletable\SoftDeletableListener;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;

Expand All @@ -18,9 +20,9 @@ class SoftDeletableExtension extends BehaviorExtension
/**
* @var array
*/
protected $default = [
private $default = [
'isRecursive' => TRUE,
'trait' => 'Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletable'
'trait' => SoftDeletable::class
];


Expand All @@ -31,7 +33,7 @@ public function loadConfiguration()
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\SoftDeletable\SoftDeletableSubscriber', [
->setClass(SoftDeletableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
$config['trait']
Expand All @@ -44,7 +46,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'trait', 'type');
Expand Down
10 changes: 6 additions & 4 deletions src/DI/TimestampableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Zenify\DoctrineBehaviors\DI;

use Kdyby;
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
use Knp\DoctrineBehaviors\ORM\Timestampable\TimestampableListener;
use Nette\Utils\AssertionException;
use Nette\Utils\Validators;

Expand All @@ -18,9 +20,9 @@ class TimestampableExtension extends BehaviorExtension
/**
* @var array
*/
protected $default = [
private $default = [
'isRecursive' => TRUE,
'trait' => 'Knp\DoctrineBehaviors\Model\Timestampable\Timestampable'
'trait' => Timestampable::class
];


Expand All @@ -31,7 +33,7 @@ public function loadConfiguration()
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('listener'))
->setClass('Knp\DoctrineBehaviors\ORM\Timestampable\TimestampableSubscriber', [
->setClass(TimestampableListener::class, [
'@' . $this->getClassAnalyzer()->getClass(),
$config['isRecursive'],
$config['trait']
Expand All @@ -44,7 +46,7 @@ public function loadConfiguration()
/**
* @throws AssertionException
*/
protected function validateConfigTypes(array $config)
private function validateConfigTypes(array $config)
{
Validators::assertField($config, 'isRecursive', 'bool');
Validators::assertField($config, 'trait', 'type');
Expand Down
Loading

0 comments on commit c9d1eb1

Please sign in to comment.