[Solar-svn] Revision 2923
pmjones at solarphp.com
pmjones at solarphp.com
Thu Nov 1 08:28:14 CDT 2007
multiple followup changes
* Replaced references to Solar_Sql_Table with Solar_Sql_Model
* Now using Solar_Registry::get('request') instead of Solar::factory('Solar_Request'), esp. in comments
* Removed unused and outdated Solar_Form_Load_Table and _Xml
* Updated comments
Modified: trunk/Solar/Cache/Adapter.php
===================================================================
--- trunk/Solar/Cache/Adapter.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/Solar/Cache/Adapter.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -238,7 +238,7 @@
*
* {{code: php
* // create a request object
- * $request = Solar::factory('Solar_Request');
+ * $request = Solar_Registry::get('request');
*
* // get the request URI as an identifier
* $id = $request->server('REQUEST_URI');
@@ -264,7 +264,7 @@
*
* {{code: php
* // create a request object
- * $request = Solar::factory('Solar_Request');
+ * $request = Solar_Registry::get('request');
*
* // create an entry ID named for the current URI
* $id = $request->server('REQUEST_URI');
@@ -309,7 +309,7 @@
*
* {{code: php
* // create a request object
- * $request = Solar::factory('Solar_Request');
+ * $request = Solar_Registry::get('request');
*
* // create an entry ID named for the current URI
* $id = $request->server('REQUEST_URI');
Modified: trunk/Solar/Form/Load/Model.php
===================================================================
--- trunk/Solar/Form/Load/Model.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/Solar/Form/Load/Model.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -28,9 +28,9 @@
/**
*
- * Loads Solar_Form elements based on Solar_Sql_Table columns.
+ * Loads Solar_Form elements based on Solar_Sql_Model columns.
*
- * @param Solar_Sql_Table $model Load form elements from this model object.
+ * @param Solar_Sql_Model $model Load form elements from this model object.
*
* @param array $list Which model columns to load as form elements, default '*'.
*
Deleted: trunk/Solar/Form/Load/Table.php
===================================================================
--- trunk/Solar/Form/Load/Table.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/Solar/Form/Load/Table.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -1,276 +0,0 @@
-<?php
-/**
- *
- * Class for loading form definitions from Solar_Sql_Table columns.
- *
- * @category Solar
- *
- * @package Solar_Form
- *
- * @author Paul M. Jones <pmjones at solarphp.com>
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- * @version $Id$
- *
- */
-
-/**
- *
- * Class for loading form definitions from Solar_Sql_Table columns.
- *
- * @category Solar
- *
- * @package Solar_Form
- *
- */
-class Solar_Form_Load_Table extends Solar_Base {
-
- /**
- *
- * Loads Solar_Form elements based on Solar_Sql_Table columns.
- *
- * @param Solar_Sql_Table $table Load form elements from this table object.
- *
- * @param array $list Which table columns to load as form elements, default '*'.
- *
- * @param string $array_name Load the table columns as elements of this
- * array-name within the form.
- *
- * @return Solar_Form|false Solar_Form object, or boolean false on error.
- *
- */
- public function fetch($table, $list = '*', $array_name = null)
- {
- if (! $table instanceof Solar_Sql_Table) {
- throw $this->_exception('ERR_NOT_TABLE_OBJECT');
- }
-
- // if not specified, set the array_name to the table name
- if (empty($array_name)) {
- $array_name = $table->name;
- }
-
- // all columns known by the table
- $all_cols = array_keys($table->col);
-
- // special condition: if looking for '*' columns,
- // get the list of all the table columns.
- if ($list == '*') {
- $list = $all_cols;
- } else {
- settype($list, 'array');
- }
-
- // default row values
- $default = $table->fetchNew();
-
- // loop through the list of requested columns and collect elements
- $elements = array();
- foreach ($list as $name => $info) {
-
- // if $name is integer, $info is just a column name,
- // and there is no added element info.
- if (is_int($name)) {
- $name = $info;
- $info = array();
- } else {
- settype($info, 'array');
- }
-
- // is the column name in the table?
- if (! in_array($name, $all_cols)) {
- continue;
- }
-
- // initial set of element info based on the table column
- $base = array(
- 'name' => $array_name . '[' . $name . ']',
- 'type' => null,
- 'label' => $table->locale(strtoupper("LABEL_$name")),
- 'descr' => $table->locale(strtoupper("DESCR_$name")),
- 'value' => $default[$name],
- 'require' => $table->col[$name]['require'],
- 'disable' => $table->col[$name]['primary'],
- 'options' => array(),
- 'attribs' => array(),
- 'invalid' => array(),
- 'valid' => array(),
- );
- $info = array_merge($base, $info);
-
- if (! empty($table->col[$name]['valid'])) {
- // get the validation array...
- $info['valid'][0] = $table->col[$name]['valid'];
- // ... and translate the message using the
- // **table** locale strings.
- $info['valid'][0][1] = $table->locale($info['valid'][0][1]);
- }
-
- // make primary keys hidden and disabled
- if ($table->col[$name]['primary']) {
- $info['type'] = 'hidden';
- $info['disable'] = true;
- }
-
- // pick an element type based on the column type
- if (empty($info['type'])) {
- // base the element type on the column type.
- switch ($table->col[$name]['type']) {
-
- case 'bool':
- $info['type'] = 'checkbox';
- break;
-
- case 'clob':
- $info['type'] = 'textarea';
- break;
-
- case 'date':
- case 'time':
- case 'timestamp':
- $info['type'] = $table->col[$name]['type'];
- break;
-
- default:
-
- // make 'id' and '*_id' columns hidden
- if ($name == 'id' || substr($name, -3) == '_id') {
- $info['type'] = 'hidden';
- }
-
- // if there is a validation for 'inList' or 'inKeys',
- // make this a select element.
- foreach ($info['valid'] as $v) {
- if ($v[0] == 'inKeys' || $v[0] == 'inList') {
- $info['type'] = 'select';
- break;
- }
- }
-
- // if type is still empty, make it text.
- if (empty($info['type'])) {
- $info['type'] = 'text';
- }
- break;
- }
- }
-
- // add validations based on column type, but only if
- // not hidden or disabled
- if ($info['type'] != 'hidden' && ! $info['disable'] &&
- empty($info['valid'])) {
-
- $method = null;
-
- switch ($table->col[$name]['type']) {
- case 'date':
- $method = 'isoDate';
- break;
- case 'time':
- $method = 'isoTime';
- break;
- case 'timestamp':
- $method = 'isoTimestamp';
- break;
- case 'smallint':
- case 'int':
- case 'bigint':
- $method = 'integer';
- break;
- }
-
- if ($method) {
- $code = 'VALID_' . strtoupper($method);
- $info['valid'] = array(
- array(
- $method,
- $this->locale($code),
- Solar_Valid::OR_BLANK
- )
- );
- }
- }
-
- // set up options for checkboxes if none specified
- if ($info['type'] == 'checkbox' && empty($info['options'])) {
- // look for 'inKeys' or 'inList' validation.
- foreach ($info['valid'] as $v) {
- if ($v[0] == 'inKeys' || $v[0] == 'inList') {
- $info['options'] = $this->_autoOptions($v[0], $v[2]);
- break;
- }
- }
- // if still empty, set to 1,0
- if (empty($info['options'])) {
- $info['options'] = array(1,0);
- }
- }
-
- // set up options for select and radio if none specified
- if (($info['type'] == 'select' || $info['type'] == 'radio') &&
- empty($info['options'])) {
- // look for 'inKeys' or 'inList' validation.
- foreach ($info['valid'] as $v) {
- if ($v[0] == 'inKeys' || $v[0] == 'inList') {
- $info['options'] = $this->_autoOptions($v[0], $v[2]);
- break;
- }
- }
- }
-
- // for text elements, set up maxlength if none specified
- if ($info['type'] == 'text' &&
- empty($info['attribs']['maxlength']) &&
- $table->col[$name]['size'] > 0) {
- /** @todo Add +1 or +2 to 'size' for numeric types? */
- $info['attribs']['maxlength'] = $table->col[$name]['size'];
- }
-
- // if no label specified, set up based on element name
- if (empty($info['label'])) {
- $info['label'] = $info['name'];
- }
-
- // keep the element
- $elements[$info['name']] = $info;
- }
-
- $result = array(
- 'attribs' => array(),
- 'elements' => $elements
- );
-
- return $result;
- }
-
- /**
- *
- * Builds an option list from inKeys and inList validations.
- *
- * The 'inKeys' options are not changed.
- *
- * The 'inList' options are generally sequential, so the label
- * and the value are made to be identical (based on the label).
- *
- * @param string $type The validation type, 'inKeys' or 'inList'.
- *
- * @param array $opts The options provided by the validation.
- *
- * @return array
- *
- */
- protected function _autoOptions($type, $opts)
- {
- // leave the labels and values alone
- if ($type == 'inKeys') {
- return $opts;
- }
-
- // make the form display the labels as both labels and values
- if ($type == 'inList') {
- $vals = array_values($opts);
- return array_combine($vals, $vals);
- }
- }
-}
Deleted: trunk/Solar/Form/Load/Xml.php
===================================================================
--- trunk/Solar/Form/Load/Xml.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/Solar/Form/Load/Xml.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -1,243 +0,0 @@
-<?php
-/**
- *
- * Class for loading Solar_Form definitions from a SimpleXML file.
- *
- * @category Solar
- *
- * @package Solar_Form
- *
- * @author Matthew Weier O'Phinney <mweierophinney at gmail.com>
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- * @version $Id$
- *
- */
-
-/**
- *
- * Class for loading Solar_Form definitions from a SimpleXML file.
- *
- * @category Solar
- *
- * @package Solar_Form
- *
- */
-class Solar_Form_Load_Xml extends Solar_Base {
-
- /**
- *
- * Array of element attribute names.
- *
- * Used by Solar_Form_Load_Xml::fetch() to get element attributes.
- *
- * @var array
- *
- */
- protected $_elementAttribs = array(
- 'type',
- 'value',
- 'require',
- 'disable',
- );
-
- /**
- *
- * Loads a Solar_Form definition from an XML file.
- *
- * Loads a Solar_Form definition from an XML file using PHP5's
- * SimpleXML functions.
- *
- * The location of a form definition file is required.
- *
- * If an error occurs, a Solar error is generated and returned.
- *
- * @param string $filename Path to form definition file.
- *
- * @return object|false Solar_Form object, boolean false on error.
- *
- */
- public function fetch($filename)
- {
- $args = func_get_args();
- $filename = array_shift($args);
- $param = array_shift($args);
-
- if (! file_exists($filename)) {
- throw $this->_exception('ERR_FILE_NOT_FOUND');
- }
-
- // load the XML file data
- $xml = simplexml_load_file($filename);
- if (false === $xml) {
- // return an error here
- throw $this->_exception(
- 'ERR_BAD_XML',
- array(
- 'filename' => $filename
- )
- );
- }
-
- // loop through the XML file data elements
- $elements = array();
- foreach ($xml->element as $element) {
-
- // skip empty element names ...
- if (empty($element['name'])) {
- continue;
- }
-
- // ... otherwise, get element name and initialize array
- $name = (string) $element['name'];
- $elementInfo = array();
-
- // Get element attributes
- foreach ($this->elementAttribs as $attrib) {
- if (isset($element[$attrib])) {
- $elementInfo[$attrib] = (string) $element[$attrib];
- }
- }
-
- // Get element label/description, if present
- if (!empty($element->label)) {
- $elementInfo['label'] = (string) $element->label;
- }
- if (!empty($element->descr)) {
- $elementInfo['descr'] = (string) $element->descr;
- }
-
- // Get attribs and options
- foreach (array('attribs', 'options') as $opt) {
- if (!empty($element->$opt)) {
- $info = array();
- foreach ($element->$opt as $data) {
- if (empty($data['name'])) continue;
- $info[(string) $data['name']] = (string) $data;
- }
- $elementInfo[$opt] = $info;
- }
- }
-
- // Get element filters
- if (! empty($element->filters)) {
- $filters = array();
- foreach ($element->filters->filter as $filter) {
-
- if (empty($filter['method'])) continue;
- $method = (string) $filter['method'];
-
- $params = array();
- $tmpFilter = array($method);
-
- // Were any arguments passed?
- if (!empty($filter->params)) {
- $params = $this->getParams($filter->params->param);
- }
-
- // Add arguments to filter array
- foreach ($params as $param) {
- array_push($tmpFilter, $param);
- }
-
- // Add filter to element
- $filters[] = $tmpFilter;
- }
- $elementInfo['filter'] = $filters;
- }
-
- // Get element validations
- if (! empty($element->validate)) {
- $validate = array();
- foreach ($element->validate->rule as $rule) {
- if (empty($rule['method'])) {
- continue;
- }
-
- $method = (string) $rule['method'];
- $message = '';
- if (! empty($rule->message)) {
- $message = (string) $rule->message;
- }
-
- $params = array();
- $tmpRule = array($method, $message);
-
- // Were any arguments passed?
- if (! empty($rule->args)) {
- $params = $this->getParams($rule->args->arg);
- }
-
- // Add arguments to validation array
- foreach ($params as $param) {
- array_push($tmpRule, $param);
- }
-
- // Add validation to element
- $validate[] = $tmpRule;
- }
-
- $elementInfo['valid'] = $validate;
- }
-
- // Add element to formElements array
- $elements[$name] = $elementInfo;
- }
-
- return array(
- 'attribs' => array(),
- 'elements' => $elements
- );
- }
-
- /**
- *
- * Gets parameters for a filter or validation rule.
- *
- * @param array $params The array of parameters.
- *
- * @return array
- *
- */
- protected function _getParams($params)
- {
- $final = array();
- foreach ($params as $param) {
- // Get the parameter type
- // 'array' means it's an array; anything other than
- // 'array' will be ignored.
- $argType = 'args';
- if (!empty($param['type'])) {
- $argType = (string) $param['type'];
- }
-
- if ('array' == $argType) {
- if (empty($param->item)) {
- $param = (array) $param;
- } else {
- $items = array();
- foreach ($param->item as $item) {
- $value = (string) $item;
- if (empty($item['name'])) {
- $items[] = $value;
- } else {
- $items[(string) $item['name']] = $value;
- }
- }
- $param = $items;
- }
- } else {
- if (empty($param->item)) {
- $param = (string) $param;
- } else {
- $param = (string) $param->item;
- }
- }
-
- array_push($final, $param);
- }
-
- return $final;
- }
-}
Modified: trunk/Solar/Sql/Select.php
===================================================================
--- trunk/Solar/Sql/Select.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/Solar/Sql/Select.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -250,7 +250,7 @@
*
* Adds a FROM table and columns to the query.
*
- * @param string|object $spec If a Solar_Sql_Table object, the table
+ * @param string|object $spec If a Solar_Sql_Model object, the table
* to select from; if a string, the table name to select from.
*
* @param array|string $cols The columns to select from this table.
@@ -261,14 +261,14 @@
public function from($spec, $cols = null)
{
// the $spec may be a table object, or a string.
- if ($spec instanceof Solar_Sql_Table) {
+ if ($spec instanceof Solar_Sql_Model) {
// get the table name
- $name = $spec->name;
+ $name = $spec->table_name;
// add all columns?
if ($cols == '*') {
- $cols = array_keys($spec->col);
+ $cols = array_keys($spec->table_cols);
}
} else {
@@ -339,7 +339,7 @@
*
* Adds a JOIN table and columns to the query.
*
- * @param string|object $spec If a Solar_Sql_Table object, the table
+ * @param string|object $spec If a Solar_Sql_Model object, the table
* to join to; if a string, the table name to join to.
*
* @param string $cond Join on this condition.
@@ -359,7 +359,7 @@
*
* Adds a LEFT JOIN table and columns to the query.
*
- * @param string|object $spec If a Solar_Sql_Table object, the table
+ * @param string|object $spec If a Solar_Sql_Model object, the table
* to join to; if a string, the table name to join to.
*
* @param string $cond Join on this condition.
@@ -379,7 +379,7 @@
*
* Adds an INNER JOIN table and columns to the query.
*
- * @param string|object $spec If a Solar_Sql_Table object, the table
+ * @param string|object $spec If a Solar_Sql_Model object, the table
* to join to; if a string, the table name to join to.
*
* @param string $cond Join on this condition.
@@ -1223,7 +1223,7 @@
* @param string $type The type of join; empty for a plain JOIN, or
* "LEFT", "INNER", etc.
*
- * @param string|Solar_Sql_Table $spec If a Solar_Sql_Table
+ * @param string|Solar_Sql_Model $spec If a Solar_Sql_Model
* object, the table to join to; if a string, the table name to
* join to.
*
@@ -1238,14 +1238,14 @@
protected function _join($type, $spec, $cond, $cols)
{
// the $spec may be a table object, or a string.
- if ($spec instanceof Solar_Sql_Table) {
+ if ($spec instanceof Solar_Sql_Model) {
// get the table name
- $name = $spec->name;
+ $name = $spec->table_name;
// add all columns?
if ($cols == '*') {
- $cols = array_keys($spec->col);
+ $cols = array_keys($spec->table_cols);
}
} else {
Modified: trunk/tests/Solar/Controller/PageTest.php
===================================================================
--- trunk/tests/Solar/Controller/PageTest.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/tests/Solar/Controller/PageTest.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -34,7 +34,7 @@
Solar::start('config.inc.php');
// load the request environment
- $this->_request = Solar::factory('Solar_Request');
+ $this->_request = Solar_Registry::get('request');
// set up the example page controller object
$this->_page = Solar::factory('Solar_Example_Controller_Page');
Modified: trunk/tests/Solar/RequestTest.php
===================================================================
--- trunk/tests/Solar/RequestTest.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/tests/Solar/RequestTest.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -17,7 +17,7 @@
protected function _getRequest()
{
- return Solar::factory('Solar_Request');
+ return Solar_Registry::get('request');
}
public function testCanInstantiateThroughFactory()
Modified: trunk/tests/Solar/UriTest.php
===================================================================
--- trunk/tests/Solar/UriTest.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/tests/Solar/UriTest.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -15,7 +15,7 @@
// when running from the command line, these elements are empty.
// add them so that web-like testing can occur.
- $this->_request = Solar::factory('Solar_Request');
+ $this->_request = Solar_Registry::get('request');
$this->_request->server['HTTP_HOST'] = 'example.com';
$this->_request->server['SCRIPT_NAME'] = '/path/to/index.php';
$this->_request->server['PATH_INFO'] = '/appname/action';
Modified: trunk/tests/Test/Solar/Request.php
===================================================================
--- trunk/tests/Test/Solar/Request.php 2007-10-27 12:31:35 UTC (rev 2922)
+++ trunk/tests/Test/Solar/Request.php 2007-11-01 13:28:14 UTC (rev 2923)
@@ -79,7 +79,7 @@
*/
public function test__construct()
{
- $obj = Solar::factory('Solar_Request');
+ $obj = Solar_Registry::get('request');
$this->assertInstance($obj, 'Solar_Request');
}
More information about the Solar-svn
mailing list