1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: egorov |
5
|
|
|
* Date: 12.02.2015 |
6
|
|
|
* Time: 12:23 |
7
|
|
|
*/ |
8
|
|
|
namespace samsonphp\compressor; |
9
|
|
|
|
10
|
|
|
use samsonphp\event\Event; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* SamsonPHP core compressor |
14
|
|
|
* @package samsonphp\compressor |
15
|
|
|
*/ |
16
|
|
|
class Core |
17
|
|
|
{ |
18
|
|
|
/** @var string Configuration environment */ |
19
|
|
|
protected $environment = 'prod'; |
20
|
|
|
|
21
|
|
|
/** @var Object Logger object */ |
22
|
|
|
protected $logger; |
23
|
|
|
|
24
|
|
|
/** @var \samson\core\Core Core pointer */ |
25
|
|
|
protected $core; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \samson\core\Core $core Core pointer |
29
|
|
|
* @param string $environment Configuration environment |
30
|
|
|
* @param object $logger Logger object |
31
|
|
|
*/ |
32
|
|
|
public function __construct($core, $environment = 'prod', $logger = null) |
33
|
|
|
{ |
34
|
|
|
$this->core = & $core; |
35
|
|
|
$this->environment = $environment; |
36
|
|
|
$this->logger = & $logger; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Method prepare core instance removing all unnecessary loaded modules |
41
|
|
|
* from it, and configuring it. |
42
|
|
|
* @return string Base64 encoded serialized core object instance |
43
|
|
|
*/ |
44
|
|
|
public function compress() |
45
|
|
|
{ |
46
|
|
|
$this->logger->log(' -- Compressing core'); |
47
|
|
|
|
48
|
|
|
// Switch to production environment |
49
|
|
|
$this->core->environment($this->environment); |
50
|
|
|
|
51
|
|
|
// Set rendering from string variables mode |
52
|
|
|
$this->core->render_mode = \samson\core\Core::RENDER_VARIABLE; |
|
|
|
|
53
|
|
|
|
54
|
|
|
// Unload all modules from core that does not implement interface iModuleCompressable |
55
|
|
|
foreach ($this->core->module_stack as $id => & $m) { |
|
|
|
|
56
|
|
|
// Unload modules that is not compressable |
57
|
|
|
if (!is_a($m, '\samsonframework\core\CompressInterface')) { |
58
|
|
|
$this->core->unload($id); |
59
|
|
|
$this->logger->log(' -- [##] -> Unloading module from core', $id); |
60
|
|
|
} else { // Reconfigure module |
61
|
|
|
Event::fire('core.module.configure', array(&$m, $id)); |
62
|
|
|
$this->logger->log(' -- [##] -> Loading config data', $id); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Change system path to relative type |
67
|
|
|
$this->core->path(''); |
68
|
|
|
|
69
|
|
|
// Create serialized object copy |
70
|
|
|
return base64_encode(serialize($this->core)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.