-
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.
- Loading branch information
0 parents
commit 78a1da2
Showing
23 changed files
with
543 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,12 @@ | ||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
filter: | ||
paths: [src/*] | ||
checks: | ||
php: true | ||
tools: | ||
external_code_coverage: | ||
runs: 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,24 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
before_install: | ||
- composer self-update | ||
|
||
install: composer update --prefer-source | ||
|
||
script: phpunit --coverage-clover=coverage.clover | ||
|
||
after_script: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Run Open Code | ||
|
||
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,42 @@ | ||
{ | ||
"name": "runopencode/traitor-bundle", | ||
"description": "Inject into services via method injection based on used traits of defined service classes.", | ||
"keywords": [ | ||
"dependency injection", "setter injection", "method injection", "traits based injection", "aware injection" | ||
], | ||
"type": "symfony-bundle", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nikola Svitlica a.k.a TheCelavi", | ||
"email": "[email protected]", | ||
"homepage": "http://www.runopencode.com", | ||
"role": "Project lead" | ||
}, | ||
{ | ||
"name": "RunOpenCode members", | ||
"email": "[email protected]", | ||
"homepage": "http://www.runopencode.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"RunOpenCode\\Bundle\\Traitor\\": "src/RunOpenCode/Bundle/Traitor/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"RunOpenCode\\Bundle\\Traitor\\Tests\\": "test/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=5.5", | ||
"symfony/framework-bundle": "~2.8|~3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.8|~5.0", | ||
"symfony/phpunit-bridge": "~2.7", | ||
"symfony/debug": "~2.7", | ||
"matthiasnoback/symfony-dependency-injection-test": "^0.7.6" | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/RunOpenCode/Bundle/Traitor/DependencyInjection/CompilerPass.php
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 @@ | ||
<?php | ||
/* | ||
* This file is part of the TraitorBundle, an RunOpenCode project. | ||
* | ||
* (c) 2016 RunOpenCode | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace RunOpenCode\Bundle\Traitor\DependencyInjection; | ||
|
||
|
||
class CompilerPass | ||
{ | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
src/RunOpenCode/Bundle/Traitor/DependencyInjection/Configuration.php
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,83 @@ | ||
<?php | ||
/* | ||
* This file is part of the TraitorBundle, an RunOpenCode project. | ||
* | ||
* (c) 2016 RunOpenCode | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace RunOpenCode\Bundle\Traitor\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
|
||
$rootNode = $treeBuilder->root('run_open_code_traitor'); | ||
|
||
$rootNode | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->booleanNode('use_common_traits') | ||
->defaultFalse() | ||
->info('For sake of productivity, some of the common Symfony and vendor traits, as well as traits from this library, can be automatically added to "inject" definition.') | ||
->end() | ||
->arrayNode('inject') | ||
->useAttributeAsKey('trait') | ||
->prototype('array') | ||
->validate() | ||
->ifTrue(function($value) { | ||
|
||
if (!is_array($value) || 2 !== count($value)) { | ||
return true; | ||
} | ||
|
||
if (!is_string($value[0])) { | ||
return true; | ||
} | ||
|
||
if (!is_array($value[1])) { | ||
return true; | ||
} | ||
|
||
foreach ($value[1] as $arg) { | ||
|
||
if (!is_string($arg)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}) | ||
->thenInvalid('Expected proper setter injection definition.') | ||
->end() | ||
->prototype('variable') | ||
->end() | ||
->end() | ||
->end() | ||
->arrayNode('filters') | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->arrayNode('tags') | ||
->prototype('scalar') | ||
->end() | ||
->end() | ||
->arrayNode('namespaces') | ||
->prototype('scalar') | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/RunOpenCode/Bundle/Traitor/DependencyInjection/Extension.php
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,56 @@ | ||
<?php | ||
/* | ||
* This file is part of the TraitorBundle, an RunOpenCode project. | ||
* | ||
* (c) 2016 RunOpenCode | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace RunOpenCode\Bundle\Traitor\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension; | ||
|
||
class Extension extends BaseExtension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
if ($config['use_common_traits']) { | ||
$config['inject'] = array_merge($config['inject'], $this->getCommonTraitsInjectionDefinitions()); | ||
} | ||
} | ||
|
||
public function getAlias() | ||
{ | ||
return 'run_open_code_traitor'; | ||
} | ||
|
||
protected function getCommonTraitsInjectionDefinitions() | ||
{ | ||
return array( | ||
'Symfony\Component\DependencyInjection\ContainerAwareTrait' => array('setContainer', array('@service_container')), | ||
'Psr\Log\LoggerAwareTrait' => array('setLogger', array('@logger')), | ||
'RunOpenCode\Bundle\Traitor\Traits\DoctrineAwareTrait' => array('setDoctrine', array('@doctrine')), | ||
'RunOpenCode\Bundle\Traitor\Traits\EventDispatcherAwareTrait' => array('setEventDispatcher', array('@event_dispatcher')), | ||
'RunOpenCode\Bundle\Traitor\Traits\FilesystemAwareTrait' => array('setFilesystem', array('@filesystem')), | ||
'RunOpenCode\Bundle\Traitor\Traits\KernelAwareTrait' => array('setKernel', array('@kernel')), | ||
'RunOpenCode\Bundle\Traitor\Traits\MailerAwareInterface' => array('setMailer', array('@mailer')), | ||
'RunOpenCode\Bundle\Traitor\Traits\PropertyAccessorAwareTrait' => array('setPropertyAccessor', array('@property_accessor')), | ||
'RunOpenCode\Bundle\Traitor\Traits\RequestStackAwareTrait' => array('setRequestStack', array('@request_stack')), | ||
'RunOpenCode\Bundle\Traitor\Traits\RouterAwareTrait' => array('setRouter', array('@router')), | ||
'RunOpenCode\Bundle\Traitor\Traits\AuthorizationCheckerAwareTrait' => array('setAuthorizationChecker', array('@security.authorization_checker')), | ||
'RunOpenCode\Bundle\Traitor\Traits\SessionAwareTrait' => array('setSession', array('@session')), | ||
'RunOpenCode\Bundle\Traitor\Traits\TwigAwareTrait' => array('setTwig', array('@twig')), | ||
'RunOpenCode\Bundle\Traitor\Traits\TranslatorAwareTrait' => array('setTranslator', array('@translator')), | ||
'RunOpenCode\Bundle\Traitor\Traits\ValidatorAwareTrait' => array('setValidator', array('@validator')) | ||
); | ||
} | ||
} | ||
|
Empty file.
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 @@ | ||
<?php | ||
/* | ||
* This file is part of the TraitorBundle, an RunOpenCode project. | ||
* | ||
* (c) 2016 RunOpenCode | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace RunOpenCode\Bundle\Traitor; | ||
|
||
use RunOpenCode\Bundle\Traitor\DependencyInjection\Extension; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class TraitorBundle extends Bundle | ||
{ | ||
public function getContainerExtension() | ||
{ | ||
return new Extension(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/AuthorizationCheckerAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||
|
||
trait AuthorizationCheckerAwareTrait | ||
{ | ||
protected $authorizationChecker; | ||
|
||
public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) | ||
{ | ||
$this->authorizationChecker = $authorizationChecker; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/DoctrineAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Bridge\Doctrine\RegistryInterface; | ||
|
||
trait DoctrineAwareTrait | ||
{ | ||
protected $doctrine; | ||
|
||
public function setDoctrine(RegistryInterface $doctrine) | ||
{ | ||
$this->doctrine = $doctrine; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/EventDispatcherAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
trait EventDispatcherAwareTrait | ||
{ | ||
protected $eventDispatcher; | ||
|
||
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/FilesystemAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class FilesystemAwareTrait | ||
{ | ||
protected $filesystem; | ||
|
||
public function setFilesystem(Filesystem $filesystem) | ||
{ | ||
$this->filesystem = $filesystem; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/KernelAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
trait KernelAwareTrait | ||
{ | ||
protected $kernel; | ||
|
||
public function setKernel(KernelInterface $kernel) | ||
{ | ||
$this->kernel = $kernel; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/RunOpenCode/Bundle/Traitor/Traits/MailerAwareInterface.php
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,13 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
trait MailerAwareInterface | ||
{ | ||
protected $mailer; | ||
|
||
public function setMailer(\Swift_Mailer $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/RunOpenCode/Bundle/Traitor/Traits/PropertyAccessorAwareTrait.php
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,15 @@ | ||
<?php | ||
|
||
namespace RunOpenCode\Bundle\Traitor\Traits; | ||
|
||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
|
||
trait PropertyAccessorAwareTrait | ||
{ | ||
protected $propertyAccessor; | ||
|
||
public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor) | ||
{ | ||
$this->propertyAccessor = $propertyAccessor; | ||
} | ||
} |
Oops, something went wrong.