1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Batch that create entity |
5
|
|
|
* |
6
|
|
|
* @category src |
7
|
|
|
* @package src\Batch\Controller |
8
|
|
|
* @author Judicaël Paquet <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
10
|
|
|
* @license http://www.iscreenway.com/framework/licence.php Tout droit réservé à http://www.iscreenway.com |
11
|
|
|
* @version Release: 2.0.0 |
12
|
|
|
* @filesource https://github.com/las93/venus2 |
13
|
|
|
* @link https://github.com/las93 |
14
|
|
|
* @since 2.0.0 |
15
|
|
|
* |
16
|
|
|
* @tutorial You could launch this Batch in /private/ |
17
|
|
|
* php bin/console scaffolding -p [portal] |
18
|
|
|
* -p [portal] => it's the name where you want add your entities and models |
19
|
|
|
* -r [rewrite] => if we force rewrite file |
20
|
|
|
* by default, it's Batch |
21
|
|
|
*/ |
22
|
|
|
namespace Venus\src\Batch\Controller; |
23
|
|
|
|
24
|
|
|
use \Venus\core\Config as Config; |
|
|
|
|
25
|
|
|
use \Attila\Batch\Entity as BatchEntity; |
26
|
|
|
use \Attila\Batch\Operation as Operation; |
27
|
|
|
use \Venus\src\Batch\common\Controller as Controller; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Batch that create entity |
31
|
|
|
* |
32
|
|
|
* @category src |
33
|
|
|
* @package src\Batch\Controller |
34
|
|
|
* @author Judicaël Paquet <[email protected]> |
35
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
36
|
|
|
* @license http://www.iscreenway.com/framework/licence.php Tout droit réservé à http://www.iscreenway.com |
37
|
|
|
* @version Release: 2.0.0 |
38
|
|
|
* @filesource https://github.com/las93/venus2 |
39
|
|
|
* @link https://github.com/las93 |
40
|
|
|
* @since 2.0.0 |
41
|
|
|
*/ |
42
|
|
|
class Entity extends Controller |
43
|
|
|
{ |
44
|
|
|
/** |
45
|
|
|
* run the batch to create entity |
46
|
|
|
* @tutorial bin/console scaffolding |
47
|
|
|
* |
48
|
|
|
* @access public |
49
|
|
|
* @param array $aOptions options of script |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function runScaffolding(array $aOptions = array()) |
53
|
|
|
{ |
54
|
|
|
if (!isset($aOptions['p'])) { $aOptions['p'] = 'Batch'; } |
55
|
|
|
|
56
|
|
View Code Duplication |
if (!isset($aOptions['b'])) { $aOptions['b'] = json_encode(Config::get('Db', $aOptions['p'])); } |
|
|
|
|
57
|
|
|
|
58
|
|
|
$aOptions['g'] = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$aOptions['p'].DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Entity'.DIRECTORY_SEPARATOR; |
59
|
|
|
$aOptions['h'] = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$aOptions['p'].DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Model'.DIRECTORY_SEPARATOR; |
60
|
|
|
if (!defined('ENTITY_NAMESPACE')) { define('ENTITY_NAMESPACE', '\Venus\src\\'.$aOptions['p'].'\Entity'); } |
61
|
|
|
|
62
|
|
|
if (!defined('MODEL_NAMESPACE')) { define('MODEL_NAMESPACE', '\Venus\src\\'.$aOptions['p'].'\Model'); } |
63
|
|
|
|
64
|
|
|
$oBatch = new BatchEntity; |
65
|
|
|
$oBatch->runScaffolding($aOptions); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* run the batch to create entity |
70
|
|
|
* @tutorial bin/console scaffolding |
71
|
|
|
* |
72
|
|
|
* @access public |
73
|
|
|
* @param array $aOptions options of script |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function createDb(array $aOptions = array()) |
77
|
|
|
{ |
78
|
|
|
if (!isset($aOptions['p'])) { $aOptions['p'] = 'Batch'; } |
79
|
|
|
|
80
|
|
View Code Duplication |
if (!isset($aOptions['b'])) { $aOptions['b'] = json_encode(Config::get('Db', $aOptions['p'])); } |
|
|
|
|
81
|
|
|
|
82
|
|
|
$oBatch = new Operation; |
83
|
|
|
$oBatch->createDb($aOptions); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: