PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/redbean/rb.php

https://bitbucket.org/sanbrar/zurmo-invoice-example
PHP | 8325 lines | 3206 code | 220 blank | 4899 comment | 388 complexity | 54e32e252d292266a366dbd058c10e64 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, GPL-3.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php /*
  2. .______.
  3. _______ ____ __| _/\_ |__ ____ _____ ____
  4. \_ __ \_/ __ \ / __ | | __ \_/ __ \\__ \ / \
  5. | | \/\ ___
  6. |__| \___ >____ | |___ /\___ >____ /___| /
  7. \/ \/ \/ \/ \/ \/
  8. RedBean Database Objects -
  9. Written by Gabor de Mooij (c) copyright 2010
  10. RedBean is DUAL Licensed BSD and GPLv2. You may choose the license that fits
  11. best for your project.
  12. BSD/GPLv2 License
  13. Redistribution and use in source and binary forms, with or without
  14. modification, are permitted provided that the following conditions are met:
  15. * Redistributions of source code must retain the above copyright
  16. notice, this list of conditions and the following disclaimer.
  17. * Redistributions in binary form must reproduce the above copyright
  18. notice, this list of conditions and the following disclaimer in the
  19. documentation and/or other materials provided with the distribution.
  20. * Neither the name of RedBeanPHP nor the
  21. names of its contributors may be used to endorse or promote products
  22. derived from this software without specific prior written permission.
  23. THIS SOFTWARE IS PROVIDED BY GABOR DE MOOIJ ''AS IS'' AND ANY
  24. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. DISCLAIMED. IN NO EVENT SHALL GABOR DE MOOIJ BE LIABLE FOR ANY
  27. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  30. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. RedBeanPHP is Written by Gabor de Mooij (G.J.G.T de Mooij) Copyright (c) 2010.
  34. GPLv2 LICENSE
  35. GNU GENERAL PUBLIC LICENSE
  36. Version 2, June 1991
  37. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  38. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  39. Everyone is permitted to copy and distribute verbatim copies
  40. of this license document, but changing it is not allowed.
  41. Preamble
  42. The licenses for most software are designed to take away your
  43. freedom to share and change it. By contrast, the GNU General Public
  44. License is intended to guarantee your freedom to share and change free
  45. software--to make sure the software is free for all its users. This
  46. General Public License applies to most of the Free Software
  47. Foundation's software and to any other program whose authors commit to
  48. using it. (Some other Free Software Foundation software is covered by
  49. the GNU Lesser General Public License instead.) You can apply it to
  50. your programs, too.
  51. When we speak of free software, we are referring to freedom, not
  52. price. Our General Public Licenses are designed to make sure that you
  53. have the freedom to distribute copies of free software (and charge for
  54. this service if you wish), that you receive source code or can get it
  55. if you want it, that you can change the software or use pieces of it
  56. in new free programs; and that you know you can do these things.
  57. To protect your rights, we need to make restrictions that forbid
  58. anyone to deny you these rights or to ask you to surrender the rights.
  59. These restrictions translate to certain responsibilities for you if you
  60. distribute copies of the software, or if you modify it.
  61. For example, if you distribute copies of such a program, whether
  62. gratis or for a fee, you must give the recipients all the rights that
  63. you have. You must make sure that they, too, receive or can get the
  64. source code. And you must show them these terms so they know their
  65. rights.
  66. We protect your rights with two steps: (1) copyright the software, and
  67. (2) offer you this license which gives you legal permission to copy,
  68. distribute and/or modify the software.
  69. Also, for each author's protection and ours, we want to make certain
  70. that everyone understands that there is no warranty for this free
  71. software. If the software is modified by someone else and passed on, we
  72. want its recipients to know that what they have is not the original, so
  73. that any problems introduced by others will not reflect on the original
  74. authors' reputations.
  75. Finally, any free program is threatened constantly by software
  76. patents. We wish to avoid the danger that redistributors of a free
  77. program will individually obtain patent licenses, in effect making the
  78. program proprietary. To prevent this, we have made it clear that any
  79. patent must be licensed for everyone's free use or not licensed at all.
  80. The precise terms and conditions for copying, distribution and
  81. modification follow.
  82. GNU GENERAL PUBLIC LICENSE
  83. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  84. 0. This License applies to any program or other work which contains
  85. a notice placed by the copyright holder saying it may be distributed
  86. under the terms of this General Public License. The "Program", below,
  87. refers to any such program or work, and a "work based on the Program"
  88. means either the Program or any derivative work under copyright law:
  89. that is to say, a work containing the Program or a portion of it,
  90. either verbatim or with modifications and/or translated into another
  91. language. (Hereinafter, translation is included without limitation in
  92. the term "modification".) Each licensee is addressed as "you".
  93. Activities other than copying, distribution and modification are not
  94. covered by this License; they are outside its scope. The act of
  95. running the Program is not restricted, and the output from the Program
  96. is covered only if its contents constitute a work based on the
  97. Program (independent of having been made by running the Program).
  98. Whether that is true depends on what the Program does.
  99. 1. You may copy and distribute verbatim copies of the Program's
  100. source code as you receive it, in any medium, provided that you
  101. conspicuously and appropriately publish on each copy an appropriate
  102. copyright notice and disclaimer of warranty; keep intact all the
  103. notices that refer to this License and to the absence of any warranty;
  104. and give any other recipients of the Program a copy of this License
  105. along with the Program.
  106. You may charge a fee for the physical act of transferring a copy, and
  107. you may at your option offer warranty protection in exchange for a fee.
  108. 2. You may modify your copy or copies of the Program or any portion
  109. of it, thus forming a work based on the Program, and copy and
  110. distribute such modifications or work under the terms of Section 1
  111. above, provided that you also meet all of these conditions:
  112. a) You must cause the modified files to carry prominent notices
  113. stating that you changed the files and the date of any change.
  114. b) You must cause any work that you distribute or publish, that in
  115. whole or in part contains or is derived from the Program or any
  116. part thereof, to be licensed as a whole at no charge to all third
  117. parties under the terms of this License.
  118. c) If the modified program normally reads commands interactively
  119. when run, you must cause it, when started running for such
  120. interactive use in the most ordinary way, to print or display an
  121. announcement including an appropriate copyright notice and a
  122. notice that there is no warranty (or else, saying that you provide
  123. a warranty) and that users may redistribute the program under
  124. these conditions, and telling the user how to view a copy of this
  125. License. (Exception: if the Program itself is interactive but
  126. does not normally print such an announcement, your work based on
  127. the Program is not required to print an announcement.)
  128. These requirements apply to the modified work as a whole. If
  129. identifiable sections of that work are not derived from the Program,
  130. and can be reasonably considered independent and separate works in
  131. themselves, then this License, and its terms, do not apply to those
  132. sections when you distribute them as separate works. But when you
  133. distribute the same sections as part of a whole which is a work based
  134. on the Program, the distribution of the whole must be on the terms of
  135. this License, whose permissions for other licensees extend to the
  136. entire whole, and thus to each and every part regardless of who wrote it.
  137. Thus, it is not the intent of this section to claim rights or contest
  138. your rights to work written entirely by you; rather, the intent is to
  139. exercise the right to control the distribution of derivative or
  140. collective works based on the Program.
  141. In addition, mere aggregation of another work not based on the Program
  142. with the Program (or with a work based on the Program) on a volume of
  143. a storage or distribution medium does not bring the other work under
  144. the scope of this License.
  145. 3. You may copy and distribute the Program (or a work based on it,
  146. under Section 2) in object code or executable form under the terms of
  147. Sections 1 and 2 above provided that you also do one of the following:
  148. a) Accompany it with the complete corresponding machine-readable
  149. source code, which must be distributed under the terms of Sections
  150. 1 and 2 above on a medium customarily used for software interchange; or,
  151. b) Accompany it with a written offer, valid for at least three
  152. years, to give any third party, for a charge no more than your
  153. cost of physically performing source distribution, a complete
  154. machine-readable copy of the corresponding source code, to be
  155. distributed under the terms of Sections 1 and 2 above on a medium
  156. customarily used for software interchange; or,
  157. c) Accompany it with the information you received as to the offer
  158. to distribute corresponding source code. (This alternative is
  159. allowed only for noncommercial distribution and only if you
  160. received the program in object code or executable form with such
  161. an offer, in accord with Subsection b above.)
  162. The source code for a work means the preferred form of the work for
  163. making modifications to it. For an executable work, complete source
  164. code means all the source code for all modules it contains, plus any
  165. associated interface definition files, plus the scripts used to
  166. control compilation and installation of the executable. However, as a
  167. special exception, the source code distributed need not include
  168. anything that is normally distributed (in either source or binary
  169. form) with the major components (compiler, kernel, and so on) of the
  170. operating system on which the executable runs, unless that component
  171. itself accompanies the executable.
  172. If distribution of executable or object code is made by offering
  173. access to copy from a designated place, then offering equivalent
  174. access to copy the source code from the same place counts as
  175. distribution of the source code, even though third parties are not
  176. compelled to copy the source along with the object code.
  177. 4. You may not copy, modify, sublicense, or distribute the Program
  178. except as expressly provided under this License. Any attempt
  179. otherwise to copy, modify, sublicense or distribute the Program is
  180. void, and will automatically terminate your rights under this License.
  181. However, parties who have received copies, or rights, from you under
  182. this License will not have their licenses terminated so long as such
  183. parties remain in full compliance.
  184. 5. You are not required to accept this License, since you have not
  185. signed it. However, nothing else grants you permission to modify or
  186. distribute the Program or its derivative works. These actions are
  187. prohibited by law if you do not accept this License. Therefore, by
  188. modifying or distributing the Program (or any work based on the
  189. Program), you indicate your acceptance of this License to do so, and
  190. all its terms and conditions for copying, distributing or modifying
  191. the Program or works based on it.
  192. 6. Each time you redistribute the Program (or any work based on the
  193. Program), the recipient automatically receives a license from the
  194. original licensor to copy, distribute or modify the Program subject to
  195. these terms and conditions. You may not impose any further
  196. restrictions on the recipients' exercise of the rights granted herein.
  197. You are not responsible for enforcing compliance by third parties to
  198. this License.
  199. 7. If, as a consequence of a court judgment or allegation of patent
  200. infringement or for any other reason (not limited to patent issues),
  201. conditions are imposed on you (whether by court order, agreement or
  202. otherwise) that contradict the conditions of this License, they do not
  203. excuse you from the conditions of this License. If you cannot
  204. distribute so as to satisfy simultaneously your obligations under this
  205. License and any other pertinent obligations, then as a consequence you
  206. may not distribute the Program at all. For example, if a patent
  207. license would not permit royalty-free redistribution of the Program by
  208. all those who receive copies directly or indirectly through you, then
  209. the only way you could satisfy both it and this License would be to
  210. refrain entirely from distribution of the Program.
  211. If any portion of this section is held invalid or unenforceable under
  212. any particular circumstance, the balance of the section is intended to
  213. apply and the section as a whole is intended to apply in other
  214. circumstances.
  215. It is not the purpose of this section to induce you to infringe any
  216. patents or other property right claims or to contest validity of any
  217. such claims; this section has the sole purpose of protecting the
  218. integrity of the free software distribution system, which is
  219. implemented by public license practices. Many people have made
  220. generous contributions to the wide range of software distributed
  221. through that system in reliance on consistent application of that
  222. system; it is up to the author/donor to decide if he or she is willing
  223. to distribute software through any other system and a licensee cannot
  224. impose that choice.
  225. This section is intended to make thoroughly clear what is believed to
  226. be a consequence of the rest of this License.
  227. 8. If the distribution and/or use of the Program is restricted in
  228. certain countries either by patents or by copyrighted interfaces, the
  229. original copyright holder who places the Program under this License
  230. may add an explicit geographical distribution limitation excluding
  231. those countries, so that distribution is permitted only in or among
  232. countries not thus excluded. In such case, this License incorporates
  233. the limitation as if written in the body of this License.
  234. 9. The Free Software Foundation may publish revised and/or new versions
  235. of the General Public License from time to time. Such new versions will
  236. be similar in spirit to the present version, but may differ in detail to
  237. address new problems or concerns.
  238. Each version is given a distinguishing version number. If the Program
  239. specifies a version number of this License which applies to it and "any
  240. later version", you have the option of following the terms and conditions
  241. either of that version or of any later version published by the Free
  242. Software Foundation. If the Program does not specify a version number of
  243. this License, you may choose any version ever published by the Free Software
  244. Foundation.
  245. 10. If you wish to incorporate parts of the Program into other free
  246. programs whose distribution conditions are different, write to the author
  247. to ask for permission. For software which is copyrighted by the Free
  248. Software Foundation, write to the Free Software Foundation; we sometimes
  249. make exceptions for this. Our decision will be guided by the two goals
  250. of preserving the free status of all derivatives of our free software and
  251. of promoting the sharing and reuse of software generally.
  252. NO WARRANTY
  253. 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  254. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
  255. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  256. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  257. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  258. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
  259. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
  260. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  261. REPAIR OR CORRECTION.
  262. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  263. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  264. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  265. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  266. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  267. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  268. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  269. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  270. POSSIBILITY OF SUCH DAMAGES.
  271. */
  272. /**
  273. * RedBean_ObjectDatabase
  274. * @file RedBean/RedBean_ObjectDatabase.php
  275. * @description RedBean simulates an object oriented database. This interface
  276. * describes the API for the object database. It is the
  277. * abstract core of RedBean describing its main functionality.
  278. * @author Gabor de Mooij
  279. * @license BSD
  280. *
  281. *
  282. * (c) G.J.G.T. (Gabor) de Mooij
  283. * This source file is subject to the BSD/GPLv2 License that is bundled
  284. * with this source code in the file license.txt.
  285. */
  286. interface RedBean_ObjectDatabase {
  287. /**
  288. * This interface describes how ANY Object Database should
  289. * behave.For detailed descriptions of RedBean specific implementation
  290. * see: RedBean_OODB.
  291. * An Object Database should be able to load a bean using a $type and $id.
  292. * The $type argument indicated what kind of bean you are looking for.
  293. * The $id argument specifies the primary key ID; which links the bean to
  294. * a (series) of record(s) in the database.
  295. *
  296. * @param string $type
  297. * @param integer $id
  298. *
  299. * @return RedBean_OODBBean $bean
  300. */
  301. public function load( $type, $id );
  302. /**
  303. * This interface describes how ANY Object Database should
  304. * behave.For detailed descriptions of RedBean specific implementation
  305. * see: RedBean_OODB.
  306. * An Object Database should be able to store a RedBean_OODBBean $bean.
  307. *
  308. * @param RedBean_OODBBean $bean
  309. *
  310. * @return integer $newid
  311. */
  312. public function store( RedBean_OODBBean $bean );
  313. /**
  314. * This interface describes how ANY Object Database should
  315. * behave.For detailed descriptions of RedBean specific implementation
  316. * see: RedBean_OODB.
  317. *
  318. * @param RedBean_OODBBean $bean
  319. */
  320. public function trash( RedBean_OODBBean $bean );
  321. /**
  322. * This interface describes how ANY Object Database should
  323. * behave.For detailed descriptions of RedBean specific implementation
  324. * see: RedBean_OODB.
  325. *
  326. * @param string $type
  327. * @param array $ids
  328. *
  329. * @return array $beans
  330. */
  331. public function batch( $type, $ids );
  332. /**
  333. * This interface describes how ANY Object Database should
  334. * behave.For detailed descriptions of RedBean specific implementation
  335. * see: RedBean_OODB.
  336. *
  337. * @param string $type
  338. *
  339. * @return RedBean_OODBBean $bean
  340. */
  341. public function dispense( $type );
  342. /**
  343. * This interface describes how ANY Object Database should
  344. * behave.For detailed descriptions of RedBean specific implementation
  345. * see: RedBean_OODB.
  346. *
  347. * @param string $type
  348. *
  349. * @return integer $numbeans
  350. */
  351. public function count( $type );
  352. /**
  353. * This interface describes how ANY Object Database should
  354. * behave.For detailed descriptions of RedBean specific implementation
  355. * see: RedBean_OODB.
  356. *
  357. * @param string $type
  358. *
  359. * @return mixed $undefined (impl. specific)
  360. */
  361. public function wipe( $type );
  362. /**
  363. * =====================================================
  364. * Note: that not all methods in OODB are mentioned here;
  365. * freeze(), isFrozen(), convertToBeans() etc. are extra
  366. * services provided by OODB but not required for the
  367. * Object Database interface to be implemented!
  368. *
  369. * If you are writing Hyper-portable code, please do
  370. * not rely on OODB specific methods...!
  371. * =====================================================
  372. *
  373. */
  374. }
  375. /**
  376. * RedBean Plugin
  377. * @file RedBean/Plugin.php
  378. * @description Marker interface for plugins.
  379. *
  380. * @author Gabor de Mooij
  381. * @license BSD
  382. *
  383. * (c) G.J.G.T. (Gabor) de Mooij
  384. * This source file is subject to the BSD/GPLv2 License that is bundled
  385. * with this source code in the file license.txt.
  386. */
  387. interface RedBean_Plugin {
  388. }
  389. /**
  390. * Interface for database drivers
  391. * @file RedBean/Driver.php
  392. * @description Describes the API for database classes
  393. * The Driver API conforms to the ADODB pseudo standard
  394. * for database drivers.
  395. * @author Gabor de Mooij
  396. * @license BSD
  397. *
  398. *
  399. * (c) G.J.G.T. (Gabor) de Mooij
  400. * This source file is subject to the BSD/GPLv2 License that is bundled
  401. * with this source code in the file license.txt.
  402. */
  403. interface RedBean_Driver {
  404. /**
  405. * Implements Singleton (or multiton)
  406. * Requests an instance of the database
  407. * Returns an instance of the driver Driver wrapper.
  408. *
  409. * @param string $dsn Database connection string
  410. * @param string $user DB account to be used
  411. * @param string $pass password
  412. * @param string $dbname name of the database you
  413. *
  414. * @return RedBean_Driver $driver driver wrapper instance
  415. */
  416. public static function getInstance( $host, $user, $pass, $dbname );
  417. /**
  418. * Runs a query and fetches results as a multi dimensional array.
  419. *
  420. * @param string $sql SQL to be executed
  421. *
  422. * @return array $results result
  423. */
  424. public function GetAll( $sql, $aValues=array() );
  425. /**
  426. * Runs a query and fetches results as a column.
  427. *
  428. * @param string $sql SQL Code to execute
  429. *
  430. * @return array $results Resultset
  431. */
  432. public function GetCol( $sql, $aValues=array() );
  433. /**
  434. * Runs a query an returns results as a single cell.
  435. *
  436. * @param string $sql SQL to execute
  437. *
  438. * @return mixed $cellvalue result cell
  439. */
  440. public function GetCell( $sql, $aValues=array() );
  441. /**
  442. * Runs a query and returns a flat array containing the values of
  443. * one row.
  444. *
  445. * @param string $sql SQL to execute
  446. *
  447. * @return array $row result row
  448. */
  449. public function GetRow( $sql, $aValues=array() );
  450. /**
  451. * Returns the error constant of the most
  452. * recent error.
  453. *
  454. * @return mixed $error error code
  455. */
  456. public function ErrorNo();
  457. /**
  458. * Returns the error message of the most recent
  459. * error.
  460. *
  461. * @return string $message error message
  462. */
  463. public function Errormsg();
  464. /**
  465. * Executes SQL code and allows key-value binding.
  466. * This function allows you to provide an array with values to bind
  467. * to query parameters. For instance you can bind values to question
  468. * marks in the query. Each value in the array corresponds to the
  469. * question mark in the query that matches the position of the value in the
  470. * array. You can also bind values using explicit keys, for instance
  471. * array(":key"=>123) will bind the integer 123 to the key :key in the
  472. * SQL. This method has no return value.
  473. *
  474. * @param string $sql SQL Code to execute
  475. * @param array $aValues Values to bind to SQL query
  476. *
  477. * @return void
  478. */
  479. public function Execute( $sql, $aValues=array() );
  480. /**
  481. * Escapes a string for use in SQL using the currently selected
  482. * driver driver.
  483. *
  484. * @param string $string string to be escaped
  485. *
  486. * @return string $string escaped string
  487. */
  488. public function Escape( $str );
  489. /**
  490. * Returns the latest insert ID if driver does support this
  491. * feature.
  492. *
  493. * @return integer $id primary key ID
  494. */
  495. public function GetInsertID();
  496. /**
  497. * Returns the number of rows affected by the most recent query
  498. * if the currently selected driver driver supports this feature.
  499. *
  500. * @return integer $numOfRows number of rows affected
  501. */
  502. public function Affected_Rows();
  503. /**
  504. * Toggles debug mode. In debug mode the driver will print all
  505. * SQL to the screen together with some information about the
  506. * results. All SQL code that passes through the driver will be
  507. * passes on to the screen for inspection.
  508. * This method has no return value.
  509. *
  510. * @param boolean $trueFalse turn on/off
  511. *
  512. * @return void
  513. */
  514. public function setDebugMode( $tf );
  515. /**
  516. * Returns a raw result resource from the underlying driver driver.
  517. *
  518. * @return Resource $driverResult driver result resource object
  519. */
  520. public function GetRaw();
  521. /**
  522. * Starts a transaction.
  523. * This method is part of the transaction mechanism of
  524. * RedBeanPHP. All queries in a transaction are executed together.
  525. * In case of an error all commands will be rolled back so none of the
  526. * SQL in the transaction will affect the DB. Using transactions is
  527. * considered best practice.
  528. * This method has no return value.
  529. *
  530. * @return void
  531. */
  532. public function CommitTrans();
  533. /**
  534. * Commits a transaction.
  535. * This method is part of the transaction mechanism of
  536. * RedBeanPHP. All queries in a transaction are executed together.
  537. * In case of an error all commands will be rolled back so none of the
  538. * SQL in the transaction will affect the DB. Using transactions is
  539. * considered best practice.
  540. * This method has no return value.
  541. *
  542. * @return void
  543. */
  544. public function StartTrans();
  545. /**
  546. * Rolls back a transaction.
  547. * This method is part of the transaction mechanism of
  548. * RedBeanPHP. All queries in a transaction are executed together.
  549. * In case of an error all commands will be rolled back so none of the
  550. * SQL in the transaction will affect the DB. Using transactions is
  551. * considered best practice.
  552. * This method has no return value.
  553. *
  554. * @return void
  555. */
  556. public function FailTrans();
  557. }
  558. /**
  559. * PDO Driver
  560. * @file RedBean/PDO.php
  561. * @description PDO Driver
  562. * This Driver implements the RedBean Driver API
  563. * @author Desfrenes
  564. * @license BSD
  565. *
  566. *
  567. * (c) Desfrenes & Gabor de Mooij
  568. * This source file is subject to the BSD/GPLv2 License that is bundled
  569. * with this source code in the file license.txt.
  570. *
  571. */
  572. class RedBean_Driver_PDO implements RedBean_Driver {
  573. /**
  574. * @var string
  575. * Contains database DSN for connecting to database.
  576. */
  577. private $dsn;
  578. /**
  579. * @var RedBean_Driver_PDO
  580. * Holds the instance of this class.
  581. */
  582. private static $instance;
  583. /**
  584. * @var boolean
  585. * Whether we are in debugging mode or not.
  586. */
  587. private $debug = false;
  588. /**
  589. * @var PDO
  590. * Holds the PDO instance.
  591. */
  592. private $pdo;
  593. /**
  594. * @var integer
  595. * Holds integer number of affected rows from latest query
  596. * if driver supports this feature.
  597. */
  598. private $affected_rows;
  599. /**
  600. * @var resource
  601. * Holds result resource.
  602. */
  603. private $rs;
  604. /**
  605. * @var boolean
  606. * Flag, indicates whether SQL execution has taken place.
  607. */
  608. private $exc =0;
  609. /**
  610. * @var array
  611. * Contains arbitrary connection data.
  612. *
  613. */
  614. private $connectInfo = array();
  615. /**
  616. * @var bool
  617. * Whether you want to use classic String Only binding -
  618. * backward compatibility.
  619. */
  620. public $flagUseStringOnlyBinding = false;
  621. /**
  622. *
  623. * @var boolean
  624. *
  625. * Whether we are currently connected or not.
  626. * This flag is being used to delay the connection until necessary.
  627. * Delaying connections is a good practice to speed up scripts that
  628. * don't need database connectivity but for some reason want to
  629. * init RedbeanPHP.
  630. */
  631. private $isConnected = false;
  632. /**
  633. * Returns an instance of the PDO Driver.
  634. *
  635. * @param string $dsn Database connection string
  636. * @param string $user DB account to be used
  637. * @param string $pass password
  638. * @param string $dbname name of the database you
  639. *
  640. * @return RedBean_Driver_PDO $pdo PDO wrapper instance
  641. */
  642. public static function getInstance($dsn, $user, $pass, $dbname) {
  643. if(is_null(self::$instance)) {
  644. self::$instance = new RedBean_Driver_PDO($dsn, $user, $pass);
  645. }
  646. return self::$instance;
  647. }
  648. /**
  649. * Constructor. You may either specify dsn, user and password or
  650. * just give an existing PDO connection.
  651. * Examples:
  652. * $driver = new RedBean_Driver_PDO($dsn, $user, $password);
  653. * $driver = new RedBean_Driver_PDO($existingConnection);
  654. *
  655. * @param string|PDO $dsn database connection string
  656. * @param string $user optional
  657. * @param string $pass optional
  658. *
  659. * @return void
  660. */
  661. public function __construct($dsn, $user = NULL, $pass = NULL) {
  662. if ($dsn instanceof PDO) {
  663. $this->pdo = $dsn;
  664. $this->isConnected = true;
  665. $this->pdo->setAttribute(1002, 'SET NAMES utf8');
  666. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  667. $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  668. $this->dsn = $this->getDatabaseType();
  669. } else {
  670. $this->dsn = $dsn;
  671. $this->connectInfo = array( "pass"=>$pass, "user"=>$user );
  672. }
  673. }
  674. /**
  675. * Establishes a connection to the database using PHP PDO
  676. * functionality. If a connection has already been established this
  677. * method will simply return directly. This method also turns on
  678. * UTF8 for the database and PDO-ERRMODE-EXCEPTION as well as
  679. * PDO-FETCH-ASSOC.
  680. *
  681. * @return void
  682. */
  683. public function connect() {
  684. if ($this->isConnected) return;
  685. $user = $this->connectInfo["user"];
  686. $pass = $this->connectInfo["pass"];
  687. $this->pdo = new PDO(
  688. $this->dsn,
  689. $user,
  690. $pass,
  691. array(1002 => 'SET NAMES utf8',
  692. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  693. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  694. )
  695. );
  696. $this->pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, TRUE);
  697. $this->isConnected = true;
  698. }
  699. /**
  700. * Runs a query and fetches results as a multi dimensional array.
  701. *
  702. * @param string $sql SQL to be executed
  703. *
  704. * @return array $results result
  705. */
  706. public function GetAll( $sql, $aValues=array() ) {
  707. $this->connect();
  708. $this->exc = 0;
  709. if ($this->debug) {
  710. echo "<HR>" . $sql.print_r($aValues,1);
  711. }
  712. try {
  713. if (strpos("pgsql",$this->dsn)===0) {
  714. $s = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true));
  715. }
  716. else {
  717. $s = $this->pdo->prepare($sql);
  718. }
  719. if ($this->flagUseStringOnlyBinding) {
  720. $s->execute($aValues);
  721. }
  722. else {
  723. foreach($aValues as $key=>&$value) {
  724. if (is_integer($key)) {
  725. if (ctype_digit(strval($value)) && $value < 2147483648) { $s->bindParam($key+1,$value,PDO::PARAM_INT); }
  726. else $s->bindParam($key+1,$value,PDO::PARAM_STR);
  727. }
  728. else {
  729. if (ctype_digit(strval($value)) && $value < 2147483648) $s->bindParam($key,$value,PDO::PARAM_INT);
  730. else $s->bindParam($key,$value,PDO::PARAM_STR);
  731. }
  732. }
  733. $s->execute();
  734. }
  735. if ($s->columnCount()) {
  736. $this->rs = $s->fetchAll();
  737. }
  738. else {
  739. $this->rs = null;
  740. }
  741. $rows = $this->rs;
  742. }catch(PDOException $e) {
  743. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  744. $x = new RedBean_Exception_SQL( $e->getMessage(), 0);
  745. }
  746. else {
  747. $x = new RedBean_Exception_SQL( $e->getMessage(), 0, $e );
  748. }
  749. $x->setSQLState( $e->getCode() );
  750. throw $x;
  751. }
  752. if(!$rows) {
  753. $rows = array();
  754. }
  755. if ($this->debug) {
  756. if (count($rows) > 0) {
  757. echo "<br><b style='color:green'>resultset: " . count($rows) . " rows</b>";
  758. }
  759. }
  760. return $rows;
  761. }
  762. /**
  763. * Runs a query and fetches results as a column.
  764. *
  765. * @param string $sql SQL Code to execute
  766. *
  767. * @return array $results Resultset
  768. */
  769. public function GetCol($sql, $aValues=array()) {
  770. $this->connect();
  771. $this->exc = 0;
  772. $rows = $this->GetAll($sql,$aValues);
  773. $cols = array();
  774. if ($rows && is_array($rows) && count($rows)>0) {
  775. foreach ($rows as $row) {
  776. $cols[] = array_shift($row);
  777. }
  778. }
  779. return $cols;
  780. }
  781. /**
  782. * Runs a query an returns results as a single cell.
  783. *
  784. * @param string $sql SQL to execute
  785. *
  786. * @return mixed $cellvalue result cell
  787. */
  788. public function GetCell($sql, $aValues=array()) {
  789. $this->connect();
  790. $this->exc = 0;
  791. $arr = $this->GetAll($sql,$aValues);
  792. $row1 = array_shift($arr);
  793. $col1 = array_shift($row1);
  794. return $col1;
  795. }
  796. /**
  797. * Runs a query and returns a flat array containing the values of
  798. * one row.
  799. *
  800. * @param string $sql SQL to execute
  801. *
  802. * @return array $row result row
  803. */
  804. public function GetRow($sql, $aValues=array()) {
  805. $this->connect();
  806. $this->exc = 0;
  807. $arr = $this->GetAll($sql, $aValues);
  808. return array_shift($arr);
  809. }
  810. /**
  811. * Returns the error constant of the most
  812. * recent error.
  813. *
  814. * @return mixed $error error code
  815. */
  816. public function ErrorNo() {
  817. $this->connect();
  818. if (!$this->exc) return 0;
  819. $infos = $this->pdo->errorInfo();
  820. return $infos[1];
  821. }
  822. /**
  823. * Returns the error message of the most recent
  824. * error.
  825. *
  826. * @return string $message error message
  827. */
  828. public function Errormsg() {
  829. $this->connect();
  830. if (!$this->exc) return "";
  831. $infos = $this->pdo->errorInfo();
  832. return $infos[2];
  833. }
  834. /**
  835. * Executes SQL code and allows key-value binding.
  836. * This function allows you to provide an array with values to bind
  837. * to query parameters. For instance you can bind values to question
  838. * marks in the query. Each value in the array corresponds to the
  839. * question mark in the query that matches the position of the value in the
  840. * array. You can also bind values using explicit keys, for instance
  841. * array(":key"=>123) will bind the integer 123 to the key :key in the
  842. * SQL. This method has no return value.
  843. *
  844. * @param string $sql SQL Code to execute
  845. * @param array $aValues Values to bind to SQL query
  846. *
  847. * @return void
  848. */
  849. public function Execute( $sql, $aValues=array() ) {
  850. $this->connect();
  851. $this->exc = 0;
  852. if ($this->debug) {
  853. echo "<HR>" . $sql.print_r($aValues,1);
  854. }
  855. try {
  856. if (strpos("pgsql",$this->dsn)===0) {
  857. $s = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true));
  858. }
  859. else {
  860. $s = $this->pdo->prepare($sql);
  861. }
  862. if ($this->flagUseStringOnlyBinding) {
  863. $s->execute($aValues);
  864. }
  865. else {
  866. foreach($aValues as $key=>&$value) {
  867. if (is_integer($key)) {
  868. if (ctype_digit(strval($value)) && $value < 2147483648) { $s->bindParam($key+1,$value,PDO::PARAM_INT); }
  869. else $s->bindParam($key+1,$value,PDO::PARAM_STR);
  870. }
  871. else {
  872. if (ctype_digit(strval($value)) && $value < 2147483648) $s->bindParam($key,$value,PDO::PARAM_INT);
  873. else $s->bindParam($key,$value,PDO::PARAM_STR);
  874. }
  875. }
  876. $s->execute();
  877. }
  878. $this->affected_rows=$s->rowCount();
  879. return $this->affected_rows;
  880. }
  881. catch(PDOException $e) {
  882. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  883. $x = new RedBean_Exception_SQL( $e->getMessage(), 0);
  884. }
  885. else {
  886. $x = new RedBean_Exception_SQL( $e->getMessage(), 0, $e );
  887. }
  888. $x->setSQLState( $e->getCode() );
  889. throw $x;
  890. }
  891. }
  892. /**
  893. * Escapes a string for use in SQL using the currently selected
  894. * PDO driver.
  895. *
  896. * @param string $string string to be escaped
  897. *
  898. * @return string $string escaped string
  899. */
  900. public function Escape( $str ) {
  901. $this->connect();
  902. return substr(substr($this->pdo->quote($str), 1), 0, -1);
  903. }
  904. /**
  905. * Returns the latest insert ID if driver does support this
  906. * feature.
  907. *
  908. * @return integer $id primary key ID
  909. */
  910. public function GetInsertID() {
  911. $this->connect();
  912. return (int) $this->pdo->lastInsertId();
  913. }
  914. /**
  915. * Returns the number of rows affected by the most recent query
  916. * if the currently selected PDO driver supports this feature.
  917. *
  918. * @return integer $numOfRows number of rows affected
  919. */
  920. public function Affected_Rows() {
  921. $this->connect();
  922. return (int) $this->affected_rows;
  923. }
  924. /**
  925. * Toggles debug mode. In debug mode the driver will print all
  926. * SQL to the screen together with some information about the
  927. * results. All SQL code that passes through the driver will be
  928. * passes on to the screen for inspection.
  929. * This method has no return value.
  930. *
  931. * @param boolean $trueFalse turn on/off
  932. *
  933. * @return void
  934. */
  935. public function setDebugMode( $tf ) {
  936. $this->connect();
  937. $this->debug = (bool)$tf;
  938. }
  939. /**
  940. * Returns a raw result resource from the underlying PDO driver.
  941. *
  942. * @return Resource $PDOResult PDO result resource object
  943. */
  944. public function GetRaw() {
  945. $this->connect();
  946. return $this->rs;
  947. }
  948. /**
  949. * Starts a transaction.
  950. * This method is part of the transaction mechanism of
  951. * RedBeanPHP. All queries in a transaction are executed together.
  952. * In case of an error all commands will be rolled back so none of the
  953. * SQL in the transaction will affect the DB. Using transactions is
  954. * considered best practice.
  955. * This method has no return value.
  956. *
  957. * @return void
  958. */
  959. public function StartTrans() {
  960. $this->connect();
  961. $this->pdo->beginTransaction();
  962. }
  963. /**
  964. * Commits a transaction.
  965. * This method is part of the transaction mechanism of
  966. * RedBeanPHP. All queries in a transaction are executed together.
  967. * In case of an error all commands will be rolled back so none of the
  968. * SQL in the transaction will affect the DB. Using transactions is
  969. * considered best practice.
  970. * This method has no return value.
  971. *
  972. * @return void
  973. */
  974. public function CommitTrans() {
  975. $this->connect();
  976. $this->pdo->commit();
  977. }
  978. /**
  979. * Rolls back a transaction.
  980. * This method is part of the transaction mechanism of
  981. * RedBeanPHP. All queries in a transaction are executed together.
  982. * In case of an error all commands will be rolled back so none of the
  983. * SQL in the transaction will affect the DB. Using transactions is
  984. * considered best practice.
  985. * This method has no return value.
  986. *
  987. * @return void
  988. */
  989. public function FailTrans() {
  990. $this->connect();
  991. $this->pdo->rollback();
  992. }
  993. /**
  994. * Returns the name of the database type/brand: i.e. mysql, db2 etc.
  995. *
  996. * @return string $typeName database identification
  997. */
  998. public function getDatabaseType() {
  999. $this->connect();
  1000. return $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
  1001. }
  1002. /**
  1003. * Returns the version number of the database.
  1004. *
  1005. * @return mixed $version version number of the database
  1006. */
  1007. public function getDatabaseVersion() {
  1008. $this->connect();
  1009. return $this->pdo->getAttribute(PDO::ATTR_CLIENT_VERSION);
  1010. }
  1011. /**
  1012. * Returns the underlying PHP PDO instance.
  1013. *
  1014. * @return PDO $pdo PDO instance used by PDO wrapper
  1015. */
  1016. public function getPDO() {
  1017. $this->connect();
  1018. return $this->pdo;
  1019. }
  1020. }
  1021. /**
  1022. * RedBean_OODBBean (Object Oriented DataBase Bean)
  1023. * @file RedBean/RedBean_OODBBean.php
  1024. * @description The Bean class used for passing information
  1025. * @author Gabor de Mooij
  1026. * @license BSD
  1027. *
  1028. *
  1029. * (c) G.J.G.T. (Gabor) de Mooij
  1030. * This source file is subject to the BSD/GPLv2 License that is bundled
  1031. * with this source code in the file license.txt.
  1032. */
  1033. class RedBean_OODBBean implements IteratorAggregate, ArrayAccess {
  1034. private $properties = array();
  1035. /**
  1036. * Meta Data storage. This is the internal property where all
  1037. * Meta information gets stored.
  1038. * @var array
  1039. */
  1040. private $__info = NULL;
  1041. public function getIterator() {
  1042. return new ArrayIterator($this->properties);
  1043. }
  1044. /**
  1045. * Imports all values in associative array $array. Every key is used
  1046. * for a property and every value will be assigned to the property
  1047. * identified by the key. So basically this method converts the
  1048. * associative array to a bean by loading the array. You can filter
  1049. * the values using the $selection parameter. If $selection is boolean
  1050. * false, no filtering will be applied. If $selection is an array
  1051. * only the properties specified (as values) in the $selection
  1052. * array will be taken into account. To skip a property, omit it from
  1053. * the $selection array. Also, instead of providing an array you may
  1054. * pass a comma separated list of property names. This method is
  1055. * chainable because it returns its own object.
  1056. * Imports data into bean
  1057. * @param array $array
  1058. * @param mixed $selection
  1059. * @param boolean $notrim
  1060. * @return RedBean_OODBBean $this
  1061. */
  1062. public function import( $arr, $selection=false, $notrim=false ) {
  1063. if (is_string($selection)) $selection = explode(",",$selection);
  1064. if (!$notrim && is_array($selection)) foreach($selection as $k=>$s){ $selection[$k]=trim($s); }
  1065. foreach($arr as $k=>$v) {
  1066. if ($k != "__info") {
  1067. if (!$selection || ($selection && in_array($k,$selection))) {
  1068. $this->$k = $v;
  1069. }
  1070. }
  1071. }
  1072. return $this;
  1073. }
  1074. /**
  1075. * Exports the bean as an array.
  1076. * This function exports the contents of a bean to an array and returns
  1077. * the resulting array. If $meta eq uals boolean TRUE, then the array will
  1078. * also contain the __info section containing the meta data inside the
  1079. * RedBean_OODBBean Bean object.
  1080. * @param boolean $meta
  1081. * @return array $arr
  1082. */
  1083. public function export($meta = false) {
  1084. $arr = array();
  1085. $arr = $this->properties;
  1086. if ($meta) $arr["__info"] = $this->__info;
  1087. return $arr;
  1088. }
  1089. /**
  1090. * Implements isset() function for use as an array.
  1091. * Returns whether bean has an element with key
  1092. * named $property. Returns TRUE if such an element exists
  1093. * and FALSE otherwise.
  1094. * @param string $property
  1095. * @return boolean $hasProperty
  1096. */
  1097. public function __isset( $property ) {
  1098. return (isset($this->properties[$property]));
  1099. }
  1100. /**
  1101. * Magic Getter. Gets the value for a specific property in the bean.
  1102. * If the property does not exist this getter will make sure no error
  1103. * occurs. This is because RedBean allows you to query (probe) for
  1104. * properties. If the property can not be found this method will
  1105. * return NULL instead.
  1106. * @param string $property
  1107. * @return mixed $value
  1108. */
  1109. public function __get( $property ) {
  1110. if (!isset($this->properties[$property])) return NULL;
  1111. return $this->properties[$property];
  1112. }
  1113. /**
  1114. * Magic Setter. Sets the value for a specific property.
  1115. * This setter acts as a hook for OODB to mark beans as tainted.
  1116. * The tainted meta property can be retrieved using getMeta("tainted").
  1117. * The tainted meta property indicates whether a bean has been modified and
  1118. * can be used in various caching mechanisms.
  1119. * @param string $property
  1120. * @param mixed $value
  1121. */
  1122. public function __set( $property, $value ) {
  1123. $this->setMeta("tainted",true);
  1124. if ($value===false) {
  1125. $value = "0";
  1126. }
  1127. if ($value===true) {
  1128. $value = "1";
  1129. }
  1130. $this->properties[$property] = $value;
  1131. }
  1132. /**
  1133. * Returns the value of a meta property. A meta property
  1134. * contains extra information about the bean object that will not
  1135. * get stored in the database. Meta information is used to instruct
  1136. * RedBean as well as other systems how to deal with the bean.
  1137. * For instance: $bean->setMeta("buildcommand.unique.0", array(
  1138. * "column1", "column2", "column3") );
  1139. * Will add a UNIQUE constaint for the bean on columns: column1, column2 and
  1140. * column 3.
  1141. * To access a Meta property we use a dot separated notation.
  1142. * If the property cannot be found this getter will return NULL instead.
  1143. * @param string $path
  1144. * @param mixed $default
  1145. * @return mixed $value
  1146. */
  1147. public function getMeta( $path, $default = NULL) {
  1148. return (isset($this->__info[$path])) ? $this->__info[$path] : $default;
  1149. }
  1150. /**
  1151. * Stores a value in the specified Meta information property. $value contains
  1152. * the value you want to store in the Meta section of the bean and $path
  1153. * specifies the dot separated path to the property. For instance "my.meta.property".
  1154. * If "my" and "meta" do not exist they will be created automatically.
  1155. * @param string $path
  1156. * @param mixed $value
  1157. */
  1158. public function setMeta( $path, $value ) {
  1159. $this->__info[$path] = $value;
  1160. }
  1161. /**
  1162. * Copies the meta information of the specified bean
  1163. * This is a convenience method to enable you to
  1164. * exchange meta information easily.
  1165. * @param RedBean_OODBBean $bean
  1166. * @return RedBean_OODBBean
  1167. */
  1168. public function copyMetaFrom( RedBean_OODBBean $bean ) {
  1169. $this->__info = $bean->__info;
  1170. return $this;
  1171. }
  1172. /**
  1173. * Sleep function fore serialize() call. This will be invoked if you
  1174. * perform a serialize() operation.
  1175. *
  1176. * @return mixed $array
  1177. */
  1178. public function __sleep() {
  1179. return array('properties','__info');
  1180. }
  1181. /**
  1182. * Reroutes a call to Model if exists. (new fuse)
  1183. * @param string $method
  1184. * @param array $args
  1185. * @return mixed $mixed
  1186. */
  1187. public function __call($method, $args) {
  1188. return null;
  1189. if (!isset($this->__info["model"])) {
  1190. $modelName = RedBean_ModelHelper::getModelName( $this->getMeta("type") );
  1191. if (!class_exists($modelName)) return null;
  1192. $obj = new $modelName();
  1193. $obj->loadBean($this);
  1194. $this->__info["model"] = $obj;
  1195. }
  1196. if (!method_exists($this->__info["model"],$method)) return null;
  1197. return call_user_func_array(array($this->__info["model"],$method), $args);
  1198. }
  1199. /**
  1200. * Implementation of __toString Method
  1201. * Routes call to Model.
  1202. * @return string $string
  1203. */
  1204. public function __toString() {
  1205. return $this->__call('__toString',array());
  1206. }
  1207. /**
  1208. * Implementation of Array Access Interface, you can access bean objects
  1209. * like an array.
  1210. * Call gets routed to __set.
  1211. *
  1212. * @param mixed $offset offset string
  1213. * @param mixed $value value
  1214. *
  1215. * @return void
  1216. */
  1217. public function offsetSet($offset, $value) {
  1218. $this->__set($offset, $value);
  1219. }
  1220. /**
  1221. * Implementation of Array Access Interface, you can access bean objects
  1222. * like an array.
  1223. *
  1224. * @param mixed $offset property
  1225. *
  1226. * @return
  1227. */
  1228. public function offsetExists($offset) {
  1229. return isset($this->properties[$offset]);
  1230. }
  1231. /**
  1232. * Implementation of Array Access Interface, you can access bean objects
  1233. * like an array.
  1234. * Unsets a value from the array/bean.
  1235. *
  1236. * @param mixed $offset property
  1237. *
  1238. * @return
  1239. */
  1240. public function offsetUnset($offset) {
  1241. unset($this->properties[$offset]);
  1242. }
  1243. /**
  1244. * Implementation of Array Access Interface, you can access bean objects
  1245. * like an array.
  1246. * Returns value of a property.
  1247. *
  1248. * @param mixed $offset property
  1249. *
  1250. * @return
  1251. */
  1252. public function offsetGet($offset) {
  1253. return $this->__get($offset);
  1254. }
  1255. }
  1256. /**
  1257. * Observable
  1258. * Base class for Observables
  1259. * @file RedBean/Observable.php
  1260. * @description Part of the observer pattern in RedBean
  1261. * @author Gabor de Mooij
  1262. * @license BSD
  1263. *
  1264. *
  1265. * (c) G.J.G.T. (Gabor) de Mooij
  1266. * This source file is subject to the BSD/GPLv2 License that is bundled
  1267. * with this source code in the file license.txt.
  1268. */
  1269. abstract class RedBean_Observable {
  1270. /**
  1271. *
  1272. * @var array
  1273. */
  1274. private $observers = array();
  1275. /**
  1276. * Adds a listener to this instance
  1277. * @param $eventname
  1278. * @param $observer
  1279. * @return unknown_type
  1280. */
  1281. public function addEventListener( $eventname, RedBean_Observer $observer ) {
  1282. if (!isset($this->observers[ $eventname ])) {
  1283. $this->observers[ $eventname ] = array();
  1284. }
  1285. foreach($this->observers[$eventname] as $o) if ($o==$observer) return;
  1286. $this->observers[ $eventname ][] = $observer;
  1287. }
  1288. /**
  1289. * Sends an event (signal) to the registered listeners
  1290. * @param $eventname
  1291. * @return unknown_type
  1292. */
  1293. public function signal( $eventname, $info ) {
  1294. if (!isset($this->observers[ $eventname ])) {
  1295. $this->observers[ $eventname ] = array();
  1296. }
  1297. foreach($this->observers[$eventname] as $observer) {
  1298. $observer->onEvent( $eventname, $info );
  1299. }
  1300. }
  1301. }
  1302. /**
  1303. * Observer
  1304. * @file RedBean/Observer.php
  1305. * @description Part of the observer pattern in RedBean
  1306. * @author Gabor de Mooij
  1307. * @license BSD
  1308. *
  1309. *
  1310. * (c) G.J.G.T. (Gabor) de Mooij
  1311. * This source file is subject to the BSD/GPLv2 License that is bundled
  1312. * with this source code in the file license.txt.
  1313. */
  1314. interface RedBean_Observer {
  1315. /**
  1316. * Part of the RedBean Observer Infrastructure.
  1317. * @param string $eventname
  1318. * @param RedBean_OODBBean $bean
  1319. */
  1320. public function onEvent( $eventname, $bean );
  1321. }
  1322. /**
  1323. * Adapter Interface
  1324. * @file RedBean/Adapter.php
  1325. * @description Describes the API for a RedBean Database Adapter.
  1326. * @author Gabor de Mooij
  1327. * @license BSD
  1328. *
  1329. * (c) G.J.G.T. (Gabor) de Mooij
  1330. * This source file is subject to the BSD/GPLv2 License that is bundled
  1331. * with this source code in the file license.txt.
  1332. *
  1333. */
  1334. interface RedBean_Adapter {
  1335. /**
  1336. * Returns the latest SQL statement
  1337. *
  1338. * @return string $SQLString SQLString
  1339. */
  1340. public function getSQL();
  1341. /**
  1342. * Escapes a value for usage in an SQL statement
  1343. *
  1344. * @param string $sqlvalue value
  1345. */
  1346. public function escape( $sqlvalue );
  1347. /**
  1348. * Executes an SQL Statement using an array of values to bind
  1349. * If $noevent is TRUE then this function will not signal its
  1350. * observers to notify about the SQL execution; this to prevent
  1351. * infinite recursion when using observers.
  1352. *
  1353. * @param string $sql SQL
  1354. * @param array $aValues values
  1355. * @param boolean $noevent no event firing
  1356. */
  1357. public function exec( $sql , $aValues=array(), $noevent=false);
  1358. /**
  1359. * Executes an SQL Query and returns a resultset.
  1360. * This method returns a multi dimensional resultset similar to getAll
  1361. * The values array can be used to bind values to the place holders in the
  1362. * SQL query.
  1363. *
  1364. * @param string $sql SQL
  1365. * @param array $aValues values
  1366. */
  1367. public function get( $sql, $aValues = array() );
  1368. /**
  1369. * Executes an SQL Query and returns a resultset.
  1370. * This method returns a single row (one array) resultset.
  1371. * The values array can be used to bind values to the place holders in the
  1372. * SQL query.
  1373. *
  1374. * @param string $sql SQL
  1375. * @param array $aValues values to bind
  1376. *
  1377. * @return array $aMultiDimArray row
  1378. */
  1379. public function getRow( $sql, $aValues = array() );
  1380. /**
  1381. * Executes an SQL Query and returns a resultset.
  1382. * This method returns a single column (one array) resultset.
  1383. * The values array can be used to bind values to the place holders in the
  1384. * SQL query.
  1385. *
  1386. * @param string $sql SQL
  1387. * @param array $aValues values to bind
  1388. *
  1389. * @return array $aSingleDimArray column
  1390. */

Large files files are truncated, but you can click here to view the full file