diff --git a/tests/DoctrineTest/Coverage.php b/tests/DoctrineTest/Coverage.php
index a8aedae11..32351b7da 100644
--- a/tests/DoctrineTest/Coverage.php
+++ b/tests/DoctrineTest/Coverage.php
@@ -143,14 +143,15 @@ class DoctrineTest_Coverage
$it = new RecursiveDirectoryIterator(Doctrine::getPath());
$notCoveredArray = array();
foreach (new RecursiveIteratorIterator($it) as $file){
- if (strpos($file->getPathname(), ".svn")){
- continue;
- }
- if(strpos($file->getPathname(), "cli.php")){
+ if(strpos($file->getPathname(), "config.php")){
continue;
}
+ if (strpos($file->getPathname(), ".svn")){
+ continue;
+ }
+
$class = $this->getClassNameFromFileName($file->getPathname());
if (strpos($class, '_Interface')) {
@@ -177,6 +178,7 @@ class DoctrineTest_Coverage
$this->result["data"] = $coverageInfo;
file_put_contents($this->getCoverageDir() . "coverage.txt", serialize($this->result));
+ return true;
}
diff --git a/tests/DoctrineTest/Doctrine_TestCoverage.php b/tests/DoctrineTest/Doctrine_TestCoverage.php
deleted file mode 100644
index 30b21eebe..000000000
--- a/tests/DoctrineTest/Doctrine_TestCoverage.php
+++ /dev/null
@@ -1,238 +0,0 @@
-
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @category Object Relational Mapping
- * @link www.phpdoctrine.com
- * @since 1.0
- * @version $Revision: 1976 $
- */
-class Doctrine_TestCoverage
-{
-
- const COVERED = 1;
- const MAYBE = -2;
- const NOTCOVERED = -1;
-
- private $path;
- private $coverage;
- private $key;
- private $covered;
- private $totallines = 0;
- private $totalcovered = 0;
- private $totalmaybe = 0;
- private $totalnotcovered = 0;
-
- /*
- * Create a new coverage report
- *
- * @param string $file The name of the file where coverage data is stored
- *
- */
- public function __construct()
- $result = unserialize(file_get_contents(__FILE__ . "/coverage.txt"));
- $this->path = $result["path"];
- $this->coverage = $result["coverage"];
- $this->sortBy ="percentage"; // default sort
- }
-
- /*
- * Show graphical coverage report for a file
- *
- * @param string $fileName The name of the file to show
- */
- public function showFile($fileName)
- {
- $key = $this->path . $fileName;
- $html = '
1 |
-<?php
+ | <?php
|
2 |
-/*
+ | /*
|
3 |
- * $Id: Doctrine.php 2814 2007-10-11 04:24:01Z Jonathan.Wage $
+ | * $Id: Doctrine.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
|
4 |
- *
+ | *
|
5 |
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
- *
+ | *
|
17 |
- * This software consists of voluntary contributions made by many individuals
+ | * This software consists of voluntary contributions made by many individuals
|
18 |
- * and is licensed under the LGPL. For more information, see
+ | * and is licensed under the LGPL. For more information, see
|
19 |
- * <http://www.phpdoctrine.com>.
+ | * <http://www.phpdoctrine.com>.
|
20 |
- */
+ | */
|
21 |
-
+ |
|
22 |
-/**
+ | /**
|
23 |
- * Doctrine
+ | * Doctrine
|
24 |
- * the base class of Doctrine framework
+ | * the base class of Doctrine framework
|
25 |
- *
+ | *
|
26 |
- * @package Doctrine
+ | * @package Doctrine
|
27 |
- * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
+ | * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
28 |
- * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
+ | * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
29 |
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
30 |
- * @link www.phpdoctrine.com
+ | * @link www.phpdoctrine.com
|
31 |
- * @since 1.0
+ | * @since 1.0
|
32 |
- * @version $Revision: 2814 $
+ | * @version $Revision: 2963 $
|
33 |
- */
+ | */
|
34 |
-final class Doctrine
+ | final class Doctrine
|
35 |
-{
+ | {
|
36 |
- /**
+ | /**
|
37 |
- * ERROR CONSTANTS
+ | * ERROR CONSTANTS
|
38 |
- */
+ | */
|
39 |
- const ERR = -1;
+ | const ERR = -1;
|
40 |
- const ERR_SYNTAX = -2;
+ | const ERR_SYNTAX = -2;
|
41 |
- const ERR_CONSTRAINT = -3;
+ | const ERR_CONSTRAINT = -3;
|
42 |
- const ERR_NOT_FOUND = -4;
+ | const ERR_NOT_FOUND = -4;
|
43 |
- const ERR_ALREADY_EXISTS = -5;
+ | const ERR_ALREADY_EXISTS = -5;
|
44 |
- const ERR_UNSUPPORTED = -6;
+ | const ERR_UNSUPPORTED = -6;
|
45 |
- const ERR_MISMATCH = -7;
+ | const ERR_MISMATCH = -7;
|
46 |
- const ERR_INVALID = -8;
+ | const ERR_INVALID = -8;
|
47 |
- const ERR_NOT_CAPABLE = -9;
+ | const ERR_NOT_CAPABLE = -9;
|
48 |
- const ERR_TRUNCATED = -10;
+ | const ERR_TRUNCATED = -10;
|
49 |
- const ERR_INVALID_NUMBER = -11;
+ | const ERR_INVALID_NUMBER = -11;
|
50 |
- const ERR_INVALID_DATE = -12;
+ | const ERR_INVALID_DATE = -12;
|
51 |
- const ERR_DIVZERO = -13;
+ | const ERR_DIVZERO = -13;
|
52 |
- const ERR_NODBSELECTED = -14;
+ | const ERR_NODBSELECTED = -14;
|
53 |
- const ERR_CANNOT_CREATE = -15;
+ | const ERR_CANNOT_CREATE = -15;
|
54 |
- const ERR_CANNOT_DELETE = -16;
+ | const ERR_CANNOT_DELETE = -16;
|
55 |
- const ERR_CANNOT_DROP = -17;
+ | const ERR_CANNOT_DROP = -17;
|
56 |
- const ERR_NOSUCHTABLE = -18;
+ | const ERR_NOSUCHTABLE = -18;
|
57 |
- const ERR_NOSUCHFIELD = -19;
+ | const ERR_NOSUCHFIELD = -19;
|
58 |
- const ERR_NEED_MORE_DATA = -20;
+ | const ERR_NEED_MORE_DATA = -20;
|
59 |
- const ERR_NOT_LOCKED = -21;
+ | const ERR_NOT_LOCKED = -21;
|
60 |
- const ERR_VALUE_COUNT_ON_ROW = -22;
+ | const ERR_VALUE_COUNT_ON_ROW = -22;
|
61 |
- const ERR_INVALID_DSN = -23;
+ | const ERR_INVALID_DSN = -23;
|
62 |
- const ERR_CONNECT_FAILED = -24;
+ | const ERR_CONNECT_FAILED = -24;
|
63 |
- const ERR_EXTENSION_NOT_FOUND = -25;
+ | const ERR_EXTENSION_NOT_FOUND = -25;
|
64 |
- const ERR_NOSUCHDB = -26;
+ | const ERR_NOSUCHDB = -26;
|
65 |
- const ERR_ACCESS_VIOLATION = -27;
+ | const ERR_ACCESS_VIOLATION = -27;
|
66 |
- const ERR_CANNOT_REPLACE = -28;
+ | const ERR_CANNOT_REPLACE = -28;
|
67 |
- const ERR_CONSTRAINT_NOT_NULL = -29;
+ | const ERR_CONSTRAINT_NOT_NULL = -29;
|
68 |
- const ERR_DEADLOCK = -30;
+ | const ERR_DEADLOCK = -30;
|
69 |
- const ERR_CANNOT_ALTER = -31;
+ | const ERR_CANNOT_ALTER = -31;
|
70 |
- const ERR_MANAGER = -32;
+ | const ERR_MANAGER = -32;
|
71 |
- const ERR_MANAGER_PARSE = -33;
+ | const ERR_MANAGER_PARSE = -33;
|
72 |
- const ERR_LOADMODULE = -34;
+ | const ERR_LOADMODULE = -34;
|
73 |
- const ERR_INSUFFICIENT_DATA = -35;
+ | const ERR_INSUFFICIENT_DATA = -35;
|
74 |
- const ERR_CLASS_NAME = -36;
+ | const ERR_CLASS_NAME = -36;
|
75 |
-
+ |
|
76 |
- /**
+ | /**
|
77 |
- * PDO derived constants
+ | * PDO derived constants
|
78 |
- */
+ | */
|
79 |
- const CASE_LOWER = 2;
+ | const CASE_LOWER = 2;
|
80 |
- const CASE_NATURAL = 0;
+ | const CASE_NATURAL = 0;
|
81 |
- const CASE_UPPER = 1;
+ | const CASE_UPPER = 1;
|
82 |
- const CURSOR_FWDONLY = 0;
+ | const CURSOR_FWDONLY = 0;
|
83 |
- const CURSOR_SCROLL = 1;
+ | const CURSOR_SCROLL = 1;
|
84 |
- const ERRMODE_EXCEPTION = 2;
+ | const ERRMODE_EXCEPTION = 2;
|
85 |
- const ERRMODE_SILENT = 0;
+ | const ERRMODE_SILENT = 0;
|
86 |
- const ERRMODE_WARNING = 1;
+ | const ERRMODE_WARNING = 1;
|
87 |
- const FETCH_ASSOC = 2;
+ | const FETCH_ASSOC = 2;
|
88 |
- const FETCH_BOTH = 4;
+ | const FETCH_BOTH = 4;
|
89 |
- const FETCH_BOUND = 6;
+ | const FETCH_BOUND = 6;
|
90 |
- const FETCH_CLASS = 8;
+ | const FETCH_CLASS = 8;
|
91 |
- const FETCH_CLASSTYPE = 262144;
+ | const FETCH_CLASSTYPE = 262144;
|
92 |
- const FETCH_COLUMN = 7;
+ | const FETCH_COLUMN = 7;
|
93 |
- const FETCH_FUNC = 10;
+ | const FETCH_FUNC = 10;
|
94 |
- const FETCH_GROUP = 65536;
+ | const FETCH_GROUP = 65536;
|
95 |
- const FETCH_INTO = 9;
+ | const FETCH_INTO = 9;
|
96 |
- const FETCH_LAZY = 1;
+ | const FETCH_LAZY = 1;
|
97 |
- const FETCH_NAMED = 11;
+ | const FETCH_NAMED = 11;
|
98 |
- const FETCH_NUM = 3;
+ | const FETCH_NUM = 3;
|
99 |
- const FETCH_OBJ = 5;
+ | const FETCH_OBJ = 5;
|
100 |
- const FETCH_ORI_ABS = 4;
+ | const FETCH_ORI_ABS = 4;
|
101 |
- const FETCH_ORI_FIRST = 2;
+ | const FETCH_ORI_FIRST = 2;
|
102 |
- const FETCH_ORI_LAST = 3;
+ | const FETCH_ORI_LAST = 3;
|
103 |
- const FETCH_ORI_NEXT = 0;
+ | const FETCH_ORI_NEXT = 0;
|
104 |
- const FETCH_ORI_PRIOR = 1;
+ | const FETCH_ORI_PRIOR = 1;
|
105 |
- const FETCH_ORI_REL = 5;
+ | const FETCH_ORI_REL = 5;
|
106 |
- const FETCH_SERIALIZE = 524288;
+ | const FETCH_SERIALIZE = 524288;
|
107 |
- const FETCH_UNIQUE = 196608;
+ | const FETCH_UNIQUE = 196608;
|
108 |
- const NULL_EMPTY_STRING = 1;
+ | const NULL_EMPTY_STRING = 1;
|
109 |
- const NULL_NATURAL = 0;
+ | const NULL_NATURAL = 0;
|
110 |
- const NULL_TO_STRING = NULL;
+ | const NULL_TO_STRING = NULL;
|
111 |
- const PARAM_BOOL = 5;
+ | const PARAM_BOOL = 5;
|
112 |
- const PARAM_INPUT_OUTPUT = -2147483648;
+ | const PARAM_INPUT_OUTPUT = -2147483648;
|
113 |
- const PARAM_INT = 1;
+ | const PARAM_INT = 1;
|
114 |
- const PARAM_LOB = 3;
+ | const PARAM_LOB = 3;
|
115 |
- const PARAM_NULL = 0;
+ | const PARAM_NULL = 0;
|
116 |
- const PARAM_STMT = 4;
+ | const PARAM_STMT = 4;
|
117 |
- const PARAM_STR = 2;
+ | const PARAM_STR = 2;
|
118 |
- /**
+ |
|
119 |
- * ATTRIBUTE CONSTANTS
+ | /**
|
120 |
- */
+ | * ATTRIBUTE CONSTANTS
|
121 |
-
+ | */
|
122 |
- /**
+ |
|
123 |
- * PDO derived attributes
+ | /**
|
124 |
- */
+ | * PDO derived attributes
|
125 |
- const ATTR_AUTOCOMMIT = 0;
+ | */
|
126 |
- const ATTR_PREFETCH = 1;
+ | const ATTR_AUTOCOMMIT = 0;
|
127 |
- const ATTR_TIMEOUT = 2;
+ | const ATTR_PREFETCH = 1;
|
128 |
- const ATTR_ERRMODE = 3;
+ | const ATTR_TIMEOUT = 2;
|
129 |
- const ATTR_SERVER_VERSION = 4;
+ | const ATTR_ERRMODE = 3;
|
130 |
- const ATTR_CLIENT_VERSION = 5;
+ | const ATTR_SERVER_VERSION = 4;
|
131 |
- const ATTR_SERVER_INFO = 6;
+ | const ATTR_CLIENT_VERSION = 5;
|
132 |
- const ATTR_CONNECTION_STATUS = 7;
+ | const ATTR_SERVER_INFO = 6;
|
133 |
- const ATTR_CASE = 8;
+ | const ATTR_CONNECTION_STATUS = 7;
|
134 |
- const ATTR_CURSOR_NAME = 9;
+ | const ATTR_CASE = 8;
|
135 |
- const ATTR_CURSOR = 10;
+ | const ATTR_CURSOR_NAME = 9;
|
136 |
- const ATTR_ORACLE_NULLS = 11;
+ | const ATTR_CURSOR = 10;
|
137 |
- const ATTR_PERSISTENT = 12;
+ | const ATTR_ORACLE_NULLS = 11;
|
138 |
- const ATTR_STATEMENT_CLASS = 13;
+ | const ATTR_PERSISTENT = 12;
|
139 |
- const ATTR_FETCH_TABLE_NAMES = 14;
+ | const ATTR_STATEMENT_CLASS = 13;
|
140 |
- const ATTR_FETCH_CATALOG_NAMES = 15;
+ | const ATTR_FETCH_TABLE_NAMES = 14;
|
141 |
- const ATTR_DRIVER_NAME = 16;
+ | const ATTR_FETCH_CATALOG_NAMES = 15;
|
142 |
- const ATTR_STRINGIFY_FETCHES = 17;
+ | const ATTR_DRIVER_NAME = 16;
|
143 |
- const ATTR_MAX_COLUMN_LEN = 18;
+ | const ATTR_STRINGIFY_FETCHES = 17;
|
144 |
-
+ | const ATTR_MAX_COLUMN_LEN = 18;
|
145 |
- /**
+ |
|
146 |
- * Doctrine constants
+ | /**
|
147 |
- */
+ | * Doctrine constants
|
148 |
- const ATTR_LISTENER = 100;
+ | */
|
149 |
- const ATTR_QUOTE_IDENTIFIER = 101;
+ | const ATTR_LISTENER = 100;
|
150 |
- const ATTR_FIELD_CASE = 102;
+ | const ATTR_QUOTE_IDENTIFIER = 101;
|
151 |
- const ATTR_IDXNAME_FORMAT = 103;
+ | const ATTR_FIELD_CASE = 102;
|
152 |
- const ATTR_SEQNAME_FORMAT = 104;
+ | const ATTR_IDXNAME_FORMAT = 103;
|
153 |
- const ATTR_SEQCOL_NAME = 105;
+ | const ATTR_SEQNAME_FORMAT = 104;
|
154 |
- const ATTR_CMPNAME_FORMAT = 118;
+ | const ATTR_SEQCOL_NAME = 105;
|
155 |
- const ATTR_DBNAME_FORMAT = 117;
+ | const ATTR_CMPNAME_FORMAT = 118;
|
156 |
- const ATTR_TBLCLASS_FORMAT = 119;
+ | const ATTR_DBNAME_FORMAT = 117;
|
157 |
- const ATTR_EXPORT = 140;
+ | const ATTR_TBLCLASS_FORMAT = 119;
|
158 |
- const ATTR_DECIMAL_PLACES = 141;
+ | const ATTR_EXPORT = 140;
|
159 |
-
+ | const ATTR_DECIMAL_PLACES = 141;
|
160 |
- const ATTR_PORTABILITY = 106;
+ |
|
161 |
- const ATTR_VALIDATE = 107;
+ | const ATTR_PORTABILITY = 106;
|
162 |
- const ATTR_COLL_KEY = 108;
+ | const ATTR_VALIDATE = 107;
|
163 |
- const ATTR_QUERY_LIMIT = 109;
+ | const ATTR_COLL_KEY = 108;
|
164 |
- const ATTR_DEFAULT_TABLE_TYPE = 112;
+ | const ATTR_QUERY_LIMIT = 109;
|
165 |
- const ATTR_DEF_TEXT_LENGTH = 113;
+ | const ATTR_DEFAULT_TABLE_TYPE = 112;
|
166 |
- const ATTR_DEF_VARCHAR_LENGTH = 114;
+ | const ATTR_DEF_TEXT_LENGTH = 113;
|
167 |
- const ATTR_DEF_TABLESPACE = 115;
+ | const ATTR_DEF_VARCHAR_LENGTH = 114;
|
168 |
- const ATTR_EMULATE_DATABASE = 116;
+ | const ATTR_DEF_TABLESPACE = 115;
|
169 |
- const ATTR_USE_NATIVE_ENUM = 117;
+ | const ATTR_EMULATE_DATABASE = 116;
|
170 |
- const ATTR_DEFAULT_SEQUENCE = 133;
+ | const ATTR_USE_NATIVE_ENUM = 117;
|
171 |
-
+ | const ATTR_DEFAULT_SEQUENCE = 133;
|
172 |
- const ATTR_FETCHMODE = 118;
+ |
|
173 |
- const ATTR_NAME_PREFIX = 121;
+ | const ATTR_FETCHMODE = 118;
|
174 |
- const ATTR_CREATE_TABLES = 122;
+ | const ATTR_NAME_PREFIX = 121;
|
175 |
- const ATTR_COLL_LIMIT = 123;
+ | const ATTR_CREATE_TABLES = 122;
|
176 |
-
+ | const ATTR_COLL_LIMIT = 123;
|
177 |
- const ATTR_CACHE = 150;
+ |
|
178 |
- const ATTR_CACHE_LIFESPAN = 151;
+ | const ATTR_CACHE = 150;
|
179 |
- const ATTR_LOAD_REFERENCES = 153;
+ | const ATTR_CACHE_LIFESPAN = 151;
|
180 |
- const ATTR_RECORD_LISTENER = 154;
+ | const ATTR_LOAD_REFERENCES = 153;
|
181 |
- const ATTR_THROW_EXCEPTIONS = 155;
+ | const ATTR_RECORD_LISTENER = 154;
|
182 |
-
+ | const ATTR_THROW_EXCEPTIONS = 155;
|
183 |
-
+ |
|
184 |
- /**
+ | /**
|
185 |
- * LIMIT CONSTANTS
+ | * LIMIT CONSTANTS
|
186 |
- */
+ | */
|
187 |
-
+ |
|
188 |
- /**
+ | /**
|
189 |
- * constant for row limiting
+ | * constant for row limiting
|
190 |
- */
+ | */
|
191 |
- const LIMIT_ROWS = 1;
+ | const LIMIT_ROWS = 1;
|
192 |
- /**
+ |
|
193 |
- * constant for record limiting
+ | /**
|
194 |
- */
+ | * constant for record limiting
|
195 |
- const LIMIT_RECORDS = 2;
+ | */
|
196 |
-
+ | const LIMIT_RECORDS = 2;
|
197 |
- /**
+ |
|
198 |
- * FETCHMODE CONSTANTS
+ | /**
|
199 |
- */
+ | * FETCHMODE CONSTANTS
|
200 |
-
+ | */
|
201 |
- /**
+ |
|
202 |
- * IMMEDIATE FETCHING
+ | /**
|
203 |
- * mode for immediate fetching
+ | * IMMEDIATE FETCHING
|
204 |
- */
+ | * mode for immediate fetching
|
205 |
- const FETCH_IMMEDIATE = 0;
+ | */
|
206 |
- /**
+ | const FETCH_IMMEDIATE = 0;
|
207 |
- * BATCH FETCHING
+ |
|
208 |
- * mode for batch fetching
+ | /**
|
209 |
- */
+ | * BATCH FETCHING
|
210 |
- const FETCH_BATCH = 1;
+ | * mode for batch fetching
|
211 |
- /**
+ | */
|
212 |
- * LAZY FETCHING
+ | const FETCH_BATCH = 1;
|
213 |
- * mode for offset fetching
+ |
|
214 |
- */
+ | /**
|
215 |
- const FETCH_OFFSET = 3;
+ | * LAZY FETCHING
|
216 |
- /**
+ | * mode for offset fetching
|
217 |
- * LAZY OFFSET FETCHING
+ | */
|
218 |
- * mode for lazy offset fetching
+ | const FETCH_OFFSET = 3;
|
219 |
- */
+ |
|
220 |
- const FETCH_LAZY_OFFSET = 4;
+ | /**
|
221 |
-
+ | * LAZY OFFSET FETCHING
|
222 |
- /**
+ | * mode for lazy offset fetching
|
223 |
- * FETCH CONSTANTS
+ | */
|
224 |
- */
+ | const FETCH_LAZY_OFFSET = 4;
|
225 |
-
+ |
|
226 |
-
+ | /**
|
227 |
- /**
+ | * FETCH CONSTANTS
|
228 |
- * FETCH VALUEHOLDER
+ | */
|
229 |
- */
+ |
|
230 |
- const FETCH_VHOLDER = 1;
+ |
|
231 |
- /**
+ | /**
|
232 |
- * FETCH RECORD
+ | * FETCH VALUEHOLDER
|
233 |
- *
+ | */
|
234 |
- * Specifies that the fetch method shall return Doctrine_Record
+ | const FETCH_VHOLDER = 1;
|
235 |
- * objects as the elements of the result set.
+ |
|
236 |
- *
+ | /**
|
237 |
- * This is the default fetchmode.
+ | * FETCH RECORD
|
238 |
- */
+ | *
|
239 |
- const FETCH_RECORD = 2;
+ | * Specifies that the fetch method shall return Doctrine_Record
|
240 |
- /**
+ | * objects as the elements of the result set.
|
241 |
- * FETCH ARRAY
+ | *
|
242 |
- */
+ | * This is the default fetchmode.
|
243 |
-
+ | */
|
244 |
- const FETCH_ARRAY = 3;
+ | const FETCH_RECORD = 2;
|
245 |
- /**
+ |
|
246 |
- * PORTABILITY CONSTANTS
+ | /**
|
247 |
- */
+ | * FETCH ARRAY
|
248 |
-
+ | */
|
249 |
- /**
+ | const FETCH_ARRAY = 3;
|
250 |
- * Portability: turn off all portability features.
+ |
|
251 |
- * @see Doctrine::ATTR_PORTABILITY
+ | /**
|
252 |
- */
+ | * PORTABILITY CONSTANTS
|
253 |
- const PORTABILITY_NONE = 0;
+ | */
|
254 |
- /**
+ |
|
255 |
- * Portability: convert names of tables and fields to case defined in the
+ | /**
|
256 |
- * "field_case" option when using the query*(), fetch*() methods.
+ | * Portability: turn off all portability features.
|
257 |
- * @see Doctrine::ATTR_PORTABILITY
+ | * @see self::ATTR_PORTABILITY
|
258 |
- */
+ | */
|
259 |
- const PORTABILITY_FIX_CASE = 1;
+ | const PORTABILITY_NONE = 0;
|
260 |
-
+ |
|
261 |
- /**
+ | /**
|
262 |
- * Portability: right trim the data output by query*() and fetch*().
+ | * Portability: convert names of tables and fields to case defined in the
|
263 |
- * @see Doctrine::ATTR_PORTABILITY
+ | * "field_case" option when using the query*(), fetch*() methods.
|
264 |
- */
+ | * @see self::ATTR_PORTABILITY
|
265 |
- const PORTABILITY_RTRIM = 2;
+ | */
|
266 |
- /**
+ | const PORTABILITY_FIX_CASE = 1;
|
267 |
- * Portability: force reporting the number of rows deleted.
+ |
|
268 |
- * @see Doctrine::ATTR_PORTABILITY
+ | /**
|
269 |
- */
+ | * Portability: right trim the data output by query*() and fetch*().
|
270 |
- const PORTABILITY_DELETE_COUNT = 4;
+ | * @see self::ATTR_PORTABILITY
|
271 |
- /**
+ | */
|
272 |
- * Portability: convert empty values to null strings in data output by
+ | const PORTABILITY_RTRIM = 2;
|
273 |
- * query*() and fetch*().
+ |
|
274 |
- * @see Doctrine::ATTR_PORTABILITY
+ | /**
|
275 |
- */
+ | * Portability: force reporting the number of rows deleted.
|
276 |
- const PORTABILITY_EMPTY_TO_NULL = 8;
+ | * @see self::ATTR_PORTABILITY
|
277 |
- /**
+ | */
|
278 |
- * Portability: removes database/table qualifiers from associative indexes
+ | const PORTABILITY_DELETE_COUNT = 4;
|
279 |
- * @see Doctrine::ATTR_PORTABILITY
+ |
|
280 |
- */
+ | /**
|
281 |
- const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
+ | * Portability: convert empty values to null strings in data output by
|
282 |
- /**
+ | * query*() and fetch*().
|
283 |
- * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
+ | * @see self::ATTR_PORTABILITY
|
284 |
- * @see Doctrine::ATTR_PORTABILITY
+ | */
|
285 |
- */
+ | const PORTABILITY_EMPTY_TO_NULL = 8;
|
286 |
- const PORTABILITY_EXPR = 32;
+ |
|
287 |
- /**
+ | /**
|
288 |
- * Portability: turn on all portability features.
+ | * Portability: removes database/table qualifiers from associative indexes
|
289 |
- * @see Doctrine::ATTR_PORTABILITY
+ | * @see self::ATTR_PORTABILITY
|
290 |
- */
+ | */
|
291 |
- const PORTABILITY_ALL = 63;
+ | const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
|
292 |
-
+ |
|
293 |
- /**
+ | /**
|
294 |
- * LOCKMODE CONSTANTS
+ | * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
|
295 |
- */
+ | * @see self::ATTR_PORTABILITY
|
296 |
-
+ | */
|
297 |
- /**
+ | const PORTABILITY_EXPR = 32;
|
298 |
- * mode for optimistic locking
+ |
|
299 |
- */
+ | /**
|
300 |
- const LOCK_OPTIMISTIC = 0;
+ | * Portability: turn on all portability features.
|
301 |
- /**
+ | * @see self::ATTR_PORTABILITY
|
302 |
- * mode for pessimistic locking
+ | */
|
303 |
- */
+ | const PORTABILITY_ALL = 63;
|
304 |
- const LOCK_PESSIMISTIC = 1;
+ |
|
305 |
- /**
+ | /**
|
306 |
- * EXPORT CONSTANTS
+ | * LOCKMODE CONSTANTS
|
307 |
- */
+ | */
|
308 |
-
+ |
|
309 |
- /**
+ | /**
|
310 |
- * turns of exporting
+ | * mode for optimistic locking
|
311 |
- */
+ | */
|
312 |
- const EXPORT_NONE = 0;
+ | const LOCK_OPTIMISTIC = 0;
|
313 |
- /**
+ |
|
314 |
- * export tables
+ | /**
|
315 |
- */
+ | * mode for pessimistic locking
|
316 |
- const EXPORT_TABLES = 1;
+ | */
|
317 |
- /**
+ | const LOCK_PESSIMISTIC = 1;
|
318 |
- * export constraints
+ |
|
319 |
- */
+ | /**
|
320 |
- const EXPORT_CONSTRAINTS = 2;
+ | * EXPORT CONSTANTS
|
321 |
- /**
+ | */
|
322 |
- * export plugins
+ |
|
323 |
- */
+ | /**
|
324 |
- const EXPORT_PLUGINS = 4;
+ | * EXPORT_NONE
|
325 |
- /**
+ | */
|
326 |
- * export all
+ | const EXPORT_NONE = 0;
|
327 |
- */
+ |
|
328 |
- const EXPORT_ALL = 7;
+ | /**
|
329 |
-
+ | * EXPORT_TABLES
|
330 |
- /**
+ | */
|
331 |
- * HYDRATION CONSTANTS
+ | const EXPORT_TABLES = 1;
|
332 |
- */
+ |
|
333 |
- const HYDRATE_RECORD = 2;
+ | /**
|
334 |
-
+ | * EXPORT_CONSTRAINTS
|
335 |
- const HYDRATE_ARRAY = 3;
+ | */
|
336 |
-
+ | const EXPORT_CONSTRAINTS = 2;
|
337 |
- /**
+ |
|
338 |
- * VALIDATION CONSTANTS
+ | /**
|
339 |
- */
+ | * EXPORT_PLUGINS
|
340 |
- const VALIDATE_NONE = 0;
+ | */
|
341 |
-
+ | const EXPORT_PLUGINS = 4;
|
342 |
- const VALIDATE_LENGTHS = 1;
+ |
|
343 |
-
+ | /**
|
344 |
- const VALIDATE_TYPES = 2;
+ | * EXPORT_ALL
|
345 |
-
+ | */
|
346 |
- const VALIDATE_CONSTRAINTS = 4;
+ | const EXPORT_ALL = 7;
|
347 |
-
+ |
|
348 |
- const VALIDATE_ALL = 5;
+ | /**
|
349 |
-
+ | * HYDRATION CONSTANTS
|
350 |
- /**
+ | */
|
351 |
- * constant for auto_increment identifier
+ | const HYDRATE_RECORD = 2;
|
352 |
- */
+ |
|
353 |
- const IDENTIFIER_AUTOINC = 1;
+ | /**
|
354 |
- /**
+ | * HYDRATE_ARRAY
|
355 |
- * constant for sequence identifier
+ | */
|
356 |
- */
+ | const HYDRATE_ARRAY = 3;
|
357 |
- const IDENTIFIER_SEQUENCE = 2;
+ |
|
358 |
- /**
+ | /**
|
359 |
- * constant for normal identifier
+ | * VALIDATION CONSTANTS
|
360 |
- */
+ | */
|
361 |
- const IDENTIFIER_NATURAL = 3;
+ | const VALIDATE_NONE = 0;
|
362 |
- /**
+ |
|
363 |
- * constant for composite identifier
+ | /**
|
364 |
- */
+ | * VALIDATE_LENGTHS
|
365 |
- const IDENTIFIER_COMPOSITE = 4;
+ | */
|
366 |
- /**
+ | const VALIDATE_LENGTHS = 1;
|
367 |
- * constructor
+ |
|
368 |
- */
+ | /**
|
369 |
- public function __construct()
+ | * VALIDATE_TYPES
|
370 |
- {
+ | */
|
371 |
- throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
+ | const VALIDATE_TYPES = 2;
|
372 |
- }
+ |
|
373 |
- /**
+ | /**
|
374 |
- * @var string $path doctrine root directory
+ | * VALIDATE_CONSTRAINTS
|
375 |
- */
+ | */
|
376 |
- private static $_path;
+ | const VALIDATE_CONSTRAINTS = 4;
|
377 |
- /**
+ |
|
378 |
- * @var boolean $_debug
+ | /**
|
379 |
- */
+ | * VALIDATE_ALL
|
380 |
- private static $_debug = false;
+ | */
|
381 |
-
+ | const VALIDATE_ALL = 7;
|
382 |
- public static function debug($bool = null)
+ |
|
383 |
- {
+ | /**
|
384 |
- if ($bool !== null) {
+ | * IDENTIFIER_AUTOINC
|
385 |
- self::$_debug = (bool) $bool;
+ | *
|
386 |
- }
+ | * constant for auto_increment identifier
|
387 |
- return self::$_debug;
+ | */
|
388 |
- }
+ | const IDENTIFIER_AUTOINC = 1;
|
389 |
- /**
+ |
|
390 |
- * getPath
+ | /**
|
391 |
- * returns the doctrine root
+ | * IDENTIFIER_SEQUENCE
|
392 |
- *
+ | *
|
393 |
- * @return string
+ | * constant for sequence identifier
|
394 |
- */
+ | */
|
395 |
- public static function getPath()
+ | const IDENTIFIER_SEQUENCE = 2;
|
396 |
- {
+ |
|
397 |
- if ( ! self::$_path) {
+ | /**
|
398 |
- self::$_path = dirname(__FILE__);
+ | * IDENTIFIER_NATURAL
|
399 |
- }
+ | *
|
400 |
- return self::$_path;
+ | * constant for normal identifier
|
401 |
- }
+ | */
|
402 |
- /**
+ | const IDENTIFIER_NATURAL = 3;
|
403 |
- * loadAll
+ |
|
404 |
- * loads all runtime classes
+ | /**
|
405 |
- *
+ | * IDENTIFIER_COMPOSITE
|
406 |
- * @return void
+ | *
|
407 |
- */
+ | * constant for composite identifier
|
408 |
- public static function loadAll()
+ | */
|
409 |
- {
+ | const IDENTIFIER_COMPOSITE = 4;
|
410 |
- $classes = Doctrine_Compiler::getRuntimeClasses();
+ |
|
411 |
-
+ | /**
|
412 |
- foreach ($classes as $class) {
+ | * Path
|
413 |
- Doctrine::autoload($class);
+ | *
|
414 |
- }
+ | * @var string $path doctrine root directory
|
415 |
- }
+ | */
|
416 |
- /**
+ | private static $_path;
|
417 |
- * loadModels
+ |
|
418 |
- *
+ | /**
|
419 |
- * Recursively load all models from a directory or array of directories
+ | * Debug
|
420 |
- *
+ | *
|
421 |
- * @param string $directory Path to directory of models or array of directory paths
+ | * Bool true/false
|
422 |
- * @return void
+ | *
|
423 |
- */
+ | * @var boolean $_debug
|
424 |
- public static function loadModels($directory)
+ | */
|
425 |
- {
+ | private static $_debug = false;
|
426 |
- $declared = get_declared_classes();
+ |
|
427 |
-
+ | /**
|
428 |
- if ($directory !== null) {
+ | * __construct
|
429 |
- foreach ((array) $directory as $dir) {
+ | *
|
430 |
- $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
+ | * @return void
|
431 |
- RecursiveIteratorIterator::LEAVES_ONLY);
+ | * @throws Doctrine_Exception
|
432 |
-
+ | */
|
433 |
- foreach ($it as $file) {
+ | public function __construct()
|
434 |
- $e = explode('.', $file->getFileName());
+ | {
|
435 |
- if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
+ | throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
|
436 |
- require_once $file->getPathName();
+ | }
|
437 |
- }
+ |
|
438 |
- }
+ | /**
|
439 |
- }
+ | * debug
|
440 |
-
+ | *
|
441 |
- $declared = array_diff(get_declared_classes(), $declared);
+ | * @param string $bool
|
442 |
- }
+ | * @return void
|
443 |
-
+ | */
|
444 |
- return self::getLoadedModels($declared);
+ | public static function debug($bool = null)
|
445 |
- }
+ | {
|
446 |
- /**
+ | if ($bool !== null) {
|
447 |
- * getLoadedModels
+ | self::$_debug = (bool) $bool;
|
448 |
- *
+ | }
|
449 |
- * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
+ |
|
450 |
- *
+ | return self::$_debug;
|
451 |
- * @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
+ | }
|
452 |
- * @return void
+ |
|
453 |
- */
+ | /**
|
454 |
- public static function getLoadedModels($classes = null)
+ | * getPath
|
455 |
- {
+ | * returns the doctrine root
|
456 |
- if ($classes === null) {
+ | *
|
457 |
- $classes = get_declared_classes();
+ | * @return string
|
458 |
- }
+ | */
|
459 |
-
+ | public static function getPath()
|
460 |
- $parent = new ReflectionClass('Doctrine_Record');
+ | {
|
461 |
-
+ | if ( ! self::$_path) {
|
462 |
- $loadedModels = array();
+ | self::$_path = dirname(__FILE__);
|
463 |
-
+ | }
|
464 |
- // we iterate trhough the diff of previously declared classes
+ |
|
465 |
- // and currently declared classes
+ | return self::$_path;
|
466 |
- foreach ($classes as $name) {
+ | }
|
467 |
- $class = new ReflectionClass($name);
+ |
|
468 |
-
+ | /**
|
469 |
- // Skip the following classes
+ | * loadAll
|
470 |
- // - abstract classes
+ | * loads all runtime classes
|
471 |
- // - not a subclass of Doctrine_Record
+ | *
|
472 |
- // - don't have a setTableDefinition method
+ | * @return void
|
473 |
- if ($class->isAbstract() ||
+ | */
|
474 |
- !$class->isSubClassOf($parent) ||
+ | public static function loadAll()
|
475 |
- !$class->hasMethod('setTableDefinition')) {
+ | {
|
476 |
- continue;
+ | return self::loadAllRuntimeClasses();
|
477 |
- }
+ | }
|
478 |
-
+ |
|
479 |
- $loadedModels[] = $name;
+ | /**
|
480 |
- }
+ | * importSchema
|
481 |
-
+ | * method for importing existing schema to Doctrine_Record classes
|
482 |
- return $loadedModels;
+ | *
|
483 |
- }
+ | * @param string $directory Directory to write your models to
|
484 |
- /**
+ | * @param array $databases Array of databases to generate models for
|
485 |
- * getConnectionByTableName
+ | * @return boolean
|
486 |
- *
+ | */
|
487 |
- * Get the connection object for a table by the actual table name
+ | public static function importSchema($directory, array $databases = array())
|
488 |
- *
+ | {
|
489 |
- * @param string $tableName
+ | return self::generateModelsFromDb($directory, $databases);
|
490 |
- * @return void
+ | }
|
491 |
- */
+ |
|
492 |
- public static function getConnectionByTableName($tableName)
+ | /**
|
493 |
- {
+ | * exportSchema
|
494 |
- $loadedModels = self::getLoadedModels();
+ | * method for exporting Doctrine_Record classes to a schema
|
495 |
-
+ | *
|
496 |
- foreach ($loadedModels as $name) {
+ | * @param string $directory Directory containing your models
|
497 |
- $model = new $name();
+ | * @return void
|
498 |
- $table = $model->getTable();
+ | */
|
499 |
-
+ | public static function exportSchema($directory = null)
|
500 |
- if ($table->getTableName() == $tableName) {
+ | {
|
501 |
- return $table->getConnection();
+ | return self::createTablesFromModels($directory);
|
502 |
- }
+ | }
|
503 |
- }
+ |
|
504 |
- }
+ | /**
|
505 |
- /**
+ | * exportSql
|
506 |
- * importSchema
+ | * method for exporting Doctrine_Record classes to a schema
|
507 |
- * method for importing existing schema to Doctrine_Record classes
+ | *
|
508 |
- *
+ | * @param string $directory
|
509 |
- * @param string $directory Directory to write your models to
+ | */
|
510 |
- * @param array $databases Array of databases to generate models for
+ | public static function exportSql($directory = null)
|
511 |
- * @return boolean
+ | {
|
512 |
- */
+ | return self::generateSqlFromModels($directory);
|
513 |
- public static function importSchema($directory, array $databases = array())
+ | }
|
514 |
- {
+ |
|
515 |
- return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
+ | /**
|
516 |
- }
+ | * loadAllRuntimeClasses
|
517 |
- /**
+ | *
|
518 |
- * generateModelsFromDb
+ | * loads all runtime classes
|
519 |
- *
+ | *
|
520 |
- * Generate your model definitions from an existing database
+ | * @return void
|
521 |
- *
+ | */
|
522 |
- * @param string $directory Directory to write your models to
+ | public static function loadAllRuntimeClasses()
|
523 |
- * @param string $databases Array of databases to generate models for
+ | {
|
524 |
- * @return void
+ | $classes = Doctrine_Compiler::getRuntimeClasses();
|
525 |
- */
+ |
|
526 |
- public static function generateModelsFromDb($directory, array $databases = array())
+ | foreach ($classes as $class) {
|
527 |
- {
+ | self::autoload($class);
|
528 |
- return self::importSchema($directory, $databases);
+ | }
|
529 |
- }
+ | }
|
530 |
- /**
+ |
|
531 |
- * generateYamlFromDb
+ | /**
|
532 |
- *
+ | * loadModels
|
533 |
- * Generates models from database to temporary location then uses those models to generate a yaml schema file.
+ | *
|
534 |
- * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
+ | * Recursively load all models from a directory or array of directories
|
535 |
- *
+ | *
|
536 |
- * @param string $yamlPath Path to write oyur yaml schema file to
+ | * @param string $directory Path to directory of models or array of directory paths
|
537 |
- * @return void
+ | * @return array $loadedModels
|
538 |
- */
+ | */
|
539 |
- public static function generateYamlFromDb($yamlPath)
+ | public static function loadModels($directory)
|
540 |
- {
+ | {
|
541 |
- $directory = '/tmp/tmp_doctrine_models';
+ | $declared = get_declared_classes();
|
542 |
-
+ |
|
543 |
- Doctrine::generateModelsFromDb($directory);
+ | if ($directory !== null) {
|
544 |
-
+ | foreach ((array) $directory as $dir) {
|
545 |
- $export = new Doctrine_Export_Schema();
+ | $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
546 |
-
+ | RecursiveIteratorIterator::LEAVES_ONLY);
|
547 |
- return $export->exportSchema($yamlPath, 'yml', $directory);
+ |
|
548 |
- }
+ | foreach ($it as $file) {
|
549 |
- /**
+ | $e = explode('.', $file->getFileName());
|
550 |
- * generateModelsFromYaml
+ | if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
551 |
- *
+ | require_once $file->getPathName();
|
552 |
- * Generate a yaml schema file from an existing directory of models
+ | }
|
553 |
- *
+ | }
|
554 |
- * @param string $yamlPath Path to your yaml schema files
+ | }
|
555 |
- * @param string $directory Directory to generate your models in
+ |
|
556 |
- * @return void
+ | $declared = array_diff(get_declared_classes(), $declared);
|
557 |
- */
+ | }
|
558 |
- public static function generateModelsFromYaml($yamlPath, $directory)
+ |
|
559 |
- {
+ | return self::getLoadedModels($declared);
|
560 |
- $import = new Doctrine_Import_Schema();
+ | }
|
561 |
-
+ |
|
562 |
- return $import->importSchema($yamlPath, 'yml', $directory);
+ | /**
|
563 |
- }
+ | * getLoadedModels
|
564 |
- /**
+ | *
|
565 |
- * exportSchema
+ | * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
|
566 |
- * method for exporting Doctrine_Record classes to a schema
+ | *
|
567 |
- *
+ | * Will filter through an array of classes and return the Doctrine_Records out of them.
|
568 |
- * @param string $directory Directory containing your models
+ | * If you do not specify $classes it will return all of the currently loaded Doctrine_Records
|
569 |
- * @return void
+ | *
|
570 |
- */
+ | * @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
|
571 |
- public static function exportSchema($directory = null)
+ | * @return array $loadedModels
|
572 |
- {
+ | */
|
573 |
- return Doctrine_Manager::connection()->export->exportSchema($directory);
+ | public static function getLoadedModels($classes = null)
|
574 |
- }
+ | {
|
575 |
- /**
+ | if ($classes === null) {
|
576 |
- * createTablesFromModels
+ | $classes = get_declared_classes();
|
577 |
- *
+ | }
|
578 |
- * Creates database tables for the models in the specified directory
+ |
|
579 |
- *
+ | $parent = new ReflectionClass('Doctrine_Record');
|
580 |
- * @param string $directory Directory containing your models
+ |
|
581 |
- * @return void
+ | $loadedModels = array();
|
582 |
- */
+ |
|
583 |
- public static function createTablesFromModels($directory = null)
+ | foreach ((array) $classes as $name) {
|
584 |
- {
+ | $class = new ReflectionClass($name);
|
585 |
- return self::exportSchema($directory);
+ |
|
586 |
- }
+ | // Skip the following classes
|
587 |
- /**
+ | // - abstract classes
|
588 |
- * generateYamlFromModels
+ | // - not a subclass of Doctrine_Record
|
589 |
- *
+ | // - don't have a setTableDefinition method
|
590 |
- * Generate yaml schema file for the models in the specified directory
+ | if ($class->isAbstract() ||
|
591 |
- *
+ | !$class->isSubClassOf($parent) ||
|
592 |
- * @param string $yamlPath Path to your yaml schema files
+ | !$class->hasMethod('setTableDefinition')) {
|
593 |
- * @param string $directory Directory to generate your models in
+ | continue;
|
594 |
- * @return void
+ | }
|
595 |
- */
+ |
|
596 |
- public static function generateYamlFromModels($yamlPath, $directory)
+ | $loadedModels[] = $name;
|
597 |
- {
+ | }
|
598 |
- $export = new Doctrine_Export_Schema();
+ |
|
599 |
-
+ | return $loadedModels;
|
600 |
- return $export->exportSchema($yamlPath, 'yml', $directory);
+ | }
|
601 |
- }
+ |
|
602 |
- /**
+ | /**
|
603 |
- * createDatabases
+ | * getConnectionByTableName
|
604 |
- *
+ | *
|
605 |
- * Creates databases for connections
+ | * Get the connection object for a table by the actual table name
|
606 |
- *
+ | *
|
607 |
- * @param string $specifiedConnections Array of connections you wish to create the database for
+ | * @param string $tableName
|
608 |
- * @return void
+ | * @return object Doctrine_Connection
|
609 |
- */
+ | */
|
610 |
- public static function createDatabases($specifiedConnections)
+ | public static function getConnectionByTableName($tableName)
|
611 |
- {
+ | {
|
612 |
- if ( ! is_array($specifiedConnections)) {
+ | $loadedModels = self::getLoadedModels();
|
613 |
- $specifiedConnections = (array) $specifiedConnections;
+ |
|
614 |
- }
+ | foreach ($loadedModels as $name) {
|
615 |
-
+ | $model = new $name();
|
616 |
- $connections = Doctrine_Manager::getInstance()->getConnections();
+ | $table = $model->getTable();
|
617 |
-
+ |
|
618 |
- foreach ($connections as $name => $connection) {
+ | if ($table->getTableName() == $tableName) {
|
619 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
+ | return $table->getConnection();
|
620 |
- continue;
+ | }
|
621 |
- }
+ | }
|
622 |
-
+ |
|
623 |
- $connection->export->createDatabase($name);
+ | return Doctrine_Manager::connection();
|
624 |
- }
+ | }
|
625 |
- }
+ |
|
626 |
- /**
+ | /**
|
627 |
- * dropDatabases
+ | * generateModelsFromDb
|
628 |
- *
+ | *
|
629 |
- * Drops databases for connections
+ | * method for importing existing schema to Doctrine_Record classes
|
630 |
- *
+ | *
|
631 |
- * @param string $specifiedConnections Array of connections you wish to drop the database for
+ | * @param string $directory Directory to write your models to
|
632 |
- * @return void
+ | * @param array $databases Array of databases to generate models for
|
633 |
- */
+ | * @return boolean
|
634 |
- public static function dropDatabases($specifiedConnections = array())
+ | * @throws Exception
|
635 |
- {
+ | */
|
636 |
- if ( ! is_array($specifiedConnections)) {
+ | public static function generateModelsFromDb($directory, array $databases = array())
|
637 |
- $specifiedConnections = (array) $specifiedConnections;
+ | {
|
638 |
- }
+ | return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
|
639 |
-
+ | }
|
640 |
- $connections = Doctrine_Manager::getInstance()->getConnections();
+ |
|
641 |
-
+ | /**
|
642 |
- foreach ($connections as $name => $connection) {
+ | * generateYamlFromDb
|
643 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
+ | *
|
644 |
- continue;
+ | * Generates models from database to temporary location then uses those models to generate a yaml schema file.
|
645 |
- }
+ | * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
|
646 |
-
+ | *
|
647 |
- $connection->export->dropDatabase($name);
+ | * @param string $yamlPath Path to write oyur yaml schema file to
|
648 |
- }
+ | * @return void
|
649 |
- }
+ | */
|
650 |
- /**
+ | public static function generateYamlFromDb($yamlPath)
|
651 |
- * dumpData
+ | {
|
652 |
- *
+ | $directory = '/tmp/tmp_doctrine_models';
|
653 |
- * Dump data to a yaml fixtures file
+ |
|
654 |
- *
+ | Doctrine::generateModelsFromDb($directory);
|
655 |
- * @param string $yamlPath Path to write the yaml data fixtures to
+ |
|
656 |
- * @param string $individualFiles Whether or not to dump data to individual fixtures files
+ | $export = new Doctrine_Export_Schema();
|
657 |
- * @return void
+ |
|
658 |
- */
+ | $result = $export->exportSchema($yamlPath, 'yml', $directory);
|
659 |
- public static function dumpData($yamlPath, $individualFiles = false)
+ |
|
660 |
- {
+ | exec('rm -rf ' . $directory);
|
661 |
- $data = new Doctrine_Data();
+ |
|
662 |
-
+ | return $result;
|
663 |
- return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
+ | }
|
664 |
- }
+ |
|
665 |
- /**
+ | /**
|
666 |
- * loadData
+ | * generateModelsFromYaml
|
667 |
- *
+ | *
|
668 |
- * Load data from a yaml fixtures file.
+ | * Generate a yaml schema file from an existing directory of models
|
669 |
- * The output of dumpData can be fed to loadData
+ | *
|
670 |
- *
+ | * @param string $yamlPath Path to your yaml schema files
|
671 |
- * @param string $yamlPath Path to your yaml data fixtures
+ | * @param string $directory Directory to generate your models in
|
672 |
- * @param string $append Whether or not to append the data
+ | * @return void
|
673 |
- * @return void
+ | */
|
674 |
- */
+ | public static function generateModelsFromYaml($yamlPath, $directory)
|
675 |
- public static function loadData($yamlPath, $append = false)
+ | {
|
676 |
- {
+ | $import = new Doctrine_Import_Schema();
|
677 |
- $delete = isset($append) ? ($append ? false : true) : true;
+ | $import->generateBaseClasses(true);
|
678 |
-
+ |
|
679 |
- if ($delete)
+ | return $import->importSchema($yamlPath, 'yml', $directory);
|
680 |
- {
+ | }
|
681 |
- $models = Doctrine::getLoadedModels();
+ |
|
682 |
-
+ | /**
|
683 |
- foreach ($models as $model)
+ | * createTablesFromModels
|
684 |
- {
+ | *
|
685 |
- $model = new $model();
+ | * Creates database tables for the models in the specified directory
|
686 |
-
+ | *
|
687 |
- $model->getTable()->createQuery()->delete($model)->execute();
+ | * @param string $directory Directory containing your models
|
688 |
- }
+ | * @return void
|
689 |
- }
+ | */
|
690 |
-
+ | public static function createTablesFromModels($directory = null)
|
691 |
- $data = new Doctrine_Data();
+ | {
|
692 |
-
+ | return Doctrine_Manager::connection()->export->exportSchema($directory);
|
693 |
- return $data->importData($yamlPath, 'yml');
+ | }
|
694 |
- }
+ |
|
695 |
- /**
+ | /**
|
696 |
- * loadDummyData
+ | * generateSqlFromModels
|
697 |
- *
+ | *
|
698 |
- * Populdate your models with dummy data
+ | * @param string $directory
|
699 |
- *
+ | * @return string $build String of sql queries. One query per line
|
700 |
- * @param string $append Whether or not to append the data
+ | */
|
701 |
- * @param string $num Number of records to populate
+ | public static function generateSqlFromModels($directory = null)
|
702 |
- * @return void
+ | {
|
703 |
- */
+ | $sql = Doctrine_Manager::connection()->export->exportSql($directory);
|
704 |
- public static function loadDummyData($append, $num = 5)
+ |
|
705 |
- {
+ | $build = '';
|
706 |
- $delete = isset($append) ? ($append ? false : true) : true;
+ | foreach ($sql as $query) {
|
707 |
-
+ | $build .= $query.";\n";
|
708 |
- if ($delete)
+ | }
|
709 |
- {
+ |
|
710 |
- $models = Doctrine::getLoadedModels();
+ | return $build;
|
711 |
-
+ | }
|
712 |
- foreach ($models as $model)
+ |
|
713 |
- {
+ | /**
|
714 |
- $model = new $model();
+ | * generateYamlFromModels
|
715 |
-
+ | *
|
716 |
- $model->getTable()->createQuery()->delete($model)->execute();
+ | * Generate yaml schema file for the models in the specified directory
|
717 |
- }
+ | *
|
718 |
- }
+ | * @param string $yamlPath Path to your yaml schema files
|
719 |
-
+ | * @param string $directory Directory to generate your models in
|
720 |
- $data = new Doctrine_Data();
+ | * @return void
|
721 |
-
+ | */
|
722 |
- return $data->importDummyData($num);
+ | public static function generateYamlFromModels($yamlPath, $directory)
|
723 |
- }
+ | {
|
724 |
- /**
+ | $export = new Doctrine_Export_Schema();
|
725 |
- * migrate
+ |
|
726 |
- *
+ | return $export->exportSchema($yamlPath, 'yml', $directory);
|
727 |
- * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
+ | }
|
728 |
- *
+ |
|
729 |
- * @param string $directory Directory which contains your migration classes
+ | /**
|
730 |
- * @param string $to Version you wish to migrate to.
+ | * createDatabases
|
731 |
- * @return void
+ | *
|
732 |
- */
+ | * Creates databases for connections
|
733 |
- public static function migrate($directory, $to = null)
+ | *
|
734 |
- {
+ | * @param string $specifiedConnections Array of connections you wish to create the database for
|
735 |
- $migration = new Doctrine_Migration($directory);
+ | * @return void
|
736 |
-
+ | */
|
737 |
- return $migration->migrate($to);
+ | public static function createDatabases($specifiedConnections = array())
|
738 |
- }
+ | {
|
739 |
- /**
+ | if ( ! is_array($specifiedConnections)) {
|
740 |
- * generateMigrationClass
+ | $specifiedConnections = (array) $specifiedConnections;
|
741 |
- *
+ | }
|
742 |
- * Generate new migration class skeleton
+ |
|
743 |
- *
+ | $manager = Doctrine_Manager::getInstance();
|
744 |
- * @param string $className Name of the Migration class to generate
+ | $connections = $manager->getConnections();
|
745 |
- * @param string $directory Directory which contains your migration classes
+ |
|
746 |
- * @package default
+ | foreach ($connections as $name => $connection) {
|
747 |
- */
+ | if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
|
748 |
- public static function generateMigrationClass($className, $directory)
+ | continue;
|
749 |
- {
+ | }
|
750 |
- $migration = new Doctrine_Migration($directory);
+ |
|
751 |
- $next = (string) $migration->getNextVersion();
+ | $info = $manager->parsePdoDsn($connection->getOption('dsn'));
|
752 |
-
+ | $username = $connection->getOption('username');
|
753 |
- $fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . Doctrine::tableize($className) . '.class.php';
+ | $password = $connection->getOption('password');
|
754 |
- $path = $directory . DIRECTORY_SEPARATOR . $fileName;
+ |
|
755 |
-
+ | // Make connection without database specified so we can create it
|
756 |
- $code = '<?php' . PHP_EOL;
+ | $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false);
|
757 |
- $code .= "// Automatically generated by Doctrine\n";
+ |
|
758 |
- $code .= "class " . $className . " extends Doctrine_Migration\n";
+ | try {
|
759 |
- $code .= "{\n";
+ | // Create database
|
760 |
- $code .= "\tpublic function up()\n\t{ }\n\n";
+ | $connect->export->createDatabase($name);
|
761 |
- $code .= "\tpublic function down()\n\t{ }\n";
+ |
|
762 |
- $code .= "}";
+ | // Close the tmp connection with no database
|
763 |
-
+ | $manager->closeConnection($connect);
|
764 |
- file_put_contents($path, $code);
+ |
|
765 |
- }
+ | // Close original connection
|
766 |
- /**
+ | $manager->closeConnection($connection);
|
767 |
- * exportSql
+ |
|
768 |
- * method for exporting Doctrine_Record classes to a schema
+ | // Reopen original connection with newly created database
|
769 |
- *
+ | $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true);
|
770 |
- * @param string $directory
+ | } catch (Exception $e) {
|
771 |
- */
+ |
|
772 |
- public static function exportSql($directory = null)
+ | }
|
773 |
- {
+ | }
|
774 |
- return Doctrine_Manager::connection()->export->exportSql($directory);
+ | }
|
775 |
- }
+ |
|
776 |
- /**
+ | /**
|
777 |
- * generateSqlFromModels
+ | * dropDatabases
|
778 |
- *
+ | *
|
779 |
- * Generate sql for directory of models
+ | * Drops databases for connections
|
780 |
- *
+ | *
|
781 |
- * @param string $directory Directory where your models exist
+ | * @param string $specifiedConnections Array of connections you wish to drop the database for
|
782 |
- * @return void
+ | * @return void
|
783 |
- */
+ | */
|
784 |
- public static function generateSqlFromModels($directory)
+ | public static function dropDatabases($specifiedConnections = array())
|
785 |
- {
+ | {
|
786 |
- return self::exportSql($directory);
+ | if ( ! is_array($specifiedConnections)) {
|
787 |
- }
+ | $specifiedConnections = (array) $specifiedConnections;
|
788 |
- /**
+ | }
|
789 |
- * compile
+ |
|
790 |
- * method for making a single file of most used doctrine runtime components
+ | $manager = Doctrine_Manager::getInstance();
|
791 |
- * including the compiled file instead of multiple files (in worst
+ |
|
792 |
- * cases dozens of files) can improve performance by an order of magnitude
+ | $connections = $manager->getConnections();
|
793 |
- *
+ |
|
794 |
- * @param string $target
+ | foreach ($connections as $name => $connection) {
|
795 |
- *
+ | if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
|
796 |
- * @throws Doctrine_Exception
+ | continue;
|
797 |
- * @return void
+ | }
|
798 |
- */
+ |
|
799 |
- public static function compile($target = null)
+ | try {
|
800 |
- {
+ | $connection->export->dropDatabase($name);
|
801 |
- Doctrine_Compiler::compile($target);
+ | } catch (Exception $e) {
|
802 |
- }
+ |
|
803 |
- /**
+ | }
|
804 |
- * simple autoload function
+ | }
|
805 |
- * returns true if the class was loaded, otherwise false
+ | }
|
806 |
- *
+ |
|
807 |
- * @param string $classname
+ | /**
|
808 |
- * @return boolean
+ | * dumpData
|
809 |
- */
+ | *
|
810 |
- public static function autoload($classname)
+ | * Dump data to a yaml fixtures file
|
811 |
- {
+ | *
|
812 |
- if (class_exists($classname, false)) {
+ | * @param string $yamlPath Path to write the yaml data fixtures to
|
813 |
- return false;
+ | * @param string $individualFiles Whether or not to dump data to individual fixtures files
|
814 |
- }
+ | * @return void
|
815 |
- if ( ! self::$_path) {
+ | */
|
816 |
- self::$_path = dirname(__FILE__);
+ | public static function dumpData($yamlPath, $individualFiles = false)
|
817 |
- }
+ | {
|
818 |
- $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
+ | $data = new Doctrine_Data();
|
819 |
-
+ |
|
820 |
- if ( ! file_exists($class)) {
+ | return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
|
821 |
- return false;
+ | }
|
822 |
- }
+ |
|
823 |
-
+ | /**
|
824 |
- require_once($class);
+ | * loadData
|
825 |
-
+ | *
|
826 |
- return true;
+ | * Load data from a yaml fixtures file.
|
827 |
- }
+ | * The output of dumpData can be fed to loadData
|
828 |
- /**
+ | *
|
829 |
- * dump
+ | * @param string $yamlPath Path to your yaml data fixtures
|
830 |
- *
+ | * @param string $append Whether or not to append the data
|
831 |
- * dumps a given variable
+ | * @return void
|
832 |
- *
+ | */
|
833 |
- * @param mixed $var a variable of any type
+ | public static function loadData($yamlPath, $append = false)
|
834 |
- * @param boolean $output whether to output the content
+ | {
|
835 |
- * @return void|string
+ | $data = new Doctrine_Data();
|
836 |
- */
+ |
|
837 |
- public static function dump($var, $output = true)
+ | if ( ! $append) {
|
838 |
- {
+ | $data->purge();
|
839 |
- $ret = array();
+ | }
|
840 |
- switch (gettype($var)) {
+ |
|
841 |
- case 'array':
+ | return $data->importData($yamlPath, 'yml');
|
842 |
- $ret[] = 'Array(';
+ | }
|
843 |
- foreach ($var as $k => $v) {
+ |
|
844 |
- $ret[] = $k . ' : ' . Doctrine::dump($v, false);
+ | /**
|
845 |
- }
+ | * loadDummyData
|
846 |
- $ret[] = ")";
+ | *
|
847 |
- break;
+ | * Populdate your models with dummy data
|
848 |
- case 'object':
+ | *
|
849 |
- $ret[] = 'Object(' . get_class($var) . ')';
+ | * @param string $append Whether or not to append the data
|
850 |
- break;
+ | * @param string $num Number of records to populate
|
851 |
- default:
+ | * @return void
|
852 |
- $ret[] = var_export($var, true);
+ | */
|
853 |
- }
+ | public static function loadDummyData($append, $num = 5)
|
854 |
- if ($output) {
+ | {
|
855 |
- print implode("\n", $ret);
+ | $data = new Doctrine_Data();
|
856 |
- }
+ |
|
857 |
- return implode("\n", $ret);
+ | if ( ! $append) {
|
858 |
- }
+ | $data->purge();
|
859 |
- /**
+ | }
|
860 |
- * returns table name from class name
+ |
|
861 |
- *
+ | return $data->importDummyData($num);
|
862 |
- * @param string $classname
+ | }
|
863 |
- * @return string
+ |
|
864 |
- */
+ | /**
|
865 |
- public static function tableize($classname)
+ | * migrate
|
866 |
- {
+ | *
|
867 |
- return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
+ | * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
|
868 |
- }
+ | *
|
869 |
- /**
+ | * @param string $migrationsPath Path to migrations directory which contains your migration classes
|
870 |
- * returns class name from table name
+ | * @param string $to Version you wish to migrate to.
|
871 |
- *
+ | * @return bool true
|
872 |
- * @param string $tablename
+ | * @throws new Doctrine_Migration_Exception
|
873 |
- * @return string
+ | */
|
874 |
- */
+ | public static function migrate($migrationsPath, $to = null)
|
875 |
- public static function classify($tablename)
+ | {
|
876 |
- {
+ | $migration = new Doctrine_Migration($migrationsPath);
|
877 |
- return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst($tablename));
+ |
|
878 |
- }
+ | return $migration->migrate($to);
|
879 |
-
+ | }
|
880 |
- /**
+ |
|
881 |
- * Callback function to classify a classname propperly.
+ | /**
|
882 |
- *
+ | * generateMigrationClass
|
883 |
- * @param array $matches An array of matches from a pcre_replace call
+ | *
|
884 |
- * @return string A string with matches 1 and mathces 3 in upper case.
+ | * Generate new migration class skeleton
|
885 |
- */
+ | *
|
886 |
- public static function classifyCallback($matches)
+ | * @param string $className Name of the Migration class to generate
|
887 |
- {
+ | * @param string $migrationsPath Path to directory which contains your migration classes
|
888 |
- return $matches[1] . strtoupper($matches[3]);
+ | */
|
889 |
- }
+ | public static function generateMigrationClass($className, $migrationsPath)
|
890 |
- /**
+ | {
|
891 |
- * checks for valid class name (uses camel case and underscores)
+ | $builder = new Doctrine_Migration_Builder($migrationsPath);
|
892 |
- *
+ |
|
893 |
- * @param string $classname
+ | return $builder->generateMigrationClass($className);
|
894 |
- * @return boolean
+ | }
|
895 |
- */
+ |
|
896 |
- public static function isValidClassname($classname)
+ | /**
|
897 |
- {
+ | * generateMigrationsFromDb
|
898 |
- if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
+ | *
|
899 |
- return false;
+ | * @param string $migrationsPath
|
900 |
- }
+ | * @return void
|
901 |
-
+ | * @throws new Doctrine_Migration_Exception
|
902 |
- return true;
+ | */
|
903 |
- }
+ | public static function generateMigrationsFromDb($migrationsPath)
|
904 |
-}
+ | {
|
+905 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+906 |
+
+ |
+907 |
+ return $builder->generateMigrationsFromDb();
+ |
+908 |
+ }
+ |
+909 |
+
+ |
+910 |
+ /**
+ |
+911 |
+ * generateMigrationsFromModels
+ |
+912 |
+ *
+ |
+913 |
+ * @param string $migrationsPath
+ |
+914 |
+ * @param string $modelsPath
+ |
+915 |
+ * @return void
+ |
+916 |
+ */
+ |
+917 |
+ public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null)
+ |
+918 |
+ {
+ |
+919 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+920 |
+
+ |
+921 |
+ return $builder->generateMigrationsFromModels($modelsPath);
+ |
+922 |
+ }
+ |
+923 |
+
+ |
+924 |
+ /**
+ |
+925 |
+ * getTable
+ |
+926 |
+ *
+ |
+927 |
+ * @param string $tableName
+ |
+928 |
+ * @return void
+ |
+929 |
+ */
+ |
+930 |
+ public static function getTable($tableName)
+ |
+931 |
+ {
+ |
+932 |
+ return Doctrine_Manager::table($tableName);
+ |
+933 |
+ }
+ |
+934 |
+
+ |
+935 |
+ /**
+ |
+936 |
+ * connection
+ |
+937 |
+ *
+ |
+938 |
+ * @param string $adapter
+ |
+939 |
+ * @param string $name
+ |
+940 |
+ * @return void
+ |
+941 |
+ */
+ |
+942 |
+ public static function connection($adapter, $name = null)
+ |
+943 |
+ {
+ |
+944 |
+ return Doctrine_Manager::connection($adapter, $name);
+ |
+945 |
+ }
+ |
+946 |
+
+ |
+947 |
+ /**
+ |
+948 |
+ * fileFinder
+ |
+949 |
+ *
+ |
+950 |
+ * @param string $type
+ |
+951 |
+ * @return void
+ |
+952 |
+ */
+ |
+953 |
+ public static function fileFinder($type)
+ |
+954 |
+ {
+ |
+955 |
+ return Doctrine_FileFinder::type($type);
+ |
+956 |
+ }
+ |
+957 |
+
+ |
+958 |
+ /**
+ |
+959 |
+ * compile
+ |
+960 |
+ * method for making a single file of most used doctrine runtime components
+ |
+961 |
+ * including the compiled file instead of multiple files (in worst
+ |
+962 |
+ * cases dozens of files) can improve performance by an order of magnitude
+ |
+963 |
+ *
+ |
+964 |
+ * @param string $target
+ |
+965 |
+ *
+ |
+966 |
+ * @throws Doctrine_Exception
+ |
+967 |
+ * @return void
+ |
+968 |
+ */
+ |
+969 |
+ public static function compile($target = null, $includedDrivers = array())
+ |
+970 |
+ {
+ |
+971 |
+ return Doctrine_Compiler::compile($target, $includedDrivers);
+ |
+972 |
+ }
+ |
+973 |
+
+ |
+974 |
+ /**
+ |
+975 |
+ * simple autoload function
+ |
+976 |
+ * returns true if the class was loaded, otherwise false
+ |
+977 |
+ *
+ |
+978 |
+ * @param string $classname
+ |
+979 |
+ * @return boolean
+ |
+980 |
+ */
+ |
+981 |
+ public static function autoload($classname)
+ |
+982 |
+ {
+ |
+983 |
+ if (class_exists($classname, false)) {
+ |
+984 |
+ return false;
+ |
+985 |
+ }
+ |
+986 |
+
+ |
+987 |
+ if ( ! self::$_path) {
+ |
+988 |
+ self::$_path = dirname(__FILE__);
+ |
+989 |
+ }
+ |
+990 |
+
+ |
+991 |
+ $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php';
+ |
+992 |
+
+ |
+993 |
+ if ( ! file_exists($class)) {
+ |
+994 |
+ return false;
+ |
+995 |
+ }
+ |
+996 |
+
+ |
+997 |
+ require_once($class);
+ |
+998 |
+
+ |
+999 |
+ return true;
+ |
+1000 |
+ }
+ |
+1001 |
+
+ |
+1002 |
+ /**
+ |
+1003 |
+ * dump
+ |
+1004 |
+ *
+ |
+1005 |
+ * dumps a given variable
+ |
+1006 |
+ *
+ |
+1007 |
+ * @param mixed $var a variable of any type
+ |
+1008 |
+ * @param boolean $output whether to output the content
+ |
+1009 |
+ * @return void|string
+ |
+1010 |
+ */
+ |
+1011 |
+ public static function dump($var, $output = true)
+ |
+1012 |
+ {
+ |
+1013 |
+ $ret = array();
+ |
+1014 |
+ switch (gettype($var)) {
+ |
+1015 |
+ case 'array':
+ |
+1016 |
+ $ret[] = 'Array(';
+ |
+1017 |
+ foreach ($var as $k => $v) {
+ |
+1018 |
+ $ret[] = $k . ' : ' . self::dump($v, false);
+ |
+1019 |
+ }
+ |
+1020 |
+ $ret[] = ")";
+ |
+1021 |
+ break;
+ |
+1022 |
+ case 'object':
+ |
+1023 |
+ $ret[] = 'Object(' . get_class($var) . ')';
+ |
+1024 |
+ break;
+ |
+1025 |
+ default:
+ |
+1026 |
+ $ret[] = var_export($var, true);
+ |
+1027 |
+ }
+ |
+1028 |
+ if ($output) {
+ |
+1029 |
+ print implode("\n", $ret);
+ |
+1030 |
+ }
+ |
+1031 |
+ return implode("\n", $ret);
+ |
+1032 |
+ }
+ |
+1033 |
+
+ |
+1034 |
+ /**
+ |
+1035 |
+ * returns table name from class name
+ |
+1036 |
+ *
+ |
+1037 |
+ * @param string $classname
+ |
+1038 |
+ * @return string
+ |
+1039 |
+ */
+ |
+1040 |
+ public static function tableize($classname)
+ |
+1041 |
+ {
+ |
+1042 |
+ return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
+ |
+1043 |
+ }
+ |
+1044 |
+
+ |
+1045 |
+ /**
+ |
+1046 |
+ * returns class name from table name
+ |
+1047 |
+ *
+ |
+1048 |
+ * @param string $tablename
+ |
+1049 |
+ * @return string
+ |
+1050 |
+ */
+ |
+1051 |
+ public static function classify($tablename)
+ |
+1052 |
+ {
+ |
+1053 |
+ return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst($tablename));
+ |
+1054 |
+ }
+ |
+1055 |
+
+ |
+1056 |
+ /**
+ |
+1057 |
+ * Callback function to classify a classname propperly.
+ |
+1058 |
+ *
+ |
+1059 |
+ * @param array $matches An array of matches from a pcre_replace call
+ |
+1060 |
+ * @return string A string with matches 1 and mathces 3 in upper case.
+ |
+1061 |
+ */
+ |
+1062 |
+ public static function classifyCallback($matches)
+ |
+1063 |
+ {
+ |
+1064 |
+ return $matches[1] . strtoupper($matches[3]);
+ |
+1065 |
+ }
+ |
+1066 |
+
+ |
+1067 |
+ /**
+ |
+1068 |
+ * checks for valid class name (uses camel case and underscores)
+ |
+1069 |
+ *
+ |
+1070 |
+ * @param string $classname
+ |
+1071 |
+ * @return boolean
+ |
+1072 |
+ */
+ |
+1073 |
+ public static function isValidClassname($classname)
+ |
+1074 |
+ {
+ |
+1075 |
+ if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
+ |
+1076 |
+ return false;
+ |
+1077 |
+ }
+ |
+1078 |
+
+ |
+1079 |
+ return true;
+ |
+1080 |
+ }
+ |
+1081 |
+} |