setup check
[phorkie.git] / src / phorkie / SetupCheck.php
1 <?php
2 namespace phorkie;
3
4 class SetupCheck
5 {
6     protected $deps = array(
7         'pear.php.net/VersionControl_Git' => 'VersionControl_Git',
8         'pear.twig-project.org/Twig'      => 'Twig_Autoloader',
9         'pear.php.net/Date_HumanDiff'     => 'Date_HumanDiff',
10     );
11
12     protected $writableDirs;
13
14
15     public function __construct()
16     {
17         $cfg = $GLOBALS['phorkie']['cfg'];
18         $this->writableDirs = array(
19             'gitdir' => $cfg['gitdir'],
20             'workdir' => $cfg['workdir'],
21         );
22     }
23
24     public static function run()
25     {
26         $sc = new self();
27         $sc->checkDeps();
28         $sc->checkDirs();
29     }
30
31     public function checkDeps()
32     {
33         foreach ($this->deps as $package => $class) {
34             if (!class_exists($class, true)) {
35                 $this->fail('PEAR package not installed: ' . $package);
36             }
37         }
38     }
39
40     public function checkDirs()
41     {
42         foreach ($this->writableDirs as $name => $dir) {
43             if (!is_dir($dir)) {
44                 $this->fail($name . ' directory does not exist at ' . $dir);
45             }
46             if (!is_writable($dir)) {
47                 $this->fail($name . ' directory is not writable at ' . $dir);
48             }
49         }
50     }
51
52     public function fail($msg)
53     {
54         throw new Exception($msg);
55     }
56 }
57
58 ?>