morrisonlevi

interface.ActiveRecord.php

Oct 3rd, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. /**
  3.  * I wish all ActiveRecord implementations used an interface.  I'm proposing
  4.  * this one with the intent that I can improve it, then submit changes to
  5.  * conform a few existing ActiveRecord implementations that would allow them
  6.  * to coincide.  
  7.  *
  8.  * Email me if you'd like to help with this, or if you have an idea.
  9.  *
  10.  * @author Levi Morrison <[email protected]>
  11.  */
  12. interface ActiveRecord {
  13.    
  14.     /**
  15.      * Creates a new object.  When save is called, it will insert a new record
  16.      * into the database.
  17.      * @param array $properties An associative array mapping column names to values.
  18.      */
  19.     public function __construct(array $properties = null);
  20.    
  21.     /**
  22.      * Retrieves an object with the given $id from the database. The returned
  23.      * object implements this interface.
  24.      * @param int $id
  25.      * @return ActiveRecord An object from the database, or null.
  26.      */
  27.     public static function find($id);
  28.    
  29.     /**
  30.      * Deletes the record associated with $id from the database.
  31.      * @param int $id
  32.      * @return boolean Returns true if the data was successfully deleted.
  33.      */
  34.     public static function delete($id);
  35.    
  36.     /**
  37.      * Saves the object to the database.  If the object is a new instance, it
  38.      * inserts a new record into the database.  Calling farther saves on that
  39.      * object results in updates, not new inserts.
  40.      * If the object is not a new instance, it simply saves the data to the
  41.      * database. For safety, you cannot update the primary key.
  42.      *
  43.      * A well-built implementation will only update or insert information that
  44.      * is changed by the user, not all of the fields belonging to the class.
  45.      *
  46.      * @return boolean Returns true if the save was successful.
  47.      */
  48.     public function save();
  49.    
  50. }
  51. ?>
  52.  
Advertisement
Add Comment
Please, Sign In to add comment