Source for file Filesystem.php
Documentation is available at Filesystem.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
// $Id: Filesystem.php 320703 2011-12-08 22:08:40Z danielc $
require_once 'Tree/Error.php';
* the Filesystem interface to the tree class
* this is a bit different, as id we use the entire path, since we know
* this is unique in a filesystem and an integer id could only be created
* virtually, it doesnt have a tight connection to the actual directory
* i.e. using 'add' with ids could fail since we dont know if we get the same
* id when we call 'add' with a parentId to create a new folder under since
* our id would be made up. So we use the complete path as id, which takes up
* a lot of memory, i know but since php is typeless its possible and it makes
* life easier when we want to create another dir, since we get the dir
* as parentId passed to the 'add' method, which makes it easy to create
* I also thought about hashing the path name but then the add method is
* not that easy to implement ... may be one day :-)
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @var array saves the options passed to the constructor
'columnNameMaps' => array (),
// {{{ Tree_Memory_Filesystem()
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @param string $dsn the path on the filesystem
* @param array $options additional options you can set
$this->_options = $options;
* retreive all the navigation data from the db and call build to build
* the tree in the array data and structure
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
// unset the data to be sure to get the real data again, no old data
$this->data[$this->_path] = array (
$this->_setup ($this->_path, $this->_path);
function _setup ($path, $parentId = 0 )
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..'
$this->_setup (" $path/$file" , " $path/$file" );
* this is tricky on a filesystem, since we are working with id's
* as identifiers and we need to be sure, the parentId to create
* a node under is the same as when the tree was last read.
* but this might be tricky.
function add($newValues, $parent = 0 , $prevId = 0 )
if (!@mkdir(" $parent/{$newValues['name']}" , 0700 )) {
$newValues['name']. ' under '. $parent,
return " $parent/{$newValues['name']}";
return $this->_throwError ('couldnt remove dir '. $id, __LINE__ );
function copy($srcId, $destId)
# if(!@copy($srcId, $destId)) this would only be for files :-)
# FIXXME loop through the directory to copy the children too !!!
return $this->_throwError (
" couldnt copy, $destId already exists in $srcId " , __LINE__
if (!@mkdir($dest, 0700 )) {
return $this->_throwError (
" couldnt copy dir from $srcId to $destId " , __LINE__
* prepare multiple results
* @author Wolfram Kriesing <wolfram@kriesing.de>
function _prepareResults ($results)
foreach ($results as $aResult) {
$newResults[] = $this->_prepareResult ($aResult);
* map back the index names to get what is expected
* @author Wolfram Kriesing <wolfram@kriesing.de>
function _prepareResult ($result)
$map = $this->getOption ('columnNameMaps');
foreach ($map as $key => $columnName) {
$result[$key] = $result[$columnName];
unset ($result[$columnName]);
Documentation generated on Mon, 11 Mar 2019 15:47:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|