| 1 | <?php␊ |
| 2 | /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */␊ |
| 3 | /*␊ |
| 4 | # ***** BEGIN LICENSE BLOCK *****␊ |
| 5 | # This file is part of InDefero, an open source project management application.␊ |
| 6 | # Copyright (C) 2008 CĂ©ondo Ltd and contributors.␊ |
| 7 | #␊ |
| 8 | # InDefero is free software; you can redistribute it and/or modify␊ |
| 9 | # it under the terms of the GNU General Public License as published by␊ |
| 10 | # the Free Software Foundation; either version 2 of the License, or␊ |
| 11 | # (at your option) any later version.␊ |
| 12 | #␊ |
| 13 | # InDefero is distributed in the hope that it will be useful,␊ |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of␊ |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the␊ |
| 16 | # GNU General Public License for more details.␊ |
| 17 | #␊ |
| 18 | # You should have received a copy of the GNU General Public License␊ |
| 19 | # along with this program; if not, write to the Free Software␊ |
| 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA␊ |
| 21 | #␊ |
| 22 | # ***** END LICENSE BLOCK ***** */␊ |
| 23 | ␊ |
| 24 | /**␊ |
| 25 | * Manage differents SCM systems␊ |
| 26 | */␊ |
| 27 | class IDF_Scm␊ |
| 28 | {␊ |
| 29 | ␊ |
| 30 | /**␊ |
| 31 | * Returns an instance of the correct scm backend object.␊ |
| 32 | *␊ |
| 33 | * @return Object␊ |
| 34 | */␊ |
| 35 | public static function get($request=null)␊ |
| 36 | {␊ |
| 37 | // Get scm type from project conf ; defaults to git␊ |
| 38 | $scm = $request->conf->getVal('scm', 'git');␊ |
| 39 | $scms = Pluf::f('allowed_scm');␊ |
| 40 | return call_user_func(array($scms[$scm], 'factory'),␊ |
| 41 | $request->project);␊ |
| 42 | }␊ |
| 43 | ␊ |
| 44 | /**␊ |
| 45 | * Equivalent to exec but with caching.␊ |
| 46 | *␊ |
| 47 | * @param string Command␊ |
| 48 | * @param &array Output␊ |
| 49 | * @param &int Return value␊ |
| 50 | * @return string Last line of the output␊ |
| 51 | */␊ |
| 52 | public static function exec($command, &$output=array(), &$return=0)␊ |
| 53 | {␊ |
| 54 | $key = md5($command);␊ |
| 55 | $cache = Pluf_Cache::factory();␊ |
| 56 | if (null === ($res=$cache->get($key))) {␊ |
| 57 | $ll = exec($command, $output, $return);␊ |
| 58 | $cache->set($key, array($ll, $return, $output));␊ |
| 59 | } else {␊ |
| 60 | list($ll, $return, $output) = $res;␊ |
| 61 | }␊ |
| 62 | return $ll;␊ |
| 63 | }␊ |
| 64 | ␊ |
| 65 | /**␊ |
| 66 | * Equivalent to shell_exec but with caching.␊ |
| 67 | *␊ |
| 68 | * @param string Command␊ |
| 69 | * @return string Output of the command␊ |
| 70 | */␊ |
| 71 | public static function shell_exec($command)␊ |
| 72 | {␊ |
| 73 | $key = md5($command);␊ |
| 74 | $cache = Pluf_Cache::factory();␊ |
| 75 | if (null === ($res=$cache->get($key))) {␊ |
| 76 | $res = shell_exec($command);␊ |
| 77 | $cache->set($key, $res);␊ |
| 78 | } ␊ |
| 79 | return $res;␊ |
| 80 | }␊ |
| 81 | }␊ |
| 82 | ␊ |
| 83 | |