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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu Feb 27 16:49:56 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
+ initial commit, from PEAR

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

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