1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11: * @link http://cakephp.org CakePHP(tm) Project
12: * @since 2.8
13: * @license http://www.opensource.org/licenses/mit-license.php MIT License
14: */
15:
16: abstract class BaseShellHelper {
17:
18: /**
19: * Default config for this helper.
20: *
21: * @var array
22: */
23: protected $_defaultConfig = array();
24:
25: /**
26: * ConsoleOutput instance.
27: *
28: * @var ConsoleOutput
29: */
30: protected $_consoleOutput;
31:
32: /**
33: * Runtime config
34: *
35: * @var array
36: */
37: protected $_config = array();
38:
39: /**
40: * Whether the config property has already been configured with defaults
41: *
42: * @var bool
43: */
44: protected $_configInitialized = false;
45:
46: /**
47: * Constructor.
48: *
49: * @param ConsoleOutput $consoleOutput The ConsoleOutput instance to use.
50: * @param array $config The settings for this helper.
51: */
52: public function __construct(ConsoleOutput $consoleOutput, array $config = array()) {
53: $this->_consoleOutput = $consoleOutput;
54: $this->config($config);
55: }
56:
57: /**
58: * Initialize config & store config values
59: *
60: * @param null $config Config values to set
61: * @return array|void
62: */
63: public function config($config = null) {
64: if ($config === null) {
65: return $this->_config;
66: }
67: if (!$this->_configInitialized) {
68: $this->_config = array_merge($this->_defaultConfig, $config);
69: $this->_configInitialized = true;
70: } else {
71: $this->_config = array_merge($this->_config, $config);
72: }
73: }
74:
75: /**
76: * This method should output content using `$this->_consoleOutput`.
77: *
78: * @param array $args The arguments for the helper.
79: * @return void
80: */
81: abstract public function output($args);
82: }