-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Padam87/3.0
3.0
- Loading branch information
Showing
41 changed files
with
941 additions
and
586 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor/* | ||
.idea | ||
composer.lock | ||
build | ||
composer.lock | ||
Tests/App/app/cache |
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,49 @@ | ||
<?php | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->level(Symfony\CS\FixerInterface::NONE_LEVEL) | ||
->fixers( | ||
[ | ||
// Symfony level | ||
'psr0', | ||
'encoding', | ||
'short_tag', | ||
'braces', | ||
'elseif', | ||
'eof_ending', | ||
'function_declaration', | ||
'indentation', | ||
'line_after_namespace', | ||
'linefeed', | ||
'lowercase_constants', | ||
'lowercase_keywords', | ||
'multiple_use', | ||
'php_closing_tag', | ||
'trailing_spaces', | ||
'visibility', | ||
//'concat_without_spaces', | ||
'duplicate_semicolon', | ||
'extra_empty_lines', | ||
'include', | ||
'multiline_array_trailing_comma', | ||
'namespace_no_leading_whitespace', | ||
'new_with_braces', | ||
'object_operator', | ||
'operators_spaces', | ||
'phpdoc_params', | ||
'remove_lines_between_uses', | ||
'return', | ||
'single_array_no_trailing_comma', | ||
'spaces_before_semicolon', | ||
'spaces_cast', | ||
'standardize_not_equal', | ||
'ternary_spaces', | ||
'unused_use', | ||
'whitespacy_lines', | ||
// Custom | ||
'ordered_use', | ||
'short_array_syntax', | ||
'concat_with_spaces', | ||
] | ||
) | ||
; |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
|
||
env: | ||
- SYMFONY_VERSION=2.3.* | ||
- SYMFONY_VERSION=2.4.* | ||
- SYMFONY_VERSION=dev-master | ||
- SYMFONY_VERSION=2.5.* | ||
- SYMFONY_VERSION=2.6.* | ||
- SYMFONY_VERSION=2.7.* | ||
|
||
before_script: | ||
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update | ||
- composer update --dev | ||
- composer update | ||
|
||
script: phpunit | ||
|
||
|
@@ -21,4 +21,4 @@ after_script: | |
|
||
notifications: | ||
email: | ||
- [email protected] | ||
- [email protected] |
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
*/ | ||
class Entity | ||
{ | ||
} | ||
} |
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,103 @@ | ||
<?php | ||
|
||
namespace Padam87\AttributeBundle\CacheWarmer; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Symfony\Component\Config\ConfigCache; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
|
||
class EntityAnnotationCacheWarmer implements CacheWarmerInterface | ||
{ | ||
/** | ||
* @var ManagerRegistry | ||
*/ | ||
private $doctrine; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $debug; | ||
|
||
/** | ||
* @param ManagerRegistry $doctrine | ||
* @param $debug | ||
*/ | ||
public function __construct(ManagerRegistry $doctrine, $debug) | ||
{ | ||
$this->doctrine = $doctrine; | ||
$this->debug = $debug; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isOptional() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function warmUp($cacheDir) | ||
{ | ||
$filename = $cacheDir . '/padam87/attribute_bundle/Entity.cache.php'; | ||
|
||
$cache = new ConfigCache($filename, $this->debug); | ||
|
||
if (!$cache->isFresh()) { | ||
$content = '<?php return ' . var_export($this->getEntities(), true) . ';'; | ||
$cache->write($content, $this->getResources()); | ||
} | ||
} | ||
|
||
protected function getEntities() | ||
{ | ||
$entities = []; | ||
|
||
$reader = new AnnotationReader(); | ||
|
||
/** @var ClassMetadata $metadata */ | ||
foreach ($this->getMetadata() as $metadata) { | ||
$refl = $metadata->getReflectionClass(); | ||
|
||
if ($refl === null) { | ||
$refl = new \ReflectionClass($metadata->getName()); | ||
} | ||
|
||
if ($reader->getClassAnnotation($refl, 'Padam87\AttributeBundle\Annotation\Entity') != null) { | ||
$entities[$metadata->getName()] = true; | ||
} | ||
} | ||
|
||
return $entities; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getResources() | ||
{ | ||
$res = []; | ||
|
||
/** @var ClassMetadata $m */ | ||
foreach ($this->getMetadata() as $m) { | ||
$res[] = new FileResource($m->getReflectionClass()->getFileName()); | ||
} | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getMetadata() | ||
{ | ||
$em = $this->doctrine->getManager(); | ||
|
||
return $em->getMetadataFactory()->getAllMetadata(); | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Padam87\AttributeBundle\Command; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Padam87\AttributeBundle\Entity\Schema; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Helper\TableSeparator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SyncSchemaCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('eav:schema:sync') | ||
->setDescription('Syncs the existing schemas in the database with the current metadata') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$reader = new AnnotationReader(); | ||
/** @var ManagerRegistry $doctrine */ | ||
$doctrine = $this->getContainer()->get('doctrine'); | ||
$em = $doctrine->getManager(); | ||
$cmf = $em->getMetadataFactory(); | ||
|
||
$existing = []; | ||
$created = []; | ||
|
||
/** @var ClassMetadata $metadata */ | ||
foreach ($cmf->getAllMetadata() as $metadata) { | ||
$refl = $metadata->getReflectionClass(); | ||
|
||
if ($refl === null) { | ||
$refl = new \ReflectionClass($metadata->getName()); | ||
} | ||
|
||
if ($reader->getClassAnnotation($refl, 'Padam87\AttributeBundle\Annotation\Entity') != null) { | ||
$schema = $em->getRepository('Padam87AttributeBundle:Schema')->findOneBy([ | ||
'className' => $metadata->getName(), | ||
]); | ||
|
||
if ($schema === null) { | ||
$schema = new Schema(); | ||
$schema->setClassName($metadata->getName()); | ||
|
||
$em->persist($schema); | ||
$em->flush($schema); | ||
|
||
$created[] = $metadata->getName(); | ||
} else { | ||
$existing[] = $metadata->getName(); | ||
} | ||
} | ||
} | ||
|
||
$table = new Table($output); | ||
|
||
$table->addRow(['Created:', implode(PHP_EOL, $created)]); | ||
$table->addRow(new TableSeparator()); | ||
$table->addRow(['Existing:', implode(PHP_EOL, $existing)]); | ||
|
||
$table->render(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 | ||
|
||
namespace Padam87\AttributeBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
class Padam87AttributeExtension extends Extension | ||
{ | ||
public function load(array $config, ContainerBuilder $container) | ||
{ | ||
$loader = new YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../Resources/config') | ||
); | ||
|
||
$loader->load('services.yml'); | ||
} | ||
} |
Oops, something went wrong.