Location: PHPKode > projects > Aukyla Platform > aukyla/doc/html/a00237.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Aukyla PHP Framework</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="StyleSheet" href="auton.css" type="text/css" media="screen">
  </head>

  <body>
    <div id="mainmenu">
      <a href="http://www.auton.nl/" class="home">Home</a>
    </div>
    <div id="submenu">
      <a class="logo" href="http://www.auton.nl/"></a>

      <div class="head">Ads</div>
      <a href="http://sourceforge.net/"><img src="http://sourceforge.net/sflogo.php?group_id=116358&amp;type=1" alt="SourceForge.net Logo" style="padding: 2px 4px; width: 88px; height: 31px; border: 0px"></a>
      <a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox" style="width: 110px; height: 32px; border: 0px"></a>
    </div>
    <div id="main">
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">base</a></div>
<h1>URI.php</h1><div class="fragment"><pre class="fragment">00001 &lt;?php
00002 <span class="comment">/*</span>
00003 <span class="comment">     URI.php, handling of local URI's.</span>
00004 <span class="comment">     Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg</span>
00005 <span class="comment"></span>
00006 <span class="comment">     This program is free software; you can redistribute it and/or modify it</span>
00007 <span class="comment">     under the terms of the GNU General Public License as published by the Free</span>
00008 <span class="comment">     Software Foundation; either version 2 of the License, or (at your option)</span>
00009 <span class="comment">     any later version.</span>
00010 <span class="comment"></span>
00011 <span class="comment">     This program is distributed in the hope that it will be useful, but WITHOUT</span>
00012 <span class="comment">     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
00013 <span class="comment">     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for</span>
00014 <span class="comment">     more details.</span>
00015 <span class="comment"></span>
00016 <span class="comment">     You should have received a copy of the GNU General Public License along</span>
00017 <span class="comment">     with this program; if not, write to the Free Software Foundation, Inc.,</span>
00018 <span class="comment">     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00019 <span class="comment"></span>
00020 <span class="comment">     For any questions, comments or whatever, you may mail me at: hide@address.com</span>
00021 <span class="comment">*/</span>
00022 
00023 require_once('Constants.php');
00024 require_once('<a class="code" href="a00153.html">String</a>.php');
00025 
00029 define('PERMISSION_NONE',          0x00000000);
00030 define('PERMISSION_READ',          0x00000001);
00031 define('PERMISSION_APPEND',        0x00000002);
00032 define('PERMISSION_MODIFY',        0x00000004);
00033 define('PERMISSION_DELETE',        0x00000008);
00034 define('PERMISSION_ADMINISTRATE',  0x00000010);
00035 define('PERMISSION_CUSTOM',        0x00010000);
00036 
<a name="l00090"></a><a class="code" href="a00120.html">00090</a> <span class="keyword">class </span><a class="code" href="a00120.html">LocalURIManager</a>
00091 {
<a name="l00098"></a><a class="code" href="a00120.html#a0">00098</a>         <span class="keyword">public</span> function __construct()
00099         {
00100                 $this-&gt;namespaces = array();
00101                 $this-&gt;handles = array();
00102                 $this-&gt;nextHandle = 1;
00103         }
00104 
00105         <span class="keyword">public</span> function __destruct()
00106         {
00107                 $this-&gt;namespaces = array();
00108                 $this-&gt;handles = array();
00109                 $this-&gt;nextHandle = 1;
00110         }
00111 
<a name="l00125"></a><a class="code" href="a00120.html#e0">00125</a>         <span class="keyword">public</span> <span class="keyword">static</span> function registerURINamespace($<span class="keyword">namespace</span>, $className)
00126         {
00127                 <span class="keywordflow">if</span>(stream_wrapper_register($<span class="keyword">namespace</span>, $className) == <span class="keyword">false</span>)
00128                 {
00129                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00130                 }
00131 
00132                 $manager = self::instance();
00133 
00134                 $manager-&gt;namespaces[$namespace] = $className;
00135                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00136         }
00137 
00150         <span class="keyword">public</span> <span class="keyword">static</span> function callFunctionByURI($function, $uri, $args = array(), $saveHandle = <span class="keyword">false</span>)
00151         {
00152                 $namespace = <a class="code" href="a00153.html#e4">String::stripSpecialChars</a>(String::substringBefore($uri, <span class="charliteral">':'</span>));
00153 
00154                 <span class="keywordflow">if</span>($namespace == '')
00155                 {
00156                         trigger_error(<span class="stringliteral">"No namespace passed to URI::$function($uri)"</span>);
00157                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00158                 }
00159 
00160                 $className = self::loadNamespace($<span class="keyword">namespace</span>);
00161 
00162                 <span class="keywordflow">if</span>($className == <span class="keyword">false</span>)
00163                 {
00164                         trigger_error(<span class="stringliteral">"Invalid namespace \"$namespace\" passed to URI::$function($uri)"</span>);
00165                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00166                 }
00167 
00168                 $namespaceInstance = <span class="keyword">new</span> $className;
00169 
00170                 $args = array_merge(array($uri), $args);
00171                 $result = call_user_func_array(array($namespaceInstance, $function), $args);
00172                 <span class="keywordflow">if</span>($result == <span class="keyword">true</span> &amp;&amp; $saveHandle == <span class="keyword">true</span>)
00173                 {
00174                         $manager = self::instance();
00175 
00176                         $handle = $manager-&gt;nextHandle++;
00177                         $manager-&gt;handles[$handle] = $namespaceInstance;
00178                         <span class="keywordflow">return</span> $handle;
00179                 }
00180                 <span class="keywordflow">return</span> $result;
00181         }
00182 
<a name="l00192"></a><a class="code" href="a00120.html#e2">00192</a>         <span class="keyword">public</span> <span class="keyword">static</span> function loadNamespace($<span class="keyword">namespace</span>)
00193         {
00194                 $manager = self::instance();
00195 
00196                 <span class="keywordflow">if</span>(isset($manager-&gt;namespaces[$<span class="keyword">namespace</span>]))
00197                 {
00198                         <span class="keywordflow">return</span> $manager-&gt;namespaces[$namespace];
00199                 }
00200 
00201                 $manager = <span class="stringliteral">"{$namespace}_URIManager"</span>;
00202                 global $$manager;
00203 
00204                 $className = <span class="stringliteral">"{$namespace}_URINamespace"</span>;
00205                 $include = include_once(<span class="stringliteral">"URINamespaces/$className.php"</span>);
00206                 <span class="keywordflow">if</span>($include == <span class="keyword">false</span> ||
00207                    self::registerURINamespace($<span class="keyword">namespace</span>, $className) == <span class="keyword">false</span>)
00208                 {
00209                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00210                 }
00211 
00212                 <span class="keywordflow">return</span> $className;
00213         }
00214 
00227         <span class="keyword">public</span> <span class="keyword">static</span> function callFunctionByHandle($function, $handle, $args = array(), $closeHandle = <span class="keyword">false</span>)
00228         {
00229                 $manager = self::instance();
00230 
00231                 $namespaceInstance = $manager-&gt;handles[$handle];
00232                 <span class="keywordflow">if</span>($namespaceInstance === NULL)
00233                 {
00234                         trigger_error(<span class="stringliteral">"Invalid handle passed to URI::$function()"</span>);
00235                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00236                 }
00237 
00238                 $callback = array($namespaceInstance, $function);
00239                 $result = call_user_func_array($callback, $args);
00240                 <span class="keywordflow">if</span>($result == <span class="keyword">true</span> &amp;&amp; $closeHandle == <span class="keyword">true</span>)
00241                 {
00242                         unset($manager-&gt;handles[$handle]);
00243                 }
00244                 <span class="keywordflow">return</span> $result;
00245         }
00246 
00247         <span class="keyword">private</span> <span class="keyword">static</span> function instance()
00248         {
00249                 <span class="keywordflow">if</span>(self::$instance == null)
00250                 {
00251                         self::$instance = <span class="keyword">new</span> <a class="code" href="a00120.html">LocalURIManager</a>();
00252                 }
00253 
00254                 <span class="keywordflow">return</span> self::$instance;
00255         }
00256 
00257         <span class="keyword">private</span> <span class="keyword">static</span> $instance = null;
00258         <span class="keyword">private</span> $namespaces;
00259         <span class="keyword">private</span> $handles;
00260         <span class="keyword">private</span> $nextHandle;
00261 }
00262 
<a name="l00281"></a><a class="code" href="a00163.html">00281</a> <span class="keyword">class </span><a class="code" href="a00163.html">URI</a>
00282 {
<a name="l00294"></a><a class="code" href="a00163.html#e0">00294</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isLocalURI($uri)
00295         {
00296                 $namespace = <a class="code" href="a00153.html#e4">String::stripSpecialChars</a>(String::substringBefore($uri, <span class="charliteral">':'</span>));
00297 
00298                 <span class="keywordflow">if</span>($namespace == '')
00299                 {
00300                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00301                 }
00302 
00303                 <span class="keywordflow">if</span>(<a class="code" href="a00120.html#e2">LocalURIManager::loadNamespace</a>($<span class="keyword">namespace</span>) === <span class="keyword">false</span>)
00304                 {
00305                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00306                 }
00307 
00308                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00309         }
00310 
<a name="l00335"></a><a class="code" href="a00163.html#e1">00335</a>         <span class="keyword">public</span> <span class="keyword">static</span> function uniquePath($path, $suggestion)
00336         {
00337                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00338                 {
00339                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00340                 }
00341 
00342                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('uniquePath', $path, array($suggestion));
00343         }
00344 
<a name="l00355"></a><a class="code" href="a00163.html#e2">00355</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fopen($path, $mode)
00356         {
00357                 $permissionMode = str_replace(array(<span class="charliteral">'b'</span>, <span class="charliteral">'t'</span>), '', $mode);
00358                 <span class="keywordflow">if</span>(LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET)) === <span class="keyword">false</span>)
00359                 {
00360                         $permissions = LocalURIManager::callFunctionByURI('permissions', dirname($path));
00361                         <span class="keywordflow">if</span>($permissionMode{0} == <span class="charliteral">'r'</span> || !($permissions &amp; PERMISSION_APPEND))
00362                         {
00363                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00364                         }
00365                 }
00366                 <span class="keywordflow">else</span>
00367                 {
00368                         $permissions = LocalURIManager::callFunctionByURI('permissions', $path);
00369                         <span class="keywordflow">if</span>($permissionMode{0} == <span class="charliteral">'x'</span> ||
00370                            $permissionMode == <span class="charliteral">'r'</span> &amp;&amp; !($permissions &amp; PERMISSION_READ) ||
00371                            $permissionMode == 'r+' &amp;&amp; ($permissions &amp; (PERMISSION_READ | PERMISSION_MODIFY)) != (PERMISSION_READ | PERMISSION_MODIFY) ||
00372                            $permissionMode == <span class="charliteral">'w'</span> &amp;&amp; !($permissions &amp; PERMISSION_MODIFY) ||
00373                            $permissionMode == 'w+' &amp;&amp; ($permissions &amp; (PERMISSION_READ | PERMISSION_MODIFY)) != (PERMISSION_READ | PERMISSION_MODIFY) ||
00374                            $permissionMode == <span class="charliteral">'a'</span> &amp;&amp; !($permissions &amp; PERMISSION_APPEND) ||
00375                            $permissionMode == 'a+' &amp;&amp; ($permissions &amp; (PERMISSION_READ | PERMISSION_APPEND)) != (PERMISSION_READ | PERMISSION_MODIFY))
00376                         {
00377                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00378                         }
00379                 }
00380 
00381                 $openedPath = '';
00382                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('stream_open', $path, array($mode, 0, $openedPath), <span class="keyword">true</span>);
00383         }
00384 
<a name="l00392"></a><a class="code" href="a00163.html#e3">00392</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fread($handle, $length)
00393         {
00394                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_read', $handle, array($length));
00395         }
00396 
<a name="l00404"></a><a class="code" href="a00163.html#e4">00404</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fwrite($handle, $string)
00405         {
00406                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_write', $handle, array($string));
00407         }
00408 
<a name="l00416"></a><a class="code" href="a00163.html#e5">00416</a>         <span class="keyword">public</span> <span class="keyword">static</span> function feof($handle)
00417         {
00418                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_eof', $handle);
00419         }
00420 
<a name="l00427"></a><a class="code" href="a00163.html#e6">00427</a>         <span class="keyword">public</span> <span class="keyword">static</span> function ftell($handle)
00428         {
00429                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_tell', $handle);
00430         }
00431 
<a name="l00442"></a><a class="code" href="a00163.html#e7">00442</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fseek($handle, $offset, $whence = SEEK_SET)
00443         {
00444                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_seek', $handle, array($offset, $whence));
00445         }
00446 
<a name="l00454"></a><a class="code" href="a00163.html#e8">00454</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fflush($handle)
00455         {
00456                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_flush', $handle);
00457         }
00458 
<a name="l00467"></a><a class="code" href="a00163.html#e9">00467</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fstat($handle)
00468         {
00469                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_stat', $handle);
00470         }
00471 
<a name="l00479"></a><a class="code" href="a00163.html#e10">00479</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fclose($handle)
00480         {
00481                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('stream_close', $handle);
00482         }
00483 
<a name="l00495"></a><a class="code" href="a00163.html#e11">00495</a>         <span class="keyword">public</span> <span class="keyword">static</span> function file($path)
00496         {
00497                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00498                 {
00499                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00500                 }
00501 
00502                 $fp     = LocalURIManager::callFunctionByURI   ('stream_open',  $path, array(<span class="charliteral">'r'</span>), <span class="keyword">true</span>);
00503                 $stats  = LocalURIManager::callFunctionByHandle('stream_stat',  $fp,   array(0));
00504                 $string = LocalURIManager::callFunctionByHandle('stream_read',  $fp,   array($stats['size']));
00505                           LocalURIManager::callFunctionByHandle('stream_close', $fp,   array(), <span class="keyword">true</span>);
00506                 <span class="keywordflow">return</span> explode(<span class="stringliteral">"\n"</span>, $string);
00507         }
00508 
<a name="l00516"></a><a class="code" href="a00163.html#e12">00516</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fileGetContents($path)
00517         {
00518                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00519                 {
00520                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00521                 }
00522 
00523                 $fp       = LocalURIManager::callFunctionByURI   ('stream_open', $path, array(<span class="charliteral">'r'</span>), <span class="keyword">true</span>);
00524                 $stats    = LocalURIManager::callFunctionByHandle('stream_stat', $fp,   array(0));
00525                 <span class="keywordflow">if</span>($stats['size'] == 0)
00526                 {
00527                         $contents = '';
00528                 }
00529                 <span class="keywordflow">else</span>
00530                 {
00531                         $contents = LocalURIManager::callFunctionByHandle('stream_read', $fp, array($stats['size']));
00532                 }
00533                 LocalURIManager::callFunctionByHandle('stream_close', $fp, array(), <span class="keyword">true</span>);
00534 
00535                 <span class="keywordflow">return</span> $contents;
00536         }
00537 
<a name="l00551"></a><a class="code" href="a00163.html#e13">00551</a>         <span class="keyword">public</span> <span class="keyword">static</span> function copy($source, $destination, &amp;$realDestination = '')
00552         {
00553                 $realDestination = $destination;
00554 
00555                 <span class="comment">// check read permissions for the source file</span>
00556                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $source) &amp; PERMISSION_READ))
00557                 {
00558                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00559                 }
00560                 <span class="comment">// if the file does not yet exist, check if we are allowed to create a new file in the directory</span>
00561                 <span class="keywordflow">if</span>(($stats = LocalURIManager::callFunctionByURI('url_stat', $destination, array(STREAM_URL_STAT_QUIET))) === <span class="keyword">false</span>)
00562                 {
00563                         $permissions = LocalURIManager::callFunctionByURI('permissions', dirname($destination));
00564                         <span class="keywordflow">if</span>(!($permissions &amp; PERMISSION_APPEND))
00565                         {
00566                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00567                         }
00568                 }
00569                 <span class="comment">// if the destination itself is a directory, check if we are allowed to create a new file in the directory</span>
00570                 <span class="keywordflow">else</span> <span class="keywordflow">if</span>($stats['mode'] &amp; 0040000)
00571                 {
00572                         $permissions = LocalURIManager::callFunctionByURI('permissions', $destination);
00573                         <span class="keywordflow">if</span>(!($permissions &amp; PERMISSION_APPEND))
00574                         {
00575                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00576                         }
00577                         $destination = LocalURIManager::callFunctionByURI('uniquePath', $destination, array(basename($source)));
00578                         $realDestination = $destination;
00579                 }
00580                 <span class="comment">// otherwise, check if the destination file is writable</span>
00581                 <span class="keywordflow">else</span>
00582                 {
00583                         $permissions = LocalURIManager::callFunctionByURI('permissions', $destination);
00584                         <span class="keywordflow">if</span>(!($permissions &amp; PERMISSION_MODIFY))
00585                         {
00586                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00587                         }
00588                 }
00589 
00590                 $fpIn     = LocalURIManager::callFunctionByURI   ('stream_open',  $source,      array(<span class="charliteral">'r'</span>), <span class="keyword">true</span>);
00591                 $fpOut    = LocalURIManager::callFunctionByURI   ('stream_open',  $destination, array(<span class="charliteral">'w'</span>), <span class="keyword">true</span>);
00592 
00593                 $stats    = LocalURIManager::callFunctionByHandle('stream_stat',  $fpIn,        array(0));
00594                 <span class="keywordflow">while</span>($stats['size'] &gt; 0)
00595                 {
00596                         $blockSize = ($stats['size'] &lt; 1048576 ? $stats['size'] : 1048576);
00597                         $contents = LocalURIManager::callFunctionByHandle('stream_read',  $fpIn,  array($blockSize));
00598                                     LocalURIManager::callFunctionByHandle('stream_write', $fpOut, array($contents));
00599                         $stats['size'] -= $blockSize;
00600                 }
00601 
00602                 LocalURIManager::callFunctionByHandle('stream_close', $fpIn,        array(), <span class="keyword">true</span>);
00603                 LocalURIManager::callFunctionByHandle('stream_close', $fpOut,       array(), <span class="keyword">true</span>);
00604 
00605                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00606         }
00607 
<a name="l00614"></a><a class="code" href="a00163.html#e14">00614</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fileSize($path)
00615         {
00616                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00617                 {
00618                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00619                 }
00620 
00621                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(0));
00622                 <span class="keywordflow">return</span> ($stats != <span class="keyword">false</span> ? $stats['size'] : <span class="keyword">false</span>);
00623         }
00624 
<a name="l00647"></a><a class="code" href="a00163.html#e15">00647</a>         <span class="keyword">public</span> <span class="keyword">static</span> function permissions($path)
00648         {
00649                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('permissions', $path);
00650         }
00651 
<a name="l00687"></a><a class="code" href="a00163.html#e16">00687</a>         <span class="keyword">public</span> <span class="keyword">static</span> function permissionsArray($path)
00688         {
00689                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00690                 {
00691                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00692                 }
00693 
00694                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('permissionsArray', $path, array());
00695         }
00696 
<a name="l00715"></a><a class="code" href="a00163.html#e17">00715</a>         <span class="keyword">public</span> <span class="keyword">static</span> function setPermissionsArray($path, $permissions, $recursive = <span class="keyword">false</span>)
00716         {
00717                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_ADMINISTRATE))
00718                 {
00719                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00720                 }
00721 
00722                 $result = LocalURIManager::callFunctionByURI('setPermissionsArray', $path, array($permissions));
00723 
00724                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET));
00725                 <span class="keywordflow">if</span>($recursive == <span class="keyword">true</span> &amp;&amp; ($stats['mode'] &amp; 0040000))
00726                 {
00727                         <span class="keywordflow">if</span>(($handle = LocalURIManager::callFunctionByURI('dir_opendir', $path, array(0), <span class="keyword">true</span>)) === <span class="keyword">false</span>)
00728                         {
00729                                 <span class="keywordflow">return</span> $result;
00730                         }
00731 
00732                         <span class="keywordflow">while</span>(($entry = LocalURIManager::callFunctionByHandle('dir_readdir', $handle)) !== <span class="keyword">false</span>)
00733                         {
00734                                 <span class="keywordflow">if</span>(self::setPermissionsArray($entry, $permissions, <span class="keyword">true</span>) == <span class="keyword">false</span>)
00735                                 {
00736                                         $result = <span class="keyword">false</span>;
00737                                 }
00738                         }
00739                         LocalURIManager::callFunctionByHandle('dir_closedir', $handle, array(), <span class="keyword">true</span>);
00740                 }
00741 
00742                 <span class="keywordflow">return</span> $result;
00743         }
00744 
<a name="l00754"></a><a class="code" href="a00163.html#e18">00754</a>         <span class="keyword">public</span> <span class="keyword">static</span> function mkdir($path, $options = STREAM_REPORT_ERRORS)
00755         {
00756                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', dirname($path)) &amp; PERMISSION_APPEND))
00757                 {
00758                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00759                 }
00760 
00761                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('mkdir', $path, array(0700, $options));
00762         }
00763 
<a name="l00772"></a><a class="code" href="a00163.html#e19">00772</a>         <span class="keyword">public</span> <span class="keyword">static</span> function rmdir($path, $recursive = <span class="keyword">false</span>)
00773         {
00774                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_DELETE))
00775                 {
00776                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00777                 }
00778 
00779                 <span class="keywordflow">if</span>($recursive)
00780                 {
00781                         <span class="keywordflow">return</span> URI::recursiveRmdir($path);
00782                 }
00783 
00784                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('rmdir', $path);
00785         }
00786 
00790         <span class="keyword">private</span> <span class="keyword">static</span> function recursiveRmdir($path)
00791         {
00792                 <span class="keywordflow">if</span>(($handle = LocalURIManager::callFunctionByURI('dir_opendir', $path, array(0), <span class="keyword">true</span>)) === <span class="keyword">false</span>)
00793                 {
00794                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00795                 }
00796 
00797                 $entries = array();
00798                 <span class="keywordflow">while</span>(($entry = LocalURIManager::callFunctionByHandle('dir_readdir', $handle)) !== <span class="keyword">false</span>)
00799                 {
00800                         $entries[] = $entry;
00801                 }
00802                 LocalURIManager::callFunctionByHandle('dir_closedir', $handle, array(), <span class="keyword">true</span>);
00803 
00804                 foreach($entries as $entry)
00805                 {
00806                         $stats = LocalURIManager::callFunctionByURI('url_stat', $entry, array(STREAM_URL_STAT_QUIET));
00807                         <span class="keywordflow">if</span>($stats['mode'] &amp; 040000)
00808                         {
00809                                 <span class="keywordflow">if</span>(URI::recursiveRmdir($entry) == <span class="keyword">false</span>)
00810                                 {
00811                                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00812                                 }
00813                         }
00814                         <span class="keywordflow">else</span>
00815                         {
00816                                 <span class="keywordflow">if</span>(LocalURIManager::callFunctionByURI('unlink', $entry) == <span class="keyword">false</span>)
00817                                 {
00818                                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00819                                 }
00820                         }
00821                 }
00822 
00823                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('rmdir', $path);
00824         }
00825 
<a name="l00836"></a><a class="code" href="a00163.html#e20">00836</a>         <span class="keyword">public</span> <span class="keyword">static</span> function touch($path)
00837         {
00838                 <span class="keywordflow">if</span>(LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET)) === <span class="keyword">false</span>)
00839                 {
00840                         <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', dirname($path)) &amp; PERMISSION_APPEND))
00841                         {
00842                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00843                         }
00844                 }
00845                 <span class="keywordflow">else</span>
00846                 {
00847                         <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_APPEND))
00848                         {
00849                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00850                         }
00851                 }
00852 
00853                 <span class="keywordflow">if</span>(($handle = LocalURIManager::callFunctionByURI('stream_open', $path, array(<span class="charliteral">'a'</span>), <span class="keyword">true</span>)) === <span class="keyword">false</span>)
00854                 {
00855                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00856                 }
00857                 LocalURIManager::callFunctionByHandle('stream_close', $path, array(), <span class="keyword">true</span>);
00858 
00859                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00860         }
00861 
<a name="l00868"></a><a class="code" href="a00163.html#e21">00868</a>         <span class="keyword">public</span> <span class="keyword">static</span> function unlink($path)
00869         {
00870                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_DELETE))
00871                 {
00872                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00873                 }
00874 
00875                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('unlink', $path);
00876         }
00877 
<a name="l00889"></a><a class="code" href="a00163.html#e22">00889</a>         <span class="keyword">public</span> <span class="keyword">static</span> function rename($pathFrom, $pathTo, &amp;$realPathTo = '')
00890         {
00891                 <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e0">String::substringBefore</a>($pathFrom, ':<span class="comment">//') != String::substringBefore($pathTo, '://') ||</span>
00892                    String::startsWith(String::simplifyPath($pathTo), String::simplifyPath($pathFrom)))
00893                 {
00894                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00895                 }
00896 
00897                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $pathFrom) &amp; PERMISSION_DELETE))
00898                 {
00899                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00900                 }
00901 
00902                 $stats = LocalURIManager::callFunctionByURI('url_stat', $pathTo, array(STREAM_URL_STAT_QUIET));
00903                 <span class="keywordflow">if</span>(($stats !== <span class="keyword">false</span> &amp;&amp; $stats['mode'] &amp; 0040000) == <span class="keyword">false</span>)
00904                 {
00905                         <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $pathTo) &amp; PERMISSION_MODIFY))
00906                         {
00907                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00908                         }
00909                 }
00910                 <span class="keywordflow">else</span>
00911                 {
00912                         <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $pathTo) &amp; PERMISSION_APPEND))
00913                         {
00914                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00915                         }
00916 
00917                         $realPathTo = self::uniquePath($pathTo, basename($pathFrom));
00918                 }
00919 
00920                 <span class="keywordflow">if</span>(LocalURIManager::callFunctionByURI('rename', $pathFrom, array($realPathTo)) == <span class="keyword">true</span>)
00921                 {
00922                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00923                 }
00924 
00925                 $realPathTo = $pathFrom;
00926                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00927         }
00928 
<a name="l00937"></a><a class="code" href="a00163.html#e23">00937</a>         <span class="keyword">public</span> <span class="keyword">static</span> function opendir($path)
00938         {
00939                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00940                 {
00941                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00942                 }
00943 
00944                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('dir_opendir', $path, array(0), <span class="keyword">true</span>);
00945         }
00946 
<a name="l00954"></a><a class="code" href="a00163.html#e24">00954</a>         <span class="keyword">public</span> <span class="keyword">static</span> function readdir($handle)
00955         {
00956                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('dir_readdir', $handle);
00957         }
00958 
<a name="l00966"></a><a class="code" href="a00163.html#e25">00966</a>         <span class="keyword">public</span> <span class="keyword">static</span> function rewinddir($handle)
00967         {
00968                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('dir_rewinddir', $handle);
00969         }
00970 
<a name="l00978"></a><a class="code" href="a00163.html#e26">00978</a>         <span class="keyword">public</span> <span class="keyword">static</span> function closedir($handle)
00979         {
00980                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByHandle('dir_closedir', $handle, array(), <span class="keyword">true</span>);
00981         }
00982 
<a name="l00992"></a><a class="code" href="a00163.html#e27">00992</a>         <span class="keyword">public</span> <span class="keyword">static</span> function entries($path)
00993         {
00994                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
00995                 {
00996                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00997                 }
00998 
00999                 <span class="keywordflow">if</span>(($handle = LocalURIManager::callFunctionByURI('dir_opendir', $path, array(0), <span class="keyword">true</span>)) === <span class="keyword">false</span>)
01000                 {
01001                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
01002                 }
01003 
01004                 $entries = array();
01005                 <span class="keywordflow">while</span>(($entry = LocalURIManager::callFunctionByHandle('dir_readdir', $handle)) !== <span class="keyword">false</span>)
01006                 {
01007                         $entries[] = $entry;
01008                 }
01009                 LocalURIManager::callFunctionByHandle('dir_closedir', $handle, array(), <span class="keyword">true</span>);
01010 
01011                 <span class="keywordflow">return</span> $entries;
01012         }
01013 
<a name="l01022"></a><a class="code" href="a00163.html#e28">01022</a>         <span class="keyword">public</span> <span class="keyword">static</span> function stat($path)
01023         {
01024                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
01025                 {
01026                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
01027                 }
01028 
01029                 <span class="keywordflow">return</span> LocalURIManager::callFunctionByURI('url_stat', $path, array(0));
01030         }
01031 
<a name="l01038"></a><a class="code" href="a00163.html#e29">01038</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fileExists($path)
01039         {
01040                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET));
01041                 <span class="keywordflow">return</span> ($stats === <span class="keyword">false</span> ? <span class="keyword">false</span> : <span class="keyword">true</span>);
01042         }
01043 
<a name="l01050"></a><a class="code" href="a00163.html#e30">01050</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isDir($path)
01051         {
01052                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET));
01053                 <span class="keywordflow">return</span> (($stats !== <span class="keyword">false</span> &amp;&amp; $stats['mode'] &amp; 0040000) ? <span class="keyword">true</span> : <span class="keyword">false</span>);
01054         }
01055 
<a name="l01062"></a><a class="code" href="a00163.html#e31">01062</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isFile($path)
01063         {
01064                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET));
01065                 <span class="keywordflow">return</span> (($stats !== <span class="keyword">false</span> &amp;&amp; $stats['mode'] &amp; 0100000) ? <span class="keyword">true</span> : <span class="keyword">false</span>);
01066         }
01067 
<a name="l01074"></a><a class="code" href="a00163.html#e32">01074</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isLink($path)
01075         {
01076                 $stats = LocalURIManager::callFunctionByURI('url_stat', $path, array(STREAM_URL_STAT_QUIET));
01077                 <span class="keywordflow">return</span> ($stats !== <span class="keyword">false</span> &amp;&amp; $stats['mode'] == 0120000 ? <span class="keyword">true</span> : <span class="keyword">false</span>);
01078         }
01079 
<a name="l01097"></a><a class="code" href="a00163.html#e33">01097</a>         <span class="keyword">public</span> <span class="keyword">static</span> function metaData($path, $key, $<span class="keywordflow">default</span> = <span class="keyword">false</span>)
01098         {
01099                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_READ))
01100                 {
01101                         <span class="keywordflow">return</span> $default;
01102                 }
01103 
01104                 $meta = LocalURIManager::callFunctionByURI('metaData', $path, array($key));
01105                 <span class="keywordflow">return</span> ($meta === <span class="keyword">false</span> ? $default : $meta);
01106         }
01107 
<a name="l01122"></a><a class="code" href="a00163.html#e34">01122</a>         <span class="keyword">public</span> <span class="keyword">static</span> function setMetaData($path, $key, $value = <span class="keyword">false</span>, $recursive = <span class="keyword">false</span>)
01123         {
01124                 <span class="keywordflow">if</span>(!(LocalURIManager::callFunctionByURI('permissions', $path) &amp; PERMISSION_MODIFY))
01125                 {
01126                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
01127                 }
01128 
01129                 $result = LocalURIManager::callFunctionByURI('setMetaData', $path, array($key, $value));
01130 
01131                 <span class="keywordflow">if</span>($recursive == <span class="keyword">true</span>)
01132                 {
01133                         <span class="keywordflow">if</span>(($handle = LocalURIManager::callFunctionByURI('dir_opendir', $path, array(0), <span class="keyword">true</span>)) === <span class="keyword">false</span>)
01134                         {
01135                                 <span class="keywordflow">return</span> $result;
01136                         }
01137 
01138                         <span class="keywordflow">while</span>(($entry = LocalURIManager::callFunctionByHandle('dir_readdir', $handle)) !== <span class="keyword">false</span>)
01139                         {
01140                                 <span class="keywordflow">if</span>($this-&gt;setMetaData($entry, $key, $value, <span class="keyword">true</span>) == <span class="keyword">false</span>)
01141                                 {
01142                                         $result = <span class="keyword">false</span>;
01143                                 }
01144                         }
01145                         LocalURIManager::callFunctionByHandle('dir_closedir', $handle, array(), <span class="keyword">true</span>);
01146                 }
01147 
01148                 <span class="keywordflow">return</span> $result;
01149         }
01150 }
01151 
<a name="l01174"></a><a class="code" href="a00121.html">01174</a> <span class="keyword">abstract</span> <span class="keyword">class </span><a class="code" href="a00121.html">LocalURINamespace</a>
01175 {
01184         <span class="keyword">abstract</span> <span class="keyword">public</span> function stream_open($path, $mode, $options = 0, &amp;$opened_path = '');
01185 
01190         <span class="keyword">abstract</span> <span class="keyword">public</span> function stream_close();
01191 
<a name="l01199"></a><a class="code" href="a00121.html#a2">01199</a>         <span class="keyword">public</span> function stream_read($count)
01200         {
01201                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01202         }
01203 
<a name="l01211"></a><a class="code" href="a00121.html#a3">01211</a>         <span class="keyword">public</span> function stream_write($data)
01212         {
01213                 <span class="keywordflow">return</span> 0;
01214         }
01215 
<a name="l01219"></a><a class="code" href="a00121.html#a4">01219</a>         <span class="keyword">public</span> function stream_eof()
01220         {
01221                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
01222         }
01223 
<a name="l01227"></a><a class="code" href="a00121.html#a5">01227</a>         <span class="keyword">public</span> function stream_tell()
01228         {
01229                 <span class="keywordflow">return</span> 0;
01230         }
01231 
<a name="l01235"></a><a class="code" href="a00121.html#a6">01235</a>         <span class="keyword">public</span> function stream_seek($offset, $whence)
01236         {
01237                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01238         }
01239 
<a name="l01243"></a><a class="code" href="a00121.html#a7">01243</a>         <span class="keyword">public</span> function stream_flush()
01244         {
01245                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
01246         }
01247 
<a name="l01251"></a><a class="code" href="a00121.html#a8">01251</a>         <span class="keyword">public</span> function stream_stat()
01252         {
01253                 <span class="keywordflow">return</span> array('dev'     =&gt;  0,
01254                              'ino'     =&gt;  0,
01255                              'mode'    =&gt;  0,
01256                              'nlink'   =&gt;  0,
01257                              'uid'     =&gt;  0,
01258                              'gid'     =&gt;  0,
01259                              'rdev'    =&gt; -1,
01260                              'size'    =&gt;  0,
01261                              'atime'   =&gt;  0,
01262                              'mtime'   =&gt;  0,
01263                              'ctime'   =&gt;  0,
01264                              'blksize' =&gt; -1,
01265                              'blocks'  =&gt;  0);
01266         }
01267 
<a name="l01271"></a><a class="code" href="a00121.html#a9">01271</a>         <span class="keyword">public</span> function unlink($path)
01272         {
01273                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01274         }
01275 
<a name="l01279"></a><a class="code" href="a00121.html#a10">01279</a>         <span class="keyword">public</span> function rename($path_from, $path_to)
01280         {
01281                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01282         }
01283 
<a name="l01287"></a><a class="code" href="a00121.html#a11">01287</a>         <span class="keyword">public</span> function mkdir($path, $mode, $options)
01288         {
01289                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01290         }
01291 
<a name="l01295"></a><a class="code" href="a00121.html#a12">01295</a>         <span class="keyword">public</span> function rmdir($path, $options)
01296         {
01297                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01298         }
01299 
<a name="l01303"></a><a class="code" href="a00121.html#a13">01303</a>         <span class="keyword">public</span> function dir_opendir($path, $options)
01304         {
01305                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01306         }
01307 
<a name="l01311"></a><a class="code" href="a00121.html#a14">01311</a>         <span class="keyword">public</span> function url_stat($path, $flags)
01312         {
01313                 <span class="keywordflow">return</span> array('dev'     =&gt;  0,
01314                              'ino'     =&gt;  0,
01315                              'mode'    =&gt;  0,
01316                              'nlink'   =&gt;  0,
01317                              'uid'     =&gt;  0,
01318                              'gid'     =&gt;  0,
01319                              'rdev'    =&gt; -1,
01320                              'size'    =&gt;  0,
01321                              'atime'   =&gt;  0,
01322                              'mtime'   =&gt;  0,
01323                              'ctime'   =&gt;  0,
01324                              'blksize' =&gt; -1,
01325                              'blocks'  =&gt;  0);
01326         }
01327 
<a name="l01331"></a><a class="code" href="a00121.html#a15">01331</a>         <span class="keyword">public</span> function dir_readdir()
01332         {
01333                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01334         }
01335 
<a name="l01339"></a><a class="code" href="a00121.html#a16">01339</a>         <span class="keyword">public</span> function dir_rewinddir()
01340         {
01341                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01342         }
01343 
<a name="l01347"></a><a class="code" href="a00121.html#a17">01347</a>         <span class="keyword">public</span> function dir_closedir()
01348         {
01349                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01350         }
01351 
<a name="l01362"></a><a class="code" href="a00121.html#a18">01362</a>         <span class="keyword">public</span> function uniquePath($path, $suggestion)
01363         {
01364                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01365         }
01366 
<a name="l01382"></a><a class="code" href="a00121.html#a19">01382</a>         <span class="keyword">public</span> function permissions($path)
01383         {
01384                 <span class="keywordflow">return</span> ($this-&gt;url_stat($path, STREAM_URL_STAT_QUIET) === <span class="keyword">false</span> ? <span class="keyword">false</span> :
01385                         (PERMISSION_READ |
01386                          PERMISSION_APPEND |
01387                          PERMISSION_MODIFY |
01388                          PERMISSION_DELETE |
01389                          PERMISSION_ADMINISTRATE));
01390         }
01391 
<a name="l01448"></a><a class="code" href="a00121.html#a20">01448</a>         <span class="keyword">public</span> function permissionsArray($path)
01449         {
01450                 <span class="keywordflow">return</span> ($this-&gt;url_stat($path, STREAM_URL_STAT_QUIET) === <span class="keyword">false</span> ? <span class="keyword">false</span> :
01451                         array('other' =&gt; (PERMISSION_READ |
01452                                           PERMISSION_APPEND |
01453                                           PERMISSION_MODIFY |
01454                                           PERMISSION_DELETE |
01455                                           PERMISSION_ADMINISTRATE)));
01456         }
01457 
<a name="l01469"></a><a class="code" href="a00121.html#a21">01469</a>         <span class="keyword">public</span> function setPermissionsArray($path, $permissions)
01470         {
01471                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01472         }
01473 
<a name="l01489"></a><a class="code" href="a00121.html#a22">01489</a>         <span class="keyword">public</span> function metaData($path, $key)
01490         {
01491                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01492         }
01493 
<a name="l01504"></a><a class="code" href="a00121.html#a23">01504</a>         <span class="keyword">public</span> function setMetaData($path, $key, $value)
01505         {
01506                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
01507         }
01508 }
</pre></div>    </div>
  </body>
</html>
Return current item: Aukyla Platform