Completed
Push — master ( f3f979...855d01 )
by Tim
10s
created

Simple::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 14
nc 1
nop 6
crap 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Simple
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli;
22
23
use Rhumsaa\Uuid\Uuid;
24
use Monolog\Logger;
25
use Psr\Log\LogLevel;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
use Symfony\Component\Console\Helper\FormatterHelper;
29
use TechDivision\Import\Utils\LoggerKeys;
30
use TechDivision\Import\Utils\RegistryKeys;
31
use TechDivision\Import\ApplicationInterface;
32
use TechDivision\Import\ConfigurationInterface;
33
use TechDivision\Import\Exceptions\LineNotFoundException;
34
use TechDivision\Import\Exceptions\FileNotFoundException;
35
use TechDivision\Import\Exceptions\ImportAlreadyRunningException;
36
use TechDivision\Import\Configuration\PluginConfigurationInterface;
37
use TechDivision\Import\Services\ImportProcessorInterface;
38
use TechDivision\Import\Services\RegistryProcessorInterface;
39
40
/**
41
 * The M2IF - Console Tool implementation.
42
 *
43
 * This is a example console tool implementation that should give developers an impression
44
 * on how the M2IF could be used to implement their own Magento 2 importer.
45
 *
46
 * @author    Tim Wagner <[email protected]>
47
 * @copyright 2016 TechDivision GmbH <[email protected]>
48
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
49
 * @link      https://github.com/techdivision/import-cli-simple
50
 * @link      http://www.techdivision.com
51
 */
52
class Simple implements ApplicationInterface
53
{
54
55
    /**
56
     * The default style to write messages to the symfony console.
57
     *
58
     * @var string
59
     */
60
    const DEFAULT_STYLE = 'info';
61
62
    /**
63
     * The TechDivision company name as ANSI art.
64
     *
65
     * @var string
66
     */
67
    protected $ansiArt = ' _______        _     _____  _       _     _
68
|__   __|      | |   |  __ \(_)     (_)   (_)
69
   | | ___  ___| |__ | |  | |___   ___ ___ _  ___  _ __
70
   | |/ _ \/ __| \'_ \| |  | | \ \ / / / __| |/ _ \| \'_ \
71
   | |  __/ (__| | | | |__| | |\ V /| \__ \ | (_) | | | |
72
   |_|\___|\___|_| |_|_____/|_| \_/ |_|___/_|\___/|_| |_|
73
';
74
75
    /**
76
     * The log level => console style mapping.
77
     *
78
     * @var array
79
     */
80
    protected $logLevelStyleMapping = array(
81
        LogLevel::INFO      => 'info',
82
        LogLevel::DEBUG     => 'comment',
83
        LogLevel::ERROR     => 'error',
84
        LogLevel::ALERT     => 'error',
85
        LogLevel::CRITICAL  => 'error',
86
        LogLevel::EMERGENCY => 'error',
87
        LogLevel::WARNING   => 'error',
88
        LogLevel::NOTICE    => 'info'
89
    );
90
91
    /**
92
     * The PID for the running processes.
93
     *
94
     * @var array
95
     */
96
    protected $pid;
97
98
    /**
99
     * The actions unique serial.
100
     *
101
     * @var string
102
     */
103
    protected $serial;
104
105
    /**
106
     * The array with the system logger instances.
107
     *
108
     * @var array
109
     */
110
    protected $systemLoggers;
111
112
    /**
113
     * The RegistryProcessor instance to handle running threads.
114
     *
115
     * @var \TechDivision\Import\Services\RegistryProcessorInterface
116
     */
117
    protected $registryProcessor;
118
119
    /**
120
     * The processor to read/write the necessary import data.
121
     *
122
     * @var \TechDivision\Import\Services\ImportProcessorInterface
123
     */
124
    protected $importProcessor;
125
126
    /**
127
     * The system configuration.
128
     *
129
     * @var \TechDivision\Import\ConfigurationInterface
130
     */
131
    protected $configuration;
132
133
    /**
134
     * The input stream to read console information from.
135
     *
136
     * @var \Symfony\Component\Console\Input\InputInterface
137
     */
138
    protected $input;
139
140
    /**
141
     * The output stream to write console information to.
142
     *
143
     * @var \Symfony\Component\Console\Output\OutputInterface
144
     */
145
    protected $output;
146
147
    /**
148
     * The plugins to be processed.
149
     *
150
     * @var array
151
     */
152
    protected $plugins = array();
153
154
    /**
155
     * The flag that stop's processing the operation.
156
     *
157
     * @var boolean
158
     */
159
    protected $stopped = false;
160
161
    /**
162
     * The filehandle for the PID file.
163
     *
164
     * @var resource
165
     */
166
    protected $fh;
167
168
    /**
169
     * The constructor to initialize the instance.
170
     *
171
     * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance
172
     * @param \TechDivision\Import\Services\ImportProcessorInterface   $importProcessor   The import processor instance
173
     * @param \TechDivision\Import\ConfigurationInterface              $configuration     The system configuration
174
     * @param \Symfony\Component\Console\Input\InputInterface          $input             An InputInterface instance
175
     * @param \Symfony\Component\Console\Output\OutputInterface        $output            An OutputInterface instance
176
     * @param array                                                    $systemLoggers     The array with the system logger instances
177
     */
178 1
    public function __construct(
179
        RegistryProcessorInterface $registryProcessor,
180
        ImportProcessorInterface $importProcessor,
181
        ConfigurationInterface $configuration,
182
        InputInterface $input,
183
        OutputInterface $output,
184
        array $systemLoggers
185
    ) {
186
187
        // register the shutdown function
188 1
        register_shutdown_function(array($this, 'shutdown'));
189
190
        // initialize the values
191 1
        $this->registryProcessor = $registryProcessor;
192 1
        $this->importProcessor = $importProcessor;
193 1
        $this->configuration = $configuration;
194 1
        $this->input = $input;
195 1
        $this->output = $output;
196 1
        $this->systemLoggers = $systemLoggers;
197 1
    }
198
199
    /**
200
     * The shutdown handler to catch fatal errors.
201
     *
202
     * This method is need to make sure, that an existing PID file will be removed
203
     * if a fatal error has been triggered.
204
     *
205
     * @return void
206
     */
207
    public function shutdown()
208
    {
209
210
        // check if there was a fatal error caused shutdown
211
        if ($lastError = error_get_last()) {
212
            // initialize error type and message
213
            $type = 0;
214
            $message = '';
215
            // extract the last error values
216
            extract($lastError);
217
            // query whether we've a fatal/user error
218
            if ($type === E_ERROR || $type === E_USER_ERROR) {
219
                // clean-up the PID file
220
                $this->unlock();
221
                // log the fatal error message
222
                $this->log($message, LogLevel::ERROR);
223
            }
224
        }
225
    }
226
227
    /**
228
     * Return's the logger with the passed name, by default the system logger.
229
     *
230
     * @param string $name The name of the requested system logger
231
     *
232
     * @return \Psr\Log\LoggerInterface The logger instance
233
     * @throws \Exception Is thrown, if the requested logger is NOT available
234
     */
235
    public function getSystemLogger($name = LoggerKeys::SYSTEM)
236
    {
237
238
        // query whether or not, the requested logger is available
239
        if (isset($this->systemLoggers[$name])) {
240
            return $this->systemLoggers[$name];
241
        }
242
243
        // throw an exception if the requested logger is NOT available
244
        throw new \Exception(sprintf('The requested logger \'%s\' is not available', $name));
245
    }
246
247
    /**
248
     * Query whether or not the system logger with the passed name is available.
249
     *
250
     * @param string $name The name of the requested system logger
251
     *
252
     * @return boolean TRUE if the logger with the passed name exists, else FALSE
253
     */
254
    public function hasSystemLogger($name = LoggerKeys::SYSTEM)
255
    {
256
        return isset($this->systemLoggers[$name]);
257
    }
258
259
    /**
260
     * Return's the array with the system logger instances.
261
     *
262
     * @return array The logger instance
263
     */
264
    public function getSystemLoggers()
265
    {
266
        return $this->systemLoggers;
267
    }
268
269
    /**
270
     * Return's the RegistryProcessor instance to handle the running threads.
271
     *
272
     * @return \TechDivision\Import\Services\RegistryProcessor The registry processor instance
273
     */
274
    public function getRegistryProcessor()
275
    {
276
        return $this->registryProcessor;
277
    }
278
279
    /**
280
     * Return's the import processor instance.
281
     *
282
     * @return \TechDivision\Import\Services\ImportProcessorInterface The import processor instance
283
     */
284
    public function getImportProcessor()
285
    {
286
        return $this->importProcessor;
287
    }
288
289
    /**
290
     * Return's the system configuration.
291
     *
292
     * @return \TechDivision\Import\ConfigurationInterface The system configuration
293
     */
294
    public function getConfiguration()
295
    {
296
        return $this->configuration;
297
    }
298
299
    /**
300
     * Return's the input stream to read console information from.
301
     *
302
     * @return \Symfony\Component\Console\Input\InputInterface An IutputInterface instance
303
     */
304
    public function getInput()
305
    {
306
        return $this->input;
307
    }
308
309
    /**
310
     * Return's the output stream to write console information to.
311
     *
312
     * @return \Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
313
     */
314 1
    public function getOutput()
315
    {
316 1
        return $this->output;
317
    }
318
319
    /**
320
     * Return's the unique serial for this import process.
321
     *
322
     * @return string The unique serial
323
     */
324
    public function getSerial()
325
    {
326
        return $this->serial;
327
    }
328
329
    /**
330
     * Persist the UUID of the actual import process to the PID file.
331
     *
332
     * @return void
333
     * @throws \Exception Is thrown, if the PID can not be locked or the PID can not be added
334
     * @throws \TechDivision\Import\Exceptions\ImportAlreadyRunningException Is thrown, if a import process is already running
335
     */
336
    public function lock()
337
    {
338
339
        // query whether or not, the PID has already been set
340
        if ($this->pid === $this->getSerial()) {
341
            return;
342
        }
343
344
        // if not, initialize the PID
345
        $this->pid = $this->getSerial();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getSerial() of type string is incompatible with the declared type array of property $pid.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
346
347
        // open the PID file
348
        $this->fh = fopen($filename = $this->getPidFilename(), 'a+');
349
350
        // try to lock the PID file exclusive
351
        if (!flock($this->fh, LOCK_EX|LOCK_NB)) {
352
            throw new ImportAlreadyRunningException(sprintf('PID file %s is already in use', $filename));
353
        }
354
355
        // append the PID to the PID file
356
        if (fwrite($this->fh, $this->pid . PHP_EOL) === false) {
357
            throw new \Exception(sprintf('Can\'t write PID %s to PID file %s', $this->pid, $filename));
358
        }
359
    }
360
361
    /**
362
     * Remove's the UUID of the actual import process from the PID file.
363
     *
364
     * @return void
365
     * @throws \Exception Is thrown, if the PID can not be removed
366
     */
367
    public function unlock()
368
    {
369
        try {
370
            // remove the PID from the PID file if set
371
            if ($this->pid === $this->getSerial() && is_resource($this->fh)) {
372
                // remove the PID from the file
373
                $this->removeLineFromFile($this->pid, $this->fh);
374
375
                // finally unlock/close the PID file
376
                flock($this->fh, LOCK_UN);
377
                fclose($this->fh);
378
379
                // if the PID file is empty, delete the file
380
                if (filesize($filename = $this->getPidFilename()) === 0) {
381
                    unlink($filename);
382
                }
383
            }
384
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
385
        } catch (FileNotFoundException $fnfe) {
0 ignored issues
show
Bug introduced by
The class TechDivision\Import\Exce...s\FileNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
386
            $this->getSystemLogger()->notice(sprintf('PID file %s doesn\'t exist', $this->getPidFilename()));
387
        } catch (LineNotFoundException $lnfe) {
0 ignored issues
show
Bug introduced by
The class TechDivision\Import\Exce...s\LineNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
388
            $this->getSystemLogger()->notice(sprintf('PID %s is can not be found in PID file %s', $this->pid, $this->getPidFilename()));
389
        } catch (\Exception $e) {
390
            throw new \Exception(sprintf('Can\'t remove PID %s from PID file %s', $this->pid, $this->getPidFilename()), null, $e);
391
        }
392
    }
393
394
    /**
395
     * Remove's the passed line from the file with the passed name.
396
     *
397
     * @param string   $line The line to be removed
398
     * @param resource $fh   The file handle of the file the line has to be removed
399
     *
400
     * @return void
401
     * @throws \Exception Is thrown, if the file doesn't exists, the line is not found or can not be removed
402
     */
403
    public function removeLineFromFile($line, $fh)
404
    {
405
406
        // initialize the array for the PIDs found in the PID file
407
        $lines = array();
408
409
        // initialize the flag if the line has been found
410
        $found = false;
411
412
        // rewind the file pointer
413
        rewind($fh);
414
415
        // read the lines with the PIDs from the PID file
416
        while (($buffer = fgets($fh, 4096)) !== false) {
417
            // remove the new line
418
            $buffer = trim($buffer);
419
            // if the line is the one to be removed, ignore the line
420
            if ($line === $buffer) {
421
                $found = true;
422
                continue;
423
            }
424
425
            // add the found PID to the array
426
            $lines[] = $buffer;
427
        }
428
429
        // query whether or not, we found the line
430
        if (!$found) {
431
            throw new LineNotFoundException(sprintf('Line %s can not be found', $line));
432
        }
433
434
        // empty the file and rewind the file pointer
435
        ftruncate($fh, 0);
436
        rewind($fh);
437
438
        // append the existing lines to the file
439
        foreach ($lines as $ln) {
440
            if (fwrite($fh, $ln . PHP_EOL) === false) {
441
                throw new \Exception(sprintf('Can\'t write %s to file', $ln));
442
            }
443
        }
444
    }
445
446
    /**
447
     * Process the given operation.
448
     *
449
     * @return void
450
     * @throws \Exception Is thrown if the operation can't be finished successfully
451
     */
452
    public function process()
453
    {
454
455
        try {
456
            // track the start time
457
            $startTime = microtime(true);
458
459
            // start the transaction
460
            $this->getImportProcessor()->getConnection()->beginTransaction();
461
462
            // prepare the global data for the import process
463
            $this->setUp();
464
465
            // process the plugins defined in the configuration
466
            foreach ($this->getConfiguration()->getPlugins() as $pluginConfiguration) {
467
                // query whether or not the operation has been stopped
468
                if ($this->isStopped()) {
469
                    break;
470
                }
471
                // process the plugin if not
472
                $this->pluginFactory($pluginConfiguration)->process();
473
            }
474
475
            // tear down the  instance
476
            $this->tearDown();
477
478
            // commit the transaction
479
            $this->getImportProcessor()->getConnection()->commit();
480
481
            // track the time needed for the import in seconds
482
            $endTime = microtime(true) - $startTime;
483
484
            // log a message that import has been finished
485
            $this->log(
486
                sprintf(
487
                    'Successfully finished import with serial %s in %f s',
488
                    $this->getSerial(),
489
                    $endTime
490
                ),
491
                LogLevel::INFO
492
            );
493
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
494
        } catch (ImportAlreadyRunningException $iare) {
0 ignored issues
show
Bug introduced by
The class TechDivision\Import\Exce...AlreadyRunningException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
495
            // tear down
496
            $this->tearDown();
497
498
            // rollback the transaction
499
            $this->getImportProcessor()->getConnection()->rollBack();
500
501
            // finally, if a PID has been set (because CSV files has been found),
502
            // remove it from the PID file to unlock the importer
503
            $this->unlock();
504
505
            // track the time needed for the import in seconds
506
            $endTime = microtime(true) - $startTime;
507
508
            // log a warning, because another import process is already running
509
            $this->getSystemLogger()->warning($iare->__toString());
510
511
            // log a message that import has been finished
512
            $this->getSystemLogger()->info(
513
                sprintf(
514
                    'Can\'t finish import with serial because another import process is running %s in %f s',
515
                    $this->getSerial(),
516
                    $endTime
517
                )
518
            );
519
520
            // re-throw the exception
521
            throw $iare;
522
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
523
        } catch (\Exception $e) {
524
            // tear down
525
            $this->tearDown();
526
527
            // rollback the transaction
528
            $this->getImportProcessor()->getConnection()->rollBack();
529
530
            // finally, if a PID has been set (because CSV files has been found),
531
            // remove it from the PID file to unlock the importer
532
            $this->unlock();
533
534
            // track the time needed for the import in seconds
535
            $endTime = microtime(true) - $startTime;
536
537
            // log a message that the file import failed
538
            foreach ($this->systemLoggers as $systemLogger) {
539
                $systemLogger->error($e->__toString());
540
            }
541
542
            // log a message that import has been finished
543
            $this->getSystemLogger()->info(
544
                sprintf(
545
                    'Can\'t finish import with serial %s in %f s',
546
                    $this->getSerial(),
547
                    $endTime
548
                )
549
            );
550
551
            // re-throw the exception
552
            throw $e;
553
        }
554
    }
555
556
    /**
557
     * Stop processing the operation.
558
     *
559
     * @param string $reason The reason why the operation has been stopped
560
     *
561
     * @return void
562
     */
563
    public function stop($reason)
564
    {
565
566
        // log a message that the operation has been stopped
567
        $this->log($reason, LogLevel::INFO);
568
569
        // stop processing the plugins by setting the flag to TRUE
570
        $this->stopped = true;
571
    }
572
573
    /**
574
     * Return's TRUE if the operation has been stopped, else FALSE.
575
     *
576
     * @return boolean TRUE if the process has been stopped, else FALSE
577
     */
578
    public function isStopped()
579
    {
580
        return $this->stopped;
581
    }
582
583
    /**
584
     * Factory method to create new plugin instances.
585
     *
586
     * @param \TechDivision\Import\Configuration\PluginConfigurationInterface $pluginConfiguration The plugin configuration instance
587
     *
588
     * @return object The plugin instance
589
     */
590
    protected function pluginFactory(PluginConfigurationInterface $pluginConfiguration)
591
    {
592
593
        // load the plugin class name
594
        $className = $pluginConfiguration->getClassName();
595
596
        // initialize and return the plugin instance
597
        return new $className($this, $pluginConfiguration);
598
    }
599
600
    /**
601
     * Lifecycle callback that will be inovked before the
602
     * import process has been started.
603
     *
604
     * @return void
605
     */
606
    protected function setUp()
607
    {
608
609
        // generate the serial for the new job
610
        $this->serial = Uuid::uuid4()->__toString();
611
612
        // write the TechDivision ANSI art icon to the console
613
        $this->log($this->ansiArt);
614
615
        // log the debug information, if debug mode is enabled
616
        if ($this->getConfiguration()->isDebugMode()) {
617
            // log the system's PHP configuration
618
            $this->log(sprintf('PHP version: %s', phpversion()), LogLevel::DEBUG);
619
            $this->log('-------------------- Loaded Extensions -----------------------', LogLevel::DEBUG);
620
            $this->log(implode(', ', $loadedExtensions = get_loaded_extensions()), LogLevel::DEBUG);
621
            $this->log('--------------------------------------------------------------', LogLevel::DEBUG);
622
623
            // write a warning for low performance, if XDebug extension is activated
624
            if (in_array('xdebug', $loadedExtensions)) {
625
                $this->log('Low performance exptected, as result of enabled XDebug extension!', LogLevel::WARNING);
626
            }
627
        }
628
629
        // log a message that import has been started
630
        $this->log(
631
            sprintf(
632
                'Now start import with serial %s (operation: %s)',
633
                $this->getSerial(),
634
                $this->getConfiguration()->getOperationName()
635
            ),
636
            LogLevel::INFO
637
        );
638
639
        // initialize the status
640
        $status = array(
641
            RegistryKeys::STATUS => 1,
642
            RegistryKeys::BUNCHES => 0,
643
            RegistryKeys::SOURCE_DIRECTORY => $this->getConfiguration()->getSourceDir(),
644
            RegistryKeys::MISSING_OPTION_VALUES => array()
645
        );
646
647
        // append it to the registry
648
        $this->getRegistryProcessor()->setAttribute($this->getSerial(), $status);
649
    }
650
651
    /**
652
     * Lifecycle callback that will be inovked after the
653
     * import process has been finished.
654
     *
655
     * @return void
656
     */
657
    protected function tearDown()
658
    {
659
        $this->getRegistryProcessor()->removeAttribute($this->getSerial());
660
    }
661
662
    /**
663
     * Simple method that writes the passed method the the console and the
664
     * system logger, if configured and a log level has been passed.
665
     *
666
     * @param string $msg      The message to log
667
     * @param string $logLevel The log level to use
668
     *
669
     * @return void
670
     */
671
    protected function log($msg, $logLevel = null)
672
    {
673
674
        // initialize the formatter helper
675
        $helper = new FormatterHelper();
676
677
        // map the log level to the console style
678
        $style = $this->mapLogLevelToStyle($logLevel);
679
680
        // format the message, according to the passed log level and write it to the console
681
        $this->getOutput()->writeln($logLevel ? $helper->formatBlock($msg, $style) : $msg);
682
683
        // log the message if a log level has been passed
684
        if ($logLevel && $systemLogger = $this->getSystemLogger()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $logLevel of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
685
            $systemLogger->log($logLevel, $msg);
686
        }
687
    }
688
689
    /**
690
     * Map's the passed log level to a valid symfony console style.
691
     *
692
     * @param string $logLevel The log level to map
693
     *
694
     * @return string The apropriate symfony console style
695
     */
696
    protected function mapLogLevelToStyle($logLevel)
697
    {
698
699
        // query whether or not the log level is mapped
700
        if (isset($this->logLevelStyleMapping[$logLevel])) {
701
            return $this->logLevelStyleMapping[$logLevel];
702
        }
703
704
        // return the default style => info
705
        return Simple::DEFAULT_STYLE;
706
    }
707
708
    /**
709
     * Return's the PID filename to use.
710
     *
711
     * @return string The PID filename
712
     */
713
    protected function getPidFilename()
714
    {
715
        return $this->getConfiguration()->getPidFilename();
716
    }
717
}
718