Skip to content

Commit 39bc838

Browse files
committed
ADded ConfigHelper
1 parent 7704c87 commit 39bc838

File tree

2 files changed

+65
-16
lines changed

2 files changed

+65
-16
lines changed

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
use Symfony\Component\Console\Input\ArrayInput;
105105
use PHPCR\Shell\Console\Command\Shell\ConfigInitCommand;
106106
use PHPCR\Shell\Console\Helper\ConfigHelper;
107+
use Symfony\Component\Console\Input\StringInput;
107108

108109
class ShellApplication extends Application
109110
{
@@ -147,15 +148,15 @@ public function init()
147148

148149
$session = $this->initSession();
149150

151+
$this->getHelperSet()->set(new ConfigHelper());
150152
$this->getHelperSet()->set(new EditorHelper($this->session));
153+
$this->getHelperSet()->set(new NodeHelper($this->session));
154+
$this->getHelperSet()->set(new PathHelper($this->session));
151155
$this->getHelperSet()->set(new PhpcrConsoleDumperHelper());
152156
$this->getHelperSet()->set(new PhpcrHelper($this->session));
157+
$this->getHelperSet()->set(new RepositoryHelper($this->session->getRepository()));
153158
$this->getHelperSet()->set(new ResultFormatterHelper());
154159
$this->getHelperSet()->set(new TextHelper());
155-
$this->getHelperSet()->set(new NodeHelper($this->session));
156-
$this->getHelperSet()->set(new PathHelper($this->session));
157-
$this->getHelperSet()->set(new RepositoryHelper($this->session->getRepository()));
158-
$this->getHelperSet()->set(new ConfigHelper());
159160

160161
// add new commands
161162
$this->add(new AccessControlPrivilegeListCommand());
@@ -241,24 +242,12 @@ public function init()
241242
$ls = $this->get('dump');
242243
$ls->getDefinition()->getArgument('identifier')->setDefault(null);
243244

244-
$this->add($this->wrap(new NodeListCommand())
245-
->setName('ls')
246-
);
247-
$this->add($this->wrap(new PathChangeCommand())
248-
->setName('cd')
249-
);
250245
$this->add($this->wrap(new NodeRemoveCommand())
251246
->setName('rm')
252247
);
253248
$this->add($this->wrap(new NodesUpdateCommand())
254249
->setName('update')
255250
);
256-
$this->add($this->wrap(new NodeTouchCommand())
257-
->setName('touch')
258-
);
259-
$this->add($this->wrap(new NodeTypeRegisterCommand())
260-
->setName('nt-register')
261-
);
262251
$this->add($this->wrap(new WorkspacePurgeCommand())
263252
->setName('workspace-purge')
264253
);

src/PHPCR/Shell/Console/Helper/ConfigHelper.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,35 @@
33
namespace PHPCR\Shell\Console\Helper;
44

55
use Symfony\Component\Console\Helper\Helper;
6+
use Symfony\Component\Yaml\Yaml;
67

8+
/**
9+
* Helper for config stuff
10+
*
11+
* @author Daniel Leech <daniel@dantleech.com>
12+
*/
713
class ConfigHelper extends Helper
814
{
15+
/**
16+
* Base filenames of all the possible configuration files
17+
* in the users configuration directory.
18+
*
19+
* @var array
20+
*/
21+
protected $configKeys = array(
22+
'alias'
23+
);
24+
25+
/**
26+
* Cached configuration
27+
*
28+
* @var array
29+
*/
30+
protected $cachedConfig = null;
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
935
public function getName()
1036
{
1137
return 'config';
@@ -46,4 +72,38 @@ public function getConfigDir()
4672

4773
return $home;
4874
}
75+
76+
private function loadConfig()
77+
{
78+
$config = array();
79+
80+
$configDir = $this->getConfigDir();
81+
82+
foreach ($this->configKeys as $configKey) {
83+
$fullPath = $configDir . '/' . $configKey . '.yml';
84+
$config[$configKey] = array();
85+
86+
if (file_exists($fullPath)) {
87+
$config[$configKey] = Yaml::parse($fullPath);
88+
}
89+
}
90+
91+
return $config;
92+
}
93+
94+
/**
95+
* Return the configuration
96+
*
97+
* @return array
98+
*/
99+
public function getConfig($type)
100+
{
101+
if (null !== $this->cachedConfig) {
102+
return $this->cachedConfig;
103+
}
104+
105+
$this->cachedConfig = $this->loadConfig();
106+
107+
return $this->cachedConfig['alias'];
108+
}
49109
}

0 commit comments

Comments
 (0)