Completed
Push — 2.x ( dc834d...91b37b )
by
unknown
02:07
created

OrmMetadata::getEntityMappingFiles()   A

Complexity

Conditions 2
Paths 6

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 9
nc 6
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\EasyExtendsBundle\Bundle;
13
14
use Symfony\Component\Finder\Finder;
15
16
class OrmMetadata
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $mappingEntityDirectory;
22
23
    /**
24
     * @var string
25
     */
26
    protected $extendedMappingEntityDirectory;
27
28
    /**
29
     * @var string
30
     */
31
    protected $entityDirectory;
32
33
    /**
34
     * @var string
35
     */
36
    protected $extendedEntityDirectory;
37
38
    /**
39
     * @var string
40
     */
41
    protected $extendedSerializerDirectory;
42
43
    /**
44
     * @param BundleMetadata $bundleMetadata
45
     */
46
    public function __construct(BundleMetadata $bundleMetadata)
47
    {
48
        $this->mappingEntityDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getBundle()->getPath());
49
        $this->extendedMappingEntityDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getExtendedDirectory());
50
        $this->entityDirectory = sprintf('%s/Entity', $bundleMetadata->getBundle()->getPath());
51
        $this->extendedEntityDirectory = sprintf('%s/Entity', $bundleMetadata->getExtendedDirectory());
52
        $this->extendedSerializerDirectory = sprintf('%s/Resources/config/serializer', $bundleMetadata->getExtendedDirectory());
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getMappingEntityDirectory()
59
    {
60
        return $this->mappingEntityDirectory;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getExtendedMappingEntityDirectory()
67
    {
68
        return $this->extendedMappingEntityDirectory;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getEntityDirectory()
75
    {
76
        return $this->entityDirectory;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getExtendedEntityDirectory()
83
    {
84
        return $this->extendedEntityDirectory;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getExtendedSerializerDirectory()
91
    {
92
        return $this->extendedSerializerDirectory;
93
    }
94
95
    /**
96
     * @return array|\Iterator
97
     */
98
    public function getEntityMappingFiles()
99
    {
100
        try {
101
            $f = new Finder();
102
            $f->name('*.orm.xml.skeleton');
103
            $f->name('*.orm.yml.skeleton');
104
            $f->in($this->getMappingEntityDirectory());
105
106
            return $f->getIterator();
107
        } catch (\Exception $e) {
108
            return array();
109
        }
110
    }
111
112
    /**
113
     * @return array
114
     */
115
    public function getEntityNames()
116
    {
117
        $names = array();
118
119
        try {
120
            $f = new Finder();
121
            $f->name('*.orm.xml.skeleton');
122
            $f->name('*.orm.yml.skeleton');
123
            $f->in($this->getMappingEntityDirectory());
124
125
            foreach ($f->getIterator() as $file) {
126
                $name = explode('.', basename($file));
127
                $names[] = $name[0];
128
            }
129
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
130
        }
131
132
        return $names;
133
    }
134
135
    /**
136
     * @return array|\Iterator
137
     */
138
    public function getRepositoryFiles()
139
    {
140
        try {
141
            $f = new Finder();
142
            $f->name('*Repository.php');
143
            $f->in($this->getEntityDirectory());
144
145
            return $f->getIterator();
146
        } catch (\Exception $e) {
147
            return array();
148
        }
149
    }
150
}
151