source: branches/1.2/workflow/inc/class.fsutils.inc.php @ 1349

Revision 1349, 3.1 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * Supporting class for file system handling.
4 * @author Carlos Eduardo Nogueira Gonçalves
5 * @version 1.0
6 * @package Workflow
7 * @license http://www.gnu.org/copyleft/gpl.html GPL
8 */
9class FsUtils {
10       
11        /**
12         * @var string $configDir Path to configs files directory
13         * @access public
14         */
15        var $configDir = null;
16        /**
17         * @var string $processDir Path to workflow processes directory
18         * @access public
19         */
20        var $processDir = null;
21        /**
22         * @var array $errors Errors summary
23         * @access public
24         */
25        var $errors = null;             
26        /**
27         * Sets constants and initializes attributes
28         * @access public
29         * @return FileSystem
30         */
31        function FsUtils()
32        {
33                $this->configDir = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP .'inc' . SEP . 'config' . SEP;
34                $this->processDir = GALAXIA_PROCESSES . SEP;                           
35                $this->errors = array();               
36        }
37        /**
38         * Simple wrapper for appending errors to the summary
39         * @param string $errorMsg Error details
40         * @return void
41         * @access public
42         */
43        function _appendError ($errorMsg) {
44                array_push($this->errors, $errorMsg);
45        }
46        /**
47         * Clears error summary
48         * @return void
49         * @access public
50         */     
51        function clearErrors () {
52                $this->errors = array();
53        }
54        /**
55         * Reads directories contents
56         * @param string $path Directory path
57         * @return mixed  Directory's content where the array's keys are the file names and the values its contents or false in case of errors
58         * @access public 
59         */
60        function readFolder ($path)     {
61
62                $contents = array(); /* dir content */
63                $dir = null; /* dir reading handle */   
64                $file = null; /* each dir's file name */
65                $absolute = $this->processDir . $path; /* absolute path to the processes dir - prevents access to other dirs */
66
67                if (! is_dir($absolute) ) {                     
68                        $this->_appendError("O caminho $absolute não é um diretório.");
69                        return false;
70                }
71               
72                if (! $dir = @opendir($absolute) ) {                   
73                        $this->_appendError("O diretório $absolute não pode ser lido.");
74                        return false;                                   
75                } else {                       
76                        while ( false !== ( $fileName = readdir($dir) ) ) {                             
77                                $file = $absolute . $fileName; /* gets full path reference */
78                                if ( is_file($file) ) { /* ignores subdirs */                                                                           
79                                        if (! is_readable($file) ) {
80                                                $this->_appendError("O arquivo " . $path . $file . " não pode ser lido.");
81                                        } else {
82                                                @$contents[$fileName] = file_get_contents($file); /* reads each file contents */                                               
83                                        }                                                               
84                                }                               
85                        }
86                }
87               
88                if ( count($this->errors) ) {
89                        return false;
90                } else {
91                        return $contents;
92                }
93        }
94       
95        /**
96         * Loads configuration settings from *.ini files
97         * @param string $configFile File name
98         * @return array Configuration settings or an error message
99         * @access public
100         */
101        function getConfig ($configFile) {             
102               
103                $absolute = $this->configDir . $configFile; /* absolute path to the config file - prevents access to other dirs */
104               
105                if (! file_exists($absolute) ) {                       
106                        return "O arquivo $configFile não existe.";
107                } elseif (! is_file($absolute) ) {
108                        return $configFile . " não é um arquivo comum.";
109                } elseif (! is_readable($absolute) ) {
110                        return "O arquivo $configFile não pode ser lido.";
111                }
112
113                return parse_ini_file($absolute);
114        }               
115}
116?>
Note: See TracBrowser for help on using the repository browser.