4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Shell;
14 @trigger_error('The '.__NAMESPACE__.'\Shell class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
17 * @author Jean-François Simon <contact@jfsimon.fr>
19 * @deprecated since 2.8, to be removed in 3.0.
24 const TYPE_DARWIN = 2;
25 const TYPE_CYGWIN = 3;
26 const TYPE_WINDOWS = 4;
35 * Returns guessed OS type.
39 public function getType()
41 if (null === $this->type) {
42 $this->type = $this->guessType();
49 * Tests if a command is available.
51 * @param string $command
55 public function testCommand($command)
57 if (!function_exists('exec')) {
61 // todo: find a better way (command could not be available)
62 $testCommand = 'which ';
63 if (self::TYPE_WINDOWS === $this->type) {
64 $testCommand = 'where ';
67 $command = escapeshellcmd($command);
69 exec($testCommand.$command, $output, $code);
71 return 0 === $code && count($output) > 0;
79 private function guessType()
81 $os = strtolower(PHP_OS);
83 if (false !== strpos($os, 'cygwin')) {
84 return self::TYPE_CYGWIN;
87 if (false !== strpos($os, 'darwin')) {
88 return self::TYPE_DARWIN;
91 if (false !== strpos($os, 'bsd')) {
92 return self::TYPE_BSD;
95 if (0 === strpos($os, 'win')) {
96 return self::TYPE_WINDOWS;
99 return self::TYPE_UNIX;