source: trunk/generator/classes/propel/engine/builder/om/php5/PHP5ExtensionPeerBuilder.php @ 372

Revision 372, 4.5 KB checked in by hans, 4 years ago (diff)

Preliminary implementation of ticket:267 (PDO support) and ticket:268 (on-demand map builder loading)
This changeset includes:

  • Change all runtime code to use PDO
  • Change (almost) all generator code to build PDO-enabled Peer + Object classes (Node classes not done yet).
  • Added new PHP runtime-conf format and support for INI files instead of PHP arrays.
  • New on-demand / lazy-loading for the table MapBuilder classes.
Line 
1<?php
2
3/*
4 *  $Id: PHP5BasicObjectBuilder.php 120 2005-06-17 02:18:41Z hans $
5 *
6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 *
18 * This software consists of voluntary contributions made by many individuals
19 * and is licensed under the LGPL. For more information please see
20 * <http://propel.phpdb.org>.
21 */
22
23require_once 'propel/engine/builder/om/PeerBuilder.php';
24
25/**
26 * Generates the empty PHP5 stub peer class for user object model (OM).
27 *
28 * This class produces the empty stub class that can be customized with application
29 * business logic, custom behavior, etc.
30 *
31 * This class replaces the ExtensionPeer.tpl, with the intent of being easier for users
32 * to customize (through extending & overriding).
33 *
34 * @author Hans Lellelid <hans@xmpl.org>
35 * @package propel.engine.builder.om.php5
36 */
37class PHP5ExtensionPeerBuilder extends PeerBuilder {
38       
39        /**
40         * Returns the name of the current class being built.
41         * @return string
42         */
43        public function getClassname()
44        {
45                return $this->getStubObjectBuilder()->getClassname() . 'Peer';
46        }
47
48        /**
49         * Adds the include() statements for files that this class depends on or utilizes.
50         * @param string &$script The script will be modified in this method.
51         */
52        protected function addIncludes(&$script)
53        {
54                $script .= "
55  // include base peer class
56  require_once '".$this->getPeerBuilder()->getClassFilePath()."';
57 
58  // include object class
59  include_once '".$this->getStubObjectBuilder()->getClassFilePath()."';
60";
61        } // addIncludes()
62       
63        /**
64         * Adds class phpdoc comment and openning of class.
65         * @param string &$script The script will be modified in this method.
66         */
67        protected function addClassOpen(&$script)
68        {
69               
70                $table = $this->getTable();
71                $tableName = $table->getName();
72                $tableDesc = $table->getDescription();
73               
74                $baseClassname = $this->getPeerBuilder()->getClassname();
75               
76                $script .= "
77
78/**
79 * Skeleton subclass for performing query and update operations on the '$tableName' table.
80 *
81 * $tableDesc
82 *";
83                if ($this->getBuildProperty('addTimeStamp')) {
84                        $now = strftime('%c');
85                        $script .= "
86 * This class was autogenerated by Propel on:
87 *
88 * $now
89 *";
90                }
91                $script .= "
92 * You should add additional methods to this class to meet the
93 * application requirements.  This class will only be generated as
94 * long as it does not already exist in the output directory.
95 *
96 * @package ".$this->getPackage()."
97 */     
98class ".$this->getClassname()." extends $baseClassname {
99";
100        }
101       
102                /**
103         * Specifies the methods that are added as part of the stub peer class.
104         *
105         * By default there are no methods for the empty stub classes; override this method
106         * if you want to change that behavior.
107         *
108         * @see ObjectBuilder::addClassBody()
109         */
110
111        protected function addClassBody(&$script)
112        {
113                // there is no class body
114        }
115       
116        /**
117         * Closes class.
118         * @param string &$script The script will be modified in this method.
119         */     
120        protected function addClassClose(&$script)
121        {
122                $script .= "
123} // " . $this->getClassname() . "
124";
125                $this->addStaticMapBuilderRegistration($script);
126        }
127       
128        /**
129         * Adds the static map builder registration code.
130         * @param string &$script The script will be modified in this method.
131         */
132        protected function addStaticMapBuilderRegistration(&$script)
133        {
134                $table = $this->getTable();
135                $mapBuilderFile = $this->getMapBuilderBuilder()->getClassFilePath();
136
137                $script .= "
138// static code to register the map builder for this table with the main Propel class
139try {
140        Propel::getDatabaseMap(".$this->getPeerClassname()."::DATABASE_NAME)->addTableBuilder(".$this->getPeerClassname()."::TABLE_NAME, ".$this->getPeerClassname()."::getMapBuilder());
141} catch (Exception \$e) {
142        Propel::log('Could not register MapBuilder  for ".$this->getPeerClassname()." with Propel: ' . \$e->getMessage(), Propel::LOG_ERR);
143}
144";
145        }
146       
147} // PHP5ExtensionPeerBuilder
Note: See TracBrowser for help on using the repository browser.