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

PhpcrMetadata::getDocumentMappingFiles()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
nc 5
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 PhpcrMetadata
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $mappingDocumentDirectory;
22
23
    /**
24
     * @var string
25
     */
26
    protected $extendedMappingDocumentDirectory;
27
28
    /**
29
     * @var string
30
     */
31
    protected $documentDirectory;
32
33
    /**
34
     * @var string
35
     */
36
    protected $extendedDocumentDirectory;
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->mappingDocumentDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getBundle()->getPath());
49
        $this->extendedMappingDocumentDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getExtendedDirectory());
50
        $this->documentDirectory = sprintf('%s/PHPCR', $bundleMetadata->getBundle()->getPath());
51
        $this->extendedDocumentDirectory = sprintf('%s/PHPCR', $bundleMetadata->getExtendedDirectory());
52
        $this->extendedSerializerDirectory = sprintf('%s/Resources/config/serializer', $bundleMetadata->getExtendedDirectory());
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getMappingDocumentDirectory()
59
    {
60
        return $this->mappingDocumentDirectory;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getExtendedMappingDocumentDirectory()
67
    {
68
        return $this->extendedMappingDocumentDirectory;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getDocumentDirectory()
75
    {
76
        return $this->documentDirectory;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getExtendedDocumentDirectory()
83
    {
84
        return $this->extendedDocumentDirectory;
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 getDocumentMappingFiles()
99
    {
100
        try {
101
            $f = new Finder();
102
            $f->name('*.phpcr.xml.skeleton');
103
            $f->in($this->getMappingDocumentDirectory());
104
105
            return $f->getIterator();
106
        } catch (\Exception $e) {
107
            return array();
108
        }
109
    }
110
111
    /**
112
     * @return array
113
     */
114
    public function getDocumentNames()
115
    {
116
        $names = array();
117
118
        try {
119
            $f = new Finder();
120
            $f->name('*.phpcr.xml.skeleton');
121
            $f->in($this->getMappingDocumentDirectory());
122
123
            foreach ($f->getIterator() as $file) {
124
                $name = explode('.', basename($file));
125
                $names[] = $name[0];
126
            }
127
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
128
        }
129
130
        return $names;
131
    }
132
133
    /**
134
     * @return array|\Iterator
135
     */
136
    public function getRepositoryFiles()
137
    {
138
        try {
139
            $f = new Finder();
140
            $f->name('*Repository.php');
141
            $f->in($this->getDocumentDirectory());
142
143
            return $f->getIterator();
144
        } catch (\Exception $e) {
145
            return array();
146
        }
147
    }
148
}
149