PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/install/phing/classes/phing/tasks/system/condition/OsCondition.php

https://github.com/chregu/fluxcms
PHP | 60 lines | 27 code | 5 blank | 28 comment | 4 complexity | f2c55932fe04a3005c740bfc42ef0fcd MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/tasks/system/condition/ConditionBase.php';
  22. /**
  23. * Condition that tests the OS type.
  24. *
  25. * @author Andreas Aderhold <andi@binarycloud.com>
  26. * @copyright © 2001,2002 THYRELL. All rights reserved
  27. * @version $Revision: 1.7 $ $Date: 2003/12/24 13:02:09 $
  28. * @access public
  29. * @package phing.tasks.system.condition
  30. */
  31. class OsCondition implements Condition {
  32. private $family;
  33. function setFamily($f) {
  34. $this->family = strtolower($f);
  35. }
  36. function evaluate() {
  37. $osName = strtolower(Phing::getProperty("os.name"));
  38. $pathSep = Phing::getProperty("path.separator");
  39. if ($this->family !== null) {
  40. if ($this->family === "windows") {
  41. return strpos($osName, "win") !== false;
  42. } elseif ($this->family === "dos") {
  43. return $pathSep === ";";
  44. } elseif ($this->family === "mac") {
  45. return strpos($osName, "mac") !== false;
  46. } elseif ($this->family === ("unix")) {
  47. return ($pathSep === ":"
  48. && (!StringHelper::startsWith($osName, "mac") || StringHelper::endsWith($osName, "x")));
  49. }
  50. throw new BuildException("Don't know how to detect os family '" . $this->family . "'");
  51. }
  52. return false;
  53. }
  54. }