TYPO3  7.6
finder/Shell/Shell.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Shell;
13 
17 class Shell
18 {
19  const TYPE_UNIX = 1;
20  const TYPE_DARWIN = 2;
21  const TYPE_CYGWIN = 3;
22  const TYPE_WINDOWS = 4;
23  const TYPE_BSD = 5;
24 
28  private $type;
29 
35  public function getType()
36  {
37  if (null === $this->type) {
38  $this->type = $this->guessType();
39  }
40 
41  return $this->type;
42  }
43 
51  public function testCommand($command)
52  {
53  if (!function_exists('exec')) {
54  return false;
55  }
56 
57  // todo: find a better way (command could not be available)
58  $testCommand = 'which ';
59  if (self::TYPE_WINDOWS === $this->type) {
60  $testCommand = 'where ';
61  }
62 
63  $command = escapeshellcmd($command);
64 
65  exec($testCommand.$command, $output, $code);
66 
67  return 0 === $code && count($output) > 0;
68  }
69 
75  private function guessType()
76  {
77  $os = strtolower(PHP_OS);
78 
79  if (false !== strpos($os, 'cygwin')) {
80  return self::TYPE_CYGWIN;
81  }
82 
83  if (false !== strpos($os, 'darwin')) {
84  return self::TYPE_DARWIN;
85  }
86 
87  if (false !== strpos($os, 'bsd')) {
88  return self::TYPE_BSD;
89  }
90 
91  if (0 === strpos($os, 'win')) {
92  return self::TYPE_WINDOWS;
93  }
94 
95  return self::TYPE_UNIX;
96  }
97 }