|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ffcms\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Ffcms\Core\Exception\NativeException; |
|
6
|
|
|
use Ffcms\Core\Helper\Type\Obj; |
|
7
|
|
|
use Ffcms\Core\Helper\Type\Str; |
|
8
|
|
|
use Ffcms\Core\Properties; |
|
9
|
|
|
use Ffcms\Console\Transfer\Input; |
|
10
|
|
|
use Ffcms\Console\Transfer\Output; |
|
11
|
|
|
use \Illuminate\Database\Capsule\Manager as Capsule; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Console. Console instance to use database, properties and other default features |
|
15
|
|
|
* @package Ffcms\Console |
|
16
|
|
|
*/ |
|
17
|
|
|
class Console |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var \Ffcms\Core\Properties */ |
|
20
|
|
|
public static $Properties; |
|
21
|
|
|
/** @var \Illuminate\Database\Capsule\Manager */ |
|
22
|
|
|
public static $Database; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Console constructor. Create new entry point instance |
|
26
|
|
|
* @param array|null $services |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(array $services = null) |
|
29
|
|
|
{ |
|
30
|
|
|
self::$Properties = new Properties(); |
|
31
|
|
|
|
|
32
|
|
|
// establish database link |
|
33
|
|
|
if (Obj::isArray(self::$Properties->get('database')) && (isset($services['Database']) && $services['Database'] === true || $services === null)) { |
|
34
|
|
|
self::$Database = new Capsule; |
|
35
|
|
|
self::$Database->addConnection(self::$Properties->get('database')); |
|
36
|
|
|
|
|
37
|
|
|
// Make this Capsule instance available globally via static methods... (optional) |
|
38
|
|
|
self::$Database->setAsGlobal(); |
|
39
|
|
|
|
|
40
|
|
|
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) |
|
41
|
|
|
self::$Database->bootEloquent(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Build console instance factory |
|
47
|
|
|
* @param array|null $services |
|
48
|
|
|
* @return Console |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function factory(array $services = null) |
|
51
|
|
|
{ |
|
52
|
|
|
return new self($services); |
|
53
|
|
|
} |
|
54
|
|
|
} |