Page MenuHomePhabricator

No OneTemporary

diff --git a/storage/database/ObjectFactoryInterface.php b/storage/database/ObjectFactoryInterface.php
index afdedbd..7916236 100644
--- a/storage/database/ObjectFactoryInterface.php
+++ b/storage/database/ObjectFactoryInterface.php
@@ -1,156 +1,158 @@
<?php namespace spitfire\storage\database;
use spitfire\model\Field as LogicalField;
/*
* The MIT License
*
* Copyright 2016 César de la Cal Bretschneider <cesar@magic3w.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* The database object factory is a class that allows a driver to provide SF's
* ORM with all the required bits and pieces to operate. Usually a driver needs
* to provide it's own Table, Query, Field... objects that implement / extend
* the behavior required for the ORM to work.
*
* Historically, a query would provide only the pieces it needed, as well as the
* table would. But for consistency, and to avoid generating classes that only
* need to extend in order to provide factories we're merging those behaviors
* in this single factory.
*/
interface ObjectFactoryInterface
{
/**
* Creates a relation. These wrap the typical record operations on a table
* into a separate layer.
*
* @param Table $table
*
* @return Relation
*/
function makeRelation(Table$table);
/**
* Creates a table layout to generate an appropriate schema for the DBMS to
* store the data.
*
* @param Table $table
*
* @return LayoutInterface The layout for the table
*/
function makeLayout(Table$table);
/**
* Creates a new On The Fly Schema. These allow the system to interact with a
* database that was not modeled after Spitfire's models or that was not
* reverse engineered previously.
*
* @param string $modelname
*
* @return Table Instance of the table class the driver wants the system to use
* @todo Rename to generateSchema
*/
function getOTFSchema(DB$db, $modelname);
/**
* Creates an instance of the Database field compatible with the current
* DBMS. As opposed to the Logical fields, physical fields do not accept
* complex values, just basic types that any DBMS can handle.
*
* @param Field $field
* @param string $name
* @param Field $references
*
* @return Field Field
* @todo Rename to makeField
*/
function getFieldInstance(LogicalField$field, $name, Field$references = null);
/**
* Creates a new restriction. This combines a query with a field and a value
* which allows to create the queries that we need to construct in order to
* retrieve data.
*
* @param string $query
* @param QueryField $field
* @param mixed $value
* @param string|null $operator
*
* @return Restriction|CompositeRestriction
* @todo Rename to makeRestriction
*/
function restrictionInstance($query, QueryField$field, $value, $operator = null);
/**
*
* @todo This is supposed to take a RestrictionGroup
* @param Query $query
* @param LogicalField $field
* @param mixed $value
* @param string $operator
*/
function restrictionCompositeInstance(Query$query, LogicalField$field = null, $value, $operator);
/**
* Creates a restriction group. This allows to associate several restrictions
* with each other to create more complicated queries when writing.
*
* @param RestrictionGroup $parent
* @param int $type
* @return RestrictionGroup A restriction group
*/
function restrictionGroupInstance(RestrictionGroup$parent = null, $type = RestrictionGroup::TYPE_OR);
/**
* Creates a new query. A query is created with a table to provide information
* where the data should be retrieved some and some information on the fields
* that we want it to provide.
*
* @param Table|Relation $table
*
* @return Query
* @todo Rename to makeQuery
*/
function queryInstance($table);
/**
* These objects connect a field with a query, providing an aliased name for
* the field when necessary.
*
+ * @todo The second parameter should only accept physical and not logical fields
+ *
* @param QueryTable $queryTable
* @param Field|QueryField $field
* @return QueryField
*/
function queryFieldInstance(QueryTable$queryTable, $field);
/**
* These objects connect a field with a query, providing an aliased name for
* the field when necessary.
*
* @param QueryTable|Table $table
* @return QueryTable
*/
function queryTableInstance($table);
}
diff --git a/storage/database/QueryField.php b/storage/database/QueryField.php
index 27708b0..0e10fb6 100644
--- a/storage/database/QueryField.php
+++ b/storage/database/QueryField.php
@@ -1,69 +1,104 @@
<?php namespace spitfire\storage\database;
use spitfire\model\Field as Logical;
/**
* The query field object is a component that allows a Query to wrap a field and
* connect it to itself. This is important for the DBA since it allows the app
* to establish connections between the different queries when assembling SQL
* or similar.
*
* When a query is connected to a field, you may use this to establish relationships
* and create complex queries that can properly be joined.
*
* @author César de la Cal Bretschneider <cesar@magic3w.com>
* @abstract
*/
abstract class QueryField
{
/**
* The actual database field. Note that this field is
*
* @var Logical
*/
private $field;
/**
*
* @var QueryTable
*/
private $table;
public function __construct(QueryTable$table, $field) {
$this->table = $table;
$this->field = $field;
}
- public function getQueryTable() {
+ /**
+ * Returns the parent Table for this field.
+ *
+ * @return QueryTable
+ */
+ public function getQueryTable() : QueryTable {
return $this->table;
}
/**
- * @return Logical
+ * Returns the source field for this object.
+ *
+ * @return Logical|Field
*/
public function getField() {
return $this->field;
}
- public function getPhysical() {
+ /**
+ *
+ *
+ * @return bool
+ */
+ public function isLogical() : bool {
+ return $this->field instanceof Logical;
+ }
+
+ /**
+ * Returns an array of fields that compose the physical components of the
+ * field. This method automatically converts the fields to QueryField so they
+ * can be used again.
+ *
+ * @return Field[]
+ */
+ public function getPhysical() : array {
/*
* Get the object factory for the current DB connection. It is then used
* to create physical copies of logical fields.
*/
$of = $this->table->getTable()->getDb()->getObjectFactory();
- if ($this->field instanceof Logical) {
+ if ($this->isLogical()) {
$fields = $this->field->getPhysical();
foreach ($fields as &$field) {
$field = $of->queryFieldInstance($this->table, $field);
}
return $fields;
}
return [$of->queryFieldInstance($this->table, $this->field)];
}
+ /**
+ * Many drivers use this objects to generate "object identifiers", strings that
+ * indicate what field in which table is being adressed. So we're forcing driver
+ * vendors to implement the __toString method to achieve the most consistent
+ * result possible.
+ *
+ * This may not be the case for your driver. In this event, just return a string
+ * that may be used for debugging and create an additional method for your
+ * driver.
+ *
+ * @return string
+ */
abstract public function __toString();
}

File Metadata

Mime Type
text/x-diff
Expires
Apr 12 2021, 5:52 AM (9 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1923
Default Alt Text
(8 KB)

Event Timeline