Core::compress()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 3
eloc 13
nc 3
nop 0
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;
0 ignored issues
show
Deprecated Code introduced by
The property samson\core\Core::$render_mode has been deprecated with message: @var string View path loading mode

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.

Loading history...
Deprecated Code introduced by
The constant samson\core\Core::RENDER_VARIABLE has been deprecated with message: View rendering algorithm from array of view variables

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
53
54
        // Unload all modules from core that does not implement interface iModuleCompressable
55
        foreach ($this->core->module_stack as $id => & $m) {
0 ignored issues
show
Bug introduced by
The property module_stack does not seem to exist in samson\core\Core.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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