Skip to content

Commit 550079d

Browse files
committed
Merge pull request #32 from Padam87/3.0
3.0
2 parents e7836bd + 31319e9 commit 550079d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+941
-586
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/*
2-
.idea
3-
composer.lock
2+
build
3+
composer.lock
4+
Tests/App/app/cache

.php_cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
return Symfony\CS\Config\Config::create()
4+
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
5+
->fixers(
6+
[
7+
// Symfony level
8+
'psr0',
9+
'encoding',
10+
'short_tag',
11+
'braces',
12+
'elseif',
13+
'eof_ending',
14+
'function_declaration',
15+
'indentation',
16+
'line_after_namespace',
17+
'linefeed',
18+
'lowercase_constants',
19+
'lowercase_keywords',
20+
'multiple_use',
21+
'php_closing_tag',
22+
'trailing_spaces',
23+
'visibility',
24+
//'concat_without_spaces',
25+
'duplicate_semicolon',
26+
'extra_empty_lines',
27+
'include',
28+
'multiline_array_trailing_comma',
29+
'namespace_no_leading_whitespace',
30+
'new_with_braces',
31+
'object_operator',
32+
'operators_spaces',
33+
'phpdoc_params',
34+
'remove_lines_between_uses',
35+
'return',
36+
'single_array_no_trailing_comma',
37+
'spaces_before_semicolon',
38+
'spaces_cast',
39+
'standardize_not_equal',
40+
'ternary_spaces',
41+
'unused_use',
42+
'whitespacy_lines',
43+
// Custom
44+
'ordered_use',
45+
'short_array_syntax',
46+
'concat_with_spaces',
47+
]
48+
)
49+
;

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
65
- 5.5
6+
- 5.6
77

88
env:
9-
- SYMFONY_VERSION=2.3.*
10-
- SYMFONY_VERSION=2.4.*
11-
- SYMFONY_VERSION=dev-master
9+
- SYMFONY_VERSION=2.5.*
10+
- SYMFONY_VERSION=2.6.*
11+
- SYMFONY_VERSION=2.7.*
1212

1313
before_script:
1414
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
15-
- composer update --dev
15+
- composer update
1616

1717
script: phpunit
1818

@@ -21,4 +21,4 @@ after_script:
2121

2222
notifications:
2323
email:
24-
- prager.adam87@gmail.com
24+
- prager.adam87@gmail.com

Annotation/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
*/
88
class Entity
99
{
10-
}
10+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Padam87\AttributeBundle\CacheWarmer;
4+
5+
use Doctrine\Common\Annotations\AnnotationReader;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
8+
use Symfony\Component\Config\ConfigCache;
9+
use Symfony\Component\Config\Resource\FileResource;
10+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
11+
12+
class EntityAnnotationCacheWarmer implements CacheWarmerInterface
13+
{
14+
/**
15+
* @var ManagerRegistry
16+
*/
17+
private $doctrine;
18+
19+
/**
20+
* @var bool
21+
*/
22+
private $debug;
23+
24+
/**
25+
* @param ManagerRegistry $doctrine
26+
* @param $debug
27+
*/
28+
public function __construct(ManagerRegistry $doctrine, $debug)
29+
{
30+
$this->doctrine = $doctrine;
31+
$this->debug = $debug;
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function isOptional()
38+
{
39+
return false;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function warmUp($cacheDir)
46+
{
47+
$filename = $cacheDir . '/padam87/attribute_bundle/Entity.cache.php';
48+
49+
$cache = new ConfigCache($filename, $this->debug);
50+
51+
if (!$cache->isFresh()) {
52+
$content = '<?php return ' . var_export($this->getEntities(), true) . ';';
53+
$cache->write($content, $this->getResources());
54+
}
55+
}
56+
57+
protected function getEntities()
58+
{
59+
$entities = [];
60+
61+
$reader = new AnnotationReader();
62+
63+
/** @var ClassMetadata $metadata */
64+
foreach ($this->getMetadata() as $metadata) {
65+
$refl = $metadata->getReflectionClass();
66+
67+
if ($refl === null) {
68+
$refl = new \ReflectionClass($metadata->getName());
69+
}
70+
71+
if ($reader->getClassAnnotation($refl, 'Padam87\AttributeBundle\Annotation\Entity') != null) {
72+
$entities[$metadata->getName()] = true;
73+
}
74+
}
75+
76+
return $entities;
77+
}
78+
79+
/**
80+
* @return array
81+
*/
82+
protected function getResources()
83+
{
84+
$res = [];
85+
86+
/** @var ClassMetadata $m */
87+
foreach ($this->getMetadata() as $m) {
88+
$res[] = new FileResource($m->getReflectionClass()->getFileName());
89+
}
90+
91+
return $res;
92+
}
93+
94+
/**
95+
* @return array
96+
*/
97+
protected function getMetadata()
98+
{
99+
$em = $this->doctrine->getManager();
100+
101+
return $em->getMetadataFactory()->getAllMetadata();
102+
}
103+
}

Command/SyncSchemaCommand.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Padam87\AttributeBundle\Command;
4+
5+
use Doctrine\Common\Annotations\AnnotationReader;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
8+
use Padam87\AttributeBundle\Entity\Schema;
9+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10+
use Symfony\Component\Console\Helper\Table;
11+
use Symfony\Component\Console\Helper\TableSeparator;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class SyncSchemaCommand extends ContainerAwareCommand
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function configure()
21+
{
22+
$this
23+
->setName('eav:schema:sync')
24+
->setDescription('Syncs the existing schemas in the database with the current metadata')
25+
;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
protected function execute(InputInterface $input, OutputInterface $output)
32+
{
33+
$reader = new AnnotationReader();
34+
/** @var ManagerRegistry $doctrine */
35+
$doctrine = $this->getContainer()->get('doctrine');
36+
$em = $doctrine->getManager();
37+
$cmf = $em->getMetadataFactory();
38+
39+
$existing = [];
40+
$created = [];
41+
42+
/** @var ClassMetadata $metadata */
43+
foreach ($cmf->getAllMetadata() as $metadata) {
44+
$refl = $metadata->getReflectionClass();
45+
46+
if ($refl === null) {
47+
$refl = new \ReflectionClass($metadata->getName());
48+
}
49+
50+
if ($reader->getClassAnnotation($refl, 'Padam87\AttributeBundle\Annotation\Entity') != null) {
51+
$schema = $em->getRepository('Padam87AttributeBundle:Schema')->findOneBy([
52+
'className' => $metadata->getName(),
53+
]);
54+
55+
if ($schema === null) {
56+
$schema = new Schema();
57+
$schema->setClassName($metadata->getName());
58+
59+
$em->persist($schema);
60+
$em->flush($schema);
61+
62+
$created[] = $metadata->getName();
63+
} else {
64+
$existing[] = $metadata->getName();
65+
}
66+
}
67+
}
68+
69+
$table = new Table($output);
70+
71+
$table->addRow(['Created:', implode(PHP_EOL, $created)]);
72+
$table->addRow(new TableSeparator());
73+
$table->addRow(['Existing:', implode(PHP_EOL, $existing)]);
74+
75+
$table->render();
76+
}
77+
}

Controller/SchemaController.php

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Padam87\AttributeBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Extension\Extension;
8+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
9+
10+
class Padam87AttributeExtension extends Extension
11+
{
12+
public function load(array $config, ContainerBuilder $container)
13+
{
14+
$loader = new YamlFileLoader(
15+
$container,
16+
new FileLocator(__DIR__ . '/../Resources/config')
17+
);
18+
19+
$loader->load('services.yml');
20+
}
21+
}

0 commit comments

Comments
 (0)