Browse Source

Entities

master
therselman 7 years ago
parent
commit
0ce2b02217
  1. 10
      src/ORM/ComplexMap.php
  2. 12
      src/ORM/Entity.php
  3. 64
      src/ORM/EntityMap.php
  4. 16
      src/ORM/Mapper.php
  5. 2
      src/ORM/SimpleMap.php

10
src/ORM/ComplexMap.php

@ -2,7 +2,15 @@ @@ -2,7 +2,15 @@
namespace Twister\ORM;
abstract class ComplexMap
/**
* Used to map a single entity to multiple-tables with complex joins or dynamic fields ... why?
*
*
*/
abstract class ComplexMap extends EntityMap
{
protected $joins; // optional
protected $fields;
}

12
src/ORM/Entity.php

@ -15,8 +15,6 @@ abstract class Entity implements \JsonSerializable @@ -15,8 +15,6 @@ abstract class Entity implements \JsonSerializable
{
protected $properties;
protected $map; // AKA config; can include relations, factory methods for relations etc.
function __construct(array $properties = null)
{
$this->properties =& $properties;
@ -30,12 +28,8 @@ abstract class Entity implements \JsonSerializable @@ -30,12 +28,8 @@ abstract class Entity implements \JsonSerializable
*/
function __get($name)
{
if ( ! isset($this->properties[$name]))
{
if (isset($this->map[$name]))
{
}
if ( ! isset($this->properties[$name])) {
$this->load($name);
}
return $this->properties[$name];
}
@ -68,4 +62,6 @@ abstract class Entity implements \JsonSerializable @@ -68,4 +62,6 @@ abstract class Entity implements \JsonSerializable
{
return $this->properties;
}
abstract function load(...$args);
}

64
src/ORM/EntityMap.php

@ -5,29 +5,85 @@ namespace Twister\ORM; @@ -5,29 +5,85 @@ namespace Twister\ORM;
/**
* `Maps` persistent storage to Entities
*
* `Since Eloquent models are query builders, you should review all of the methods available on the query builder. You may use any of these methods in your Eloquent queries.`
*
* Actions and responsibilities include:
* Implements field Mutators and
* Implements field Mutators and Accessors
* Relationships & Joins
* List of Fields
* Table aliases
* Virtual / dynamic field names
*
*
*
* @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html
*
* @Column
* type: Name of the Doctrine Type which is converted between PHP and Database representation.
* name: By default the property name is used for the database column name also, however the ‘name’ attribute allows you to determine the column name.
* length: Used by the “string” type to determine its maximum length in the database. Doctrine does not validate the length of a string values for you.
* precision: The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum number of digits that are stored for the values.
* scale: The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number of digits to the right of the decimal point and must not be greater than precision.
* unique: Boolean value to determine if the value of the column should be unique across all rows of the underlying entities table.
* nullable: Determines if NULL values allowed for this column. If not specified, default value is false.
* options: Array of additional options:
* default: The default value to set for the column if no value is supplied.
* unsigned: Boolean value to determine if the column should be capable of representing only non-negative integers (applies only for integer column and might not be supported by all vendors).
* fixed: Boolean value to determine if the specified length of a string column should be fixed or varying (applies only for string/binary column and might not be supported by all vendors).
* comment: The comment of the column in the schema (might not be supported by all vendors).
* collation: The collation of the column (only supported by Drizzle, Mysql, PostgreSQL>=9.1, Sqlite and SQLServer).
* check: Adds a check constraint type to the column (might not be supported by all vendors).
* columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. However you should make careful use of this feature and the consequences. SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”.
* Additionally you should remember that the “type” attribute still handles the conversion between PHP and Database values. If you use this attribute on a column that is used for joins between tables you should also take a look at @JoinColumn.
*
*
* derivedFrom: AKA dynamic field!
*
*
*
*/
abstract class EntityMap
{
protected $fields;
protected $from;
protected $tables;
protected $joins; // optional
protected $properties;
protected $aliases;
protected $relationships;
protected $indexes;
protected $constraints; // AKA validations?
// abstract private __get__();
function __construct(array $properties = null)
/**
* The current globally available instance (if any).
*
* @var static
*/
protected static $instance = null;
protected function __construct()
{
}
/**
* Get the globally available instance
*
* @return static
*/
public static function getInstance()
{
$this->properties =& $properties;
if ( ! isset(static::$instance))
{
static::$instance = new static();
}
return static::$instance;
}
}
/*
'aliases' => [ 'w' => 'worlds',
@ -64,7 +120,7 @@ abstract class EntityMap @@ -64,7 +120,7 @@ abstract class EntityMap
''
];
public $virtualFields = [ 'age' => 'TIMESTAMPDIFF(YEAR, u.dob, NOW()) as age',
public $virtualFields = [ 'age' => 'TIMESTAMPDIFF(YEAR, u.dob, NOW()) as age', // AKA derived fields
'style_name' => 'STYLIZE_NAME(u.fname, u.alias, u.lname, 0, 0)'
];

16
src/ORM/Mapper.php

@ -17,16 +17,14 @@ namespace Twister\ORM; @@ -17,16 +17,14 @@ namespace Twister\ORM;
*/
abstract class Mapper
{
protected $fields;
protected $from;
protected $joins; // optional
protected $properties;
protected $aliases;
protected $relationships;
function __construct(array $properties = null)
const ONE_TO_MANY = 0;
const ONE_TO_ONE = 1;
const MANY_TO_MANY = 2;
const EMBEDED = 3;
function __construct()
{
$this->properties =& $properties;
}
abstract function select();

2
src/ORM/SimpleMap.php

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
namespace Twister\ORM;
abstract class SimpleMap
abstract class SimpleMap extends EntityMap
{
function __construct()
{

Loading…
Cancel
Save