Pool::onConfigUpdated()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
nc 2
nop 0
1
<?php
2
namespace PHPDaemon\Servers\FlashPolicy;
3
4
use PHPDaemon\Core\Daemon;
5
use PHPDaemon\FS\FileSystem;
6
use PHPDaemon\Network\Server;
7
8
class Pool extends Server
9
{
10
11
    /**
12
     * @var string Cached policy file contents
13
     */
14
    public $policyData;
15
16
    /**
17
     * Setting default config options
18
     * Overriden from ConnectionPool::getConfigDefaults
19
     * @return array|bool
20
     */
21
    protected function getConfigDefaults()
22
    {
23
        return [
24
            /* [string|array] Listen addresses */
25
            'listen' => '0.0.0.0',
26
27
            /* [integer] Listen port */
28
            'port' => 843,
29
30
            /* [string] Path to crossdomain.xml file */
31
            'file' => getcwd() . '/conf/crossdomain.xml',
32
        ];
33
    }
34
35
    /**
36
     * Called when worker is ready
37
     * @return void
38
     */
39
    public function onReady()
40
    {
41
        $this->onConfigUpdated();
42
    }
43
44
    /**
45
     * Called when worker is going to update configuration
46
     * @return void
47
     */
48
    public function onConfigUpdated()
49
    {
50
        parent::onConfigUpdated();
51
        if (Daemon::$process instanceof \PHPDaemon\Thread\Worker) {
52
            $pool = $this;
53
            FileSystem::readfile($this->config->file->value, function ($file, $data) use ($pool) {
0 ignored issues
show
Bug introduced by
The property file does not seem to exist in PHPDaemon\Config\Section.

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...
54
                $pool->policyData = $data;
55
                $pool->enable();
56
            });
57
        }
58
    }
59
}
60