[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: ChmodTask.php 3076 2006-12-18 08:52:12Z fabien $ 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 22 require_once 'phing/Task.php'; 23 include_once 'phing/types/FileSet.php'; 24 25 /** 26 * Task that changes the permissions on a file/directory. 27 * 28 * @author Manuel Holtgrewe <grin@gmx.net> 29 * @author Hans Lellelid <hans@xmpl.org> 30 * @version $Revision: 1.12 $ 31 * @package phing.tasks.system 32 */ 33 class ChmodTask extends Task { 34 35 private $file; 36 37 private $mode; 38 39 private $filesets = array(); 40 41 private $filesystem; 42 43 private $quiet = false; 44 private $failonerror = true; 45 46 /** 47 * This flag means 'note errors to the output, but keep going' 48 * @see setQuiet() 49 */ 50 function setFailonerror($bool) { 51 $this->failonerror = $bool; 52 } 53 54 /** 55 * Set quiet mode, which suppresses warnings if chmod() fails. 56 * @see setFailonerror() 57 */ 58 function setQuiet($bool) { 59 $this->quiet = $bool; 60 if ($this->quiet) { 61 $this->failonerror = false; 62 } 63 } 64 65 /** 66 * Sets a single source file to touch. If the file does not exist 67 * an empty file will be created. 68 */ 69 function setFile(PhingFile $file) { 70 $this->file = $file; 71 } 72 73 function setMode($str) { 74 $this->mode = $str; 75 } 76 77 /** 78 * Nested creator, adds a set of files (nested fileset attribute). 79 */ 80 function createFileSet() { 81 $num = array_push($this->filesets, new FileSet()); 82 return $this->filesets[$num-1]; 83 } 84 85 /** 86 * Execute the touch operation. 87 * @return void 88 */ 89 function main() { 90 // Check Parameters 91 $this->checkParams(); 92 $this->chmod(); 93 } 94 95 /** 96 * Ensure that correct parameters were passed in. 97 * @return void 98 */ 99 private function checkParams() { 100 101 if ($this->file === null && empty($this->filesets)) { 102 throw new BuildException("Specify at least one source - a file or a fileset."); 103 } 104 105 if ($this->mode === null) { 106 throw new BuildException("You have to specify an octal mode for chmod."); 107 } 108 109 // check for mode to be in the correct format 110 if (!preg_match('/^([0-7]){3,4}$/', $this->mode)) { 111 throw new BuildException("You have specified an invalid mode."); 112 } 113 114 } 115 116 /** 117 * Does the actual work. 118 * @return void 119 */ 120 private function chmod() { 121 122 if (strlen($this->mode) === 4) { 123 $mode = octdec($this->mode); 124 } else { 125 // we need to prepend the 0 before converting 126 $mode = octdec("0". $this->mode); 127 } 128 129 // one file 130 if ($this->file !== null) { 131 $this->chmodFile($this->file, $mode); 132 } 133 134 // filesets 135 foreach($this->filesets as $fs) { 136 137 $ds = $fs->getDirectoryScanner($this->project); 138 $fromDir = $fs->getDir($this->project); 139 140 $srcFiles = $ds->getIncludedFiles(); 141 $srcDirs = $ds->getIncludedDirectories(); 142 143 for ($j = 0, $filecount = count($srcFiles); $j < $filecount; $j++) { 144 $this->chmodFile(new PhingFile($fromDir, $srcFiles[$j]), $mode); 145 } 146 147 for ($j = 0, $dircount = count($srcDirs); $j < $dircount; $j++) { 148 $this->chmodFile(new PhingFile($fromDir, $srcDirs[$j]), $mode); 149 } 150 } 151 152 } 153 154 /** 155 * Actually change the mode for the file. 156 * @param PhingFile $file 157 * @param int $mode 158 */ 159 private function chmodFile(PhingFile $file, $mode) { 160 if ( !$file->exists() ) { 161 throw new BuildException("The file " . $file->__toString() . " does not exist"); 162 } 163 164 try { 165 $file->setMode($mode); 166 $this->log("Changed file mode on '" . $file->__toString() ."' to " . vsprintf("%o", $mode)); 167 } catch (Exception $e) { 168 if($this->failonerror) { 169 throw $e; 170 } else { 171 $this->log($e->getMessage(), $this->quiet ? PROJECT_MSG_VERBOSE : PROJECT_MSG_WARN); 172 } 173 } 174 } 175 176 } 177
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |