Re: Re: Some thoughts about abstraction layers

From: Date: Thu, 29 Nov 2001 21:22:37 +0000
Subject: Re: Re: Some thoughts about abstraction layers
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3206@lists.php.net to get a copy of this message
> For small apps, whether you use a database wrapper or direct database calls > is irrelevant. For large apps, you have to use vendor specific SQL calls > at times to scale. Thats true. I created this "theory of abstraction layers" to find, which kind of abstraction layer the PEAR folks want. In a clean implementation of this layer, you can decide how much you want to abstract. > > +----------------------------------------------+ > > | Informationobjects | > > +----------------stored in---------------------+ > > | Informationcontainer | > > +---------------which could be-----------------+ > > | Datacontainers like | > > | RDBMS |OODBMS|LDAP|File| > > +------access data by---------+......+....+....+ > > | SQL | API-Calls| > > +-------from-------+---on-----+ > > | physical container | > > +--------------like-----------+ > > |MySQL|ORACLE|MSSQL|..........| > > +-----+------+-----+----------+ that question is what can we realize in PEAR, meaning what can be really generalized? IMO everything below the Data container layer. An using-example: $handle = DataContainer::factory( "RDBMS", "MySQL") ; $condition = array( "id", "gt", 12, array( "AND", array( "time", "lt", "103902326"))) ; $resultset = $handle -> SQL -> select( "table1", $columns, $condition) ; $resultset = $handle -> API -> query( "SELECT $columns FROM table1 WHERE id < 12 AND time > 103902326") ; Implemention would be something like that: class DataContainer { var $physical ; function factory( $container_type, $physical_container) { $physical = $physical_container ; // function returns a specfic DataAccess object return &new DataAccess($physical) ; } } class DataAccess { var $SQL ; var $API ; function DataAccess( $physical) { $sqlclass = "SQL_".$physical ; $apiclass = "API_".$physical ; $SQL = &new $sqlclass() ; $API = &new $apiclass() ; } } class MySQL_SQL { function select( $table, $columns, $condition, $limits, $order, ...) { // Creates a MYSQL compatible SQL-query for a SELECT-Statment $db = new DB() ; $db -> connect(...) ; // returning results } } class MySQL_API { function query( $query) { return mysql_query( $query) ; } } Another example for a file as data container // "CSV" means a access layer based on the CSV format $handle = DataContainer::factory( "FILE", "CSV") ; // 1 and 2 addressing the column of the csv line $condition = array( "1", "gt", 12, array( "AND", array( "2", "lt", "103902326"))) ; $resultset = $handle -> FGetCVS -> getEntries( $filename, $columns, $condition) ; class FGetCVS { // have functions based of the function fgetcvs } You have the possibilty to choose how deep you want to abstract. The given implemention needs a little bit clean up for real independence between the layers. Ie you can do: $db = new MySQL_SQL() ; ... $db -> select( "table1", $columns, $condition) ; Cu, Alex

« previous php.pear.dev (#3206) next »