|
1 <?php |
|
2 /* |
|
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14 * |
|
15 * This software consists of voluntary contributions made by many individuals |
|
16 * and is licensed under the LGPL. For more information, see |
|
17 * <http://www.doctrine-project.org>. |
|
18 */ |
|
19 |
|
20 namespace Doctrine\DBAL\Migrations\Configuration; |
|
21 |
|
22 use Doctrine\DBAL\Migrations\MigrationsException; |
|
23 |
|
24 /** |
|
25 * Abstract Migration Configuration class for loading configuration information |
|
26 * from a configuration file (xml or yml). |
|
27 * |
|
28 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|
29 * @link www.doctrine-project.org |
|
30 * @since 2.0 |
|
31 * @author Jonathan H. Wage <jonwage@gmail.com> |
|
32 */ |
|
33 abstract class AbstractFileConfiguration extends Configuration |
|
34 { |
|
35 /** |
|
36 * The configuration file used to load configuration information |
|
37 * |
|
38 * @var string |
|
39 */ |
|
40 private $file; |
|
41 |
|
42 /** |
|
43 * Whether or not the configuration file has been loaded yet or not |
|
44 * |
|
45 * @var bool |
|
46 */ |
|
47 private $loaded = false; |
|
48 |
|
49 /** |
|
50 * Load the information from the passed configuration file |
|
51 * |
|
52 * @param string $file The path to the configuration file |
|
53 * @return void |
|
54 * @throws MigrationException $exception Throws exception if configuration file was already loaded |
|
55 */ |
|
56 public function load($file) |
|
57 { |
|
58 if ($this->loaded) { |
|
59 throw MigrationsException::configurationFileAlreadyLoaded(); |
|
60 } |
|
61 if (file_exists($path = getcwd() . '/' . $file)) { |
|
62 $file = $path; |
|
63 } |
|
64 $this->file = $file; |
|
65 $this->doLoad($file); |
|
66 $this->loaded = true; |
|
67 } |
|
68 |
|
69 protected function getDirectoryRelativeToFile($file, $input) |
|
70 { |
|
71 $path = realpath(dirname($file) . '/' . $input); |
|
72 if ($path !== false) { |
|
73 $directory = $path; |
|
74 } else { |
|
75 $directory = $input; |
|
76 } |
|
77 return $directory; |
|
78 } |
|
79 |
|
80 public function getFile() |
|
81 { |
|
82 return $this->file; |
|
83 } |
|
84 |
|
85 /** |
|
86 * Abstract method that each file configuration driver must implement to |
|
87 * load the given configuration file whether it be xml, yaml, etc. or something |
|
88 * else. |
|
89 * |
|
90 * @param string $file The path to a configuration file. |
|
91 */ |
|
92 abstract protected function doLoad($file); |
|
93 } |