/tanora.org/www/framework/system/field.php
PHP | 144 lines | 76 code | 19 blank | 49 comment | 2 complexity | 08fa70dd1ef34d7381bbf96d0c326dca MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
- <?php
- /**
- * File: framework/system/field.php
- *
- * Defines the base class for all Field objects in an ORM.
- */
- abstract class Field {
-
- protected $db;
-
- protected $column;
- protected $input;
-
- protected $name;
- protected $value;
- protected $primary;
- protected $unique;
-
- /**
- * Sets the database member variable and the column definition.
- */
- function __construct(&$db) {
- $this->db = $db;
- }
-
- /**
- * Sets the name member variable.
- */
- public function set_name($value) {
- $this->name = $value;
- $this->input->set_name($this->name);
- }
-
- /**
- * Gets the name member variable.
- */
- public function get_name() {
- return $this->name;
- }
-
- /**
- * Returns a boolean of whether or not the value has been set.
- */
- public function has_value() {
- return isset($this->value);
- }
-
- /**
- * Returns the value.
- */
- public function get_value() {
- return $this->value;
- }
-
- /**
- * Returns the column.
- */
- public function get_column() {
- return $this->column;
- }
-
- /**
- * Sets the value.
- */
- public function set_value($value) {
- $this->value = $value;
- }
-
- /**
- * Sets the primary member variable.
- */
- public function set_primary() {
- $this->primary = TRUE;
- }
-
- /**
- * Returns true if set_primary member variable is TRUE.
- */
- public function is_primary() {
- return $this->primary === TRUE;
- }
-
- /**
- * Sets the unique member variable.
- */
- public function set_unique() {
- $this->unique = TRUE;
- }
-
- /**
- * Returns true if set_unique member variable is TRUE.
- */
- public function is_unique() {
- return $this->unique === TRUE;
- }
-
- /**
- * Returns a reference the input member variable.
- */
- public function get_input() {
- return $this->input;
- }
-
- /**
- * Sets the input value and returns the reference.
- */
- protected function _input($type) {
- // array of files in order of priority they should be checked
- $paths = array(INPUT_PATH, FRAMEWORK_PATH.'inputs/');
- require_once(FRAMEWORK_PATH.'system/input.php');
- foreach($paths as $dir) {
- $file = $dir.strtolower($type).'input.php';
- if(file_exists($file)) {
- require_once($file);
- $class = $type.'Input';
- $this->input = new $class();
- return $this->input;
- }
- }
- Framework::error('Cannot load input: '.$type);
- }
-
- /**
- * Sets the column member variable.
- */
- protected function _column($type) {
- // array of files in order of priority they should be checked
- $paths = array(COLUMN_PATH, FRAMEWORK_PATH.'columns/');
- require_once(FRAMEWORK_PATH.'system/column.php');
- foreach($paths as $dir) {
- $file = $dir.strtolower($type).'column.php';
- if(file_exists($file)) {
- require_once($file);
- $class = $type.'Column';
- $this->column = new $class($this->db, $this);
- return $this->column;
- }
- }
- Framework::error('Cannot load column: '.$type);
- }
- }
- ?>