/[cvs]/nfo/php/libs/net.php.pear/Tree/Tree.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.pear/Tree/Tree.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Jul 7 02:49:20 2004 UTC (20 years, 1 month ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -1 lines
updated to Tree-0.2.4

1 joko 1.1 <?php
2     //
3     // +----------------------------------------------------------------------+
4     // | PHP Version 4 |
5     // +----------------------------------------------------------------------+
6     // | Copyright (c) 1997-2003 The PHP Group |
7     // +----------------------------------------------------------------------+
8     // | This source file is subject to version 2.02 of the PHP license, |
9     // | that is bundled with this package in the file LICENSE, and is |
10     // | available at through the world-wide-web at |
11     // | http://www.php.net/license/2_02.txt. |
12     // | If you did not receive a copy of the PHP license and are unable to |
13     // | obtain it through the world-wide-web, please send a note to |
14     // | license@php.net so we can mail you a copy immediately. |
15     // +----------------------------------------------------------------------+
16     // | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
17     // +----------------------------------------------------------------------+
18     //
19     // $Id: Tree.php,v 1.4 2003/01/04 11:56:27 mj Exp $
20    
21     require_once('PEAR.php');
22    
23     /**
24     * the DB interface to the tree class
25     *
26     * @access public
27     * @author Wolfram Kriesing <wolfram@kriesing.de>
28     * @version 2001/06/27
29     * @package Tree
30     */
31     class Tree extends PEAR
32     {
33    
34     /**
35     * setup an object which works on trees that are temporarily saved in memory
36     * dont use with huge trees, suggested is a maximum size of tree of
37     * about 1000-5000 elements since the entire tree is read at once from the data source.
38     * use this to instanciate a class of a tree if you i.e.
39     * - need the entire tree at once
40     * - want to work on the tree w/o db-access for every call
41     * since this set of classes loads the entire tree into the memory, you should
42     * be aware about the size of the tree you work on using this class
43     * for one you should know how efficient this kind of tree class is on
44     * your data source (i.e. db) and what effect it has reading the entire tree at once.
45     * on small trees, like upto about 1000 elements an instance of this class
46     * will give you very powerful means to manage/modify the tree, no matter from which
47     * data source it comes, either from a nested-DB, simple-DB, XML-File/String or
48     * whatever is implemented
49     *
50     * @version 2002/02/05
51     * @access public
52     * @author Wolfram Kriesing <wolfram@kriesing.de>
53     * @param string $type the kind of data source this class shall work on initially,
54     * you can still switch later, by using "setDataSource"
55     * to i.e. export data from a DB to XML, or whatever implementation might exist some day
56     * currently available types are: 'DBsimple', 'XML'
57     * TODO: DBnested (which i think should be implemented after Dynamic/DBnested, since it would only need
58     * to use it's methods to manage the tree)
59     * @param $dsn $dsn the dsn, or filename, etc., empty i.e. for XML if you use setupByRawData
60     */
61     function &setupMemory( $type , $dsn='' , $options=array() )
62     # if anyone knows a better name it would be great to change it, since "setupMemory" kind of reflects it
63     # but i think it's not obvious if you dont know what is meant
64     {
65     require_once('Tree/Memory.php');
66    
67     return new Tree_Memory( $type , $dsn , $options );
68     } // end of function
69    
70     /**
71     * setup an object that works on trees where each element(s) are read on demand from the given data source
72     * actually this was intended to serve for nested trees which are read from
73     * the db up on demand, since it doesnt make sense to read a huge tree into
74     * the memory when you only want to access one level of this tree
75     *
76     * in short: an instance returned by this method works on a tree by mapping
77     * every request (such as getChild, getParent ...) to the data source defined to work on
78     *
79     * @version 2002/02/05
80     * @access public
81     * @author Wolfram Kriesing <wolfram@kriesing.de>
82     * @param
83     */
84     function &setupDynamic( $type , $dsn , $options=array() )
85     # "dynamic" stands for retreiving a tree(chunk) dynamically when needed,
86     # better name would be great :-)
87     {
88     require_once("Tree/Dynamic/$type.php");
89    
90     $className = 'Tree_Dynamic_'.$type;
91     $obj = & new $className( $dsn , $options );
92     return $obj;
93     } // end of function
94    
95     /**
96     * this is just a wrapper around the two setup methods above
97     * some example calls:
98     * <code>
99     * $tree = Tree::setup( 'Dynamic_DBnested' , 'mysql://root@localhost/test' , array('table'=>'nestedTree') );
100     * $tree = Tree::setup( 'Memory_DBsimple' , 'mysql://root@localhost/test' , array('table'=>'simpleTree') );
101     * $tree = Tree::setup( 'Memory_XML' , '/path/to/some/xml/file.xml' );
102     * </code>
103     *
104     * you can call the following too, but the functions/classes are not implemented yet
105     * or not finished
106     * <code>
107     * $tree = Tree::setup( 'Memory_DBnested' , 'mysql://root@localhost/test' , array('table'=>'nestedTree') );
108     * $tree = Tree::setup( 'Dynamic_XML' , '/path/to/some/xml/file.xml' );
109     * </code>
110     *
111     * and those would be really cool to have one day:
112     * LDAP, Filesystem, WSDL, ...
113     *
114     * @access private
115     * @version 2002/03/07
116     * @author Wolfram Kriesing <wolfram@kriesing.de>
117     * @param
118     * @return
119     */
120     function setup( $type , $dsn , $options=array() )
121     {
122     $type = explode( '_' , $type );
123     $method = 'setup'.$type[0];
124     return Tree::$method( $type[1] , $dsn , $options );
125     }
126    
127     }
128    
129     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed