/** * Returns an instance of a Pfw_Db_Adapter * * @param $route the name of the route * @param $reuse * @return Pfw_Db_Adapter */ public static function factory($route = null, $reuse = true) { if (null === $route) { if (!isset(self::$default_router)) { Pfw_Loader::loadClass('Pfw_Db_Router_Standard'); self::$default_router = new Pfw_Db_Router_Standard(self::DEFAULT_ROUTE_NAME); } $route = self::$default_router->getWriteRoute(); } if (true == $reuse) { $reuse_key = self::_genCnxKey($route); if (isset(self::$_connections[$reuse_key])) { self::$_connections[$reuse_key]->isSharedCnx(true); return self::$_connections[$reuse_key]; } } $adapter_key = strtolower($route['adapter']); if (!isset(self::$_supported_adapters[$adapter_key])) { Pfw_Loader::loadClass('Pfw_Exception_Db'); throw new Pfw_Exception_Db("Adapter type {$route['adapter']} is unsupported"); } $class = 'Pfw_Db_Adapter_' . $route['adapter']; Pfw_Loader::loadClass($class); $instance = new $class($route); if (true == $reuse) { self::$_connections[$reuse_key] = $instance; self::$_connections[$reuse_key]->isSharedCnx(true); } else { $instance->isSharedCnx(false); } return $instance; }
/** * Sets up a session handler * @param string $class name of the handler class */ protected static function setupHandler($class) { Pfw_Loader::loadClass($class); $a = new $class(); session_set_save_handler(array($a, 'open'), array($a, 'close'), array($a, 'read'), array($a, 'write'), array($a, 'destroy'), array($a, 'gc')); self::$adapter = $a; }
/** * Initialize the request. If adapter is null, * Pfw_Request_Standard will be used. * * @param string $adapter the adapter class */ public static function init($adapter = null) { if (!is_null($adapter)) { self::$adapter = $adapter; } else { $adapter_class = "Pfw_Request_Standard"; Pfw_Loader::loadClass($adapter_class); self::$adapter = new $adapter_class(); } }
public function validate($save_method) { Pfw_Loader::loadClass('Pfw_Validate'); $pfv = new Pfw_Validate($this); if (Pfw_Model::SAVE_INSERT == $save_method) { $pfv->presence('name', "required!"); $pfv->presence('description', "required!"); } return $pfv->success(); }
function setupView() { $view = $this->getView(); $view->assign('controller', Pfw_Request::getParam('controller')); if (self::is_logged_in()) { # gettng user with profile photo Pfw_Loader::loadModel('User'); $user = User::Q()->where(array('this.id = %s', Pfw_Session::get('login_id')))->exec(); $logged_in_user = $user[0]; $view->assign('logged_in_user', $logged_in_user); $view->assign('is_logged_in', true); } }
protected function execStandardMapping($association, $desc, &$o, &$objects) { $count = $desc['count']; $class = $desc['class']; // the class of the thing we're associated with $fk = $desc['foreign_key']; $table = $desc['table']; $pks = array(); foreach ($objects as &$object) { if (Pfw_Model::ASSOC_MANY == $count) { $object->{$association} = array(); $my_key = $desc['my_key']; $pks[$object->{$my_key}] = $object; } elseif (Pfw_Model::ASSOC_ONE == $count) { $object->{$association} = null; $my_key = $desc['my_key']; $pks[$object->{$my_key}] = $object; } elseif (Pfw_Model::ASSOC_BELONGSTO == $count) { $object->{$association} = null; $pks[$object->{$fk}] = $object; } } Pfw_Loader::loadModel($class); $inst = new $class(); // empty instance of thing we're associated with $qo = $inst->Q($o->_getDb()); if (isset($desc['conditions'])) { $join_cond = str_replace($association, 'this', $desc['conditions']); $qo->where($join_cond); } if (Pfw_Model::ASSOC_MANY == $count or Pfw_Model::ASSOC_ONE == $count) { $associated_objs = $qo->whereIn("this.{$fk}", array_keys($pks))->exec(); } elseif (Pfw_Model::ASSOC_BELONGSTO == $count) { $owner_key = $desc['owner_key']; $associated_objs = $qo->whereIn("this.{$owner_key}", array_keys($pks))->exec(); $fk = $owner_key; } foreach ($associated_objs as $associated_obj) { $object = $pks[$associated_obj->{$fk}]; if (empty($object)) { continue; } if (Pfw_Model::ASSOC_MANY == $count) { array_push($object->{$association}, $associated_obj); } elseif (Pfw_Model::ASSOC_ONE == $count or Pfw_Model::ASSOC_BELONGSTO == $count) { $object->{$association} = $associated_obj; } } unset($pks); }
public static function initFromCache($cache_plugins) { foreach ($cache_plugins as $phase => $plugins) { foreach ($plugins as $plugin) { $class = $plugin['class']; Pfw_Loader::loadClass($class); $inst = new $class(); $i =& $inst; array_push(self::$plugins[$phase], array('inst' => $i, 'name' => $plugin['name'])); } } objp(self::$plugins); return true; }
function indexAction() { $view = $this->getView(); $view->assign('home', true); $view->assign('site_title', 'CalPalyn: Quaternary Paleoecology Lab'); // call project model $rows = Project::Q()->exec(); //Not the most efficient but since there are handful of users $users = User::Q()->exec(); foreach ($users as $user) { $u[$user->id] = array('email' => $user->email, 'first_name' => $user->first_name); } error_log(print_r($rows, true)); foreach ($rows as $row) { $d[] = array('id' => $row->id, 'name' => $row->name, 'user_info' => "<a class='tip' name='#'>" . $u[$row->created_by]['first_name'] . "<span>" . $u[$row->created_by]['email'] . "</span></a>", 'desc' => $row->description); $p[$row->id] = array('name' => $row->name, 'description' => $row->description); error_log(print_r($d, true)); } $view->assign('projects', $d); $view->assign('projects_info', $p); // Get list of taxons Pfw_Loader::loadModel('Taxon'); $txs = Taxon::Q()->exec(); //objp($txs); foreach ($txs as $t) { $taxons[$t->type] = $t->name; } //objp($taxons); error_log("Taxons are " . print_r($taxons, true)); $view->assign('taxons', $taxons); if (isset($_REQUEST['pid']) and !empty($_REQUEST['pid'])) { Pfw_Loader::loadModel('ProjectData'); $key_data = ProjectData::Q()->getKeyValuesForProject($_REQUEST['pid']); $chart_data = $key_data['chart_data']; foreach ($chart_data as $cdk => $cdv) { $depth_values = array_keys($cdv); $taxon_values = array_values($cdv); $chart_values[$cdk] = array('depth_min' => min($depth_values), 'depth_max' => max($depth_values), 'taxon_min' => min($taxon_values), 'taxon_max' => max($taxon_values), 'depths' => self::_extendedEncode($depth_values, max($depth_values)), 'taxon_values' => self::_extendedEncode($taxon_values, max($taxon_values))); } #objp($chart_values); $view->assign('chart_data', $chart_values); $view->assign('field_names', $key_data['field_names']); $view->assign('project_data', $key_data['data']); $view->assign('project_id', $_REQUEST['pid']); $view->assign('depths', $key_data['depths']); $view->assign('debug', print_r($view->get_template_vars(), true)); } $view->display(array('layout' => 'layouts/main.tpl', 'body' => 'home/index.tpl')); }
public function createInstance($template, $replacements) { if (!is_file($template) and !is_link($template)) { Pfw_Loader::loadClass('Pfw_Exception_Script'); throw new Pfw_Exception_Script(Pfw_Exception_Script::E_FS_NOT_FOUND, $template); } if (false === ($ctnt = file_get_contents($template))) { Pfw_Loader::loadClass('Pfw_Exception_Script'); throw new Pfw_Exception_Script(Pfw_Exception_Script::E_FS_UNKNOWN, "Failed to get the contents of file '{$template}'."); } foreach ($replacements as $name => $value) { $ctnt = preg_replace("/\\\$\\{{$name}\\}/", $value, $ctnt); } return $ctnt; }
public function validate($save_method) { Pfw_Loader::loadClass('Pfw_Validate'); $pfv = new Pfw_Validate($this); if (Pfw_Model::SAVE_INSERT == $save_method) { $pfv->presence('first_name', "required!"); $pfv->presence('last_name', "required!"); $pfv->presence('email', "required!"); $pfv->email('email', "Email is invalid!"); $pfv->presence('password', "required!"); if ($pfv->presence('email', "required!")) { $email_user = User::Q()->getByEmail($this->email)->exec(); if (!empty($email_user)) { $this->addError('email', "email is taken"); $pfv->fail(); } } } return $pfv->success(); }
/** * Returns an instance of the local cache driver * * @return Pfw_Cache|null instance of a Pfw_Cache object or null if none * is configured */ public static function getInstance() { if (!is_null(self::$instance)) { return self::$instance; } if (null == ($local_cache = Pfw_Config::get('local_cache'))) { return null; } if (is_array($local_cache)) { $class = $local_cache['class']; unset($local_cache['class']); $options = $local_cache; } else { $class = $local_cache; $options = array(); } Pfw_Loader::loadClass($class); self::$instance = new $class($options); return self::$instance; }
public function saveProjectData($data, $options) { // Create taxon map one time Pfw_Loader::loadModel('Taxon'); $field_names = $options['field_names']; $pid = $options['pid']; $num_cols = count($field_names); $taxons = Taxon::Q()->exec(); $taxon = array(); // strtolower $fields = array_filter($field_names, "strtolower"); $depth_index = array_search('depth', $fields); error_log("fields columns are " . print_r($fields, true)); foreach ($taxons as $t) { $taxon[$t->name] = $t->type; } error_log("taxons are " . print_r($taxon, true)); // foreach row in data array process individual columns foreach ($data as $d) { $sql = null; $depth = $d[$depth_index]; for ($i = 0; $i < $num_cols; $i++) { if ($i == $depth_index) { continue; } //error_log(print_r($d,true)); $tname = strtolower($fields[$i]); $null_val = "'NULL'"; $taxon_type = empty($taxon[$tname]) ? $null_val : $taxon[$tname]; $taxon_value = empty($d[$i]) ? $null_val : $d[$i]; error_log("TAXON VALUE IS {$taxon_value}"); $sql = "INSERT INTO project_data (project_id,depth,taxon_type, taxon_value) VALUES({$pid},{$depth},{$taxon_type},{$taxon_value});"; error_log($sql); Pfw_Db::factory()->query($sql); } // now fire the insert sql } }
* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Framework * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2008 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://www.picnicphp.com * @since 0.10 */ require '../../Pfw/UnitTest/PHPUnit/FwkTestCase.php'; Pfw_Loader::loadInclude('Pfw_Core_Base'); class Pfw_Core_Base_Inc_Test extends Pfw_UnitTest_PHPUnit_FwkTestCase { function testArrayToHash() { $arr = array('first' => 'one', 'second' => 'two', 'third', 'fourth'); $arr = array_to_hash($arr); $this->assertEquals(array('first' => 'one', 'second' => 'two', 'third' => 'third', 'fourth' => 'fourth'), $arr); } }
* distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Framework * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2008 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://www.picnicphp.com * @since 0.10 */ require '../../Pfw/UnitTest/PHPUnit/FwkTestCase.php'; Pfw_Loader::loadInclude('Pfw_Core_Base'); Pfw_Loader::loadClass('Pfw_Db_Adapter_Mysqli'); class Pfw_Db_Adapter_Mysqli_Test extends Pfw_UnitTest_PHPUnit_FwkTestCase { public function setup() { $this->createTables(); } public function tearDown() { $this->dropTables(); } public function testSprintfEsc() { $cnx = $this->getCnx(); $user = '******'; $welcome = $cnx->_sprintfEsc(array("hello %s", $user));
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Exception_System'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Exception_Model extends Pfw_Exception_System { }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Db_Select'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Db_Select_Mysqli extends Pfw_Db_Select { }
<?php ini_set('post_max_size', "11M"); ini_set('upload_max_filesize', "11M"); Pfw_Loader::loadClass('Prj_Controller_Standard'); Pfw_Loader::loadClass('Prj_Components_FileUploaderComponent'); Pfw_Loader::loadModel('Project'); class ProjectController extends Prj_Controller_Standard { public function __construct() { parent::__construct(); // do any view initialization in here error_log(">>>IN PROJECT CONTROLLER[" . __CLASS__ . "]"); $view = $this->getView(); $view->addCssLink('custom-theme/jquery-ui-1.8.10.custom.css'); $view->addJsLink('jquery-1.4.4.min.js'); $view->addJsLink('jquery.dataTables.min.js'); #$view->addJsLink('jquery.simplemodal-1.3.4.min.js'); //$view->addCssLink('jquery.fileupload-ui.css'); //$view->addJsLink('jquery.fileupload.js'); //$view->addJsLink('jquery.fileupload-ui.js'); $view->addJsLink('jquery.jqUploader.js'); $view->addJsLink('jquery.flash.js'); $view->addJsLink('custom-theme/jquery-ui-1.8.10.custom.min.js'); #$view->addJsLink('custom-theme/jquery-ui-form.custom.min.js'); } function indexAction() { $view = $this->getView(); $view->assign('site_title', 'CalPalyn: Quaternary Paleoecology Lab Project Listing Page');
<?php Pfw_Loader::loadClass('Prj_Controller_Standard'); class ErrorController extends Prj_Controller_Standard { function fourohfourAction() { header("HTTP/1.0 404 Not Found", true, 404); $view = $this->getView(); $view->display(array('layout' => 'layouts/main.tpl', 'body' => 'error/404.tpl')); } }
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Db'); Pfw_Loader::loadClass('Pfw_Db_Expr'); Pfw_Loader::loadClass('Pfw_Db_Router_Standard'); Pfw_Loader::loadClass('Pfw_Cache_Dist'); Pfw_Loader::loadClass('Pfw_Session_Handler'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Session_DistCacheDb implements Pfw_Session_Handler { const CACHE_PREFIX = "_pfw_sess_"; const CACHE_TTL = 600; const DEFAULT_DB_TABLE = 'sessions'; protected $config; protected $sessions = array();
* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Framework * @package Pfw * @author Sean Sitter <sean@picnicphp> * @copyright 2008 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://www.picnicphp.com * @since 0.10 */ require '../../Pfw/UnitTest/PHPUnit/FwkTestCase.php'; Pfw_Loader::loadClass('Pfw_Script_Template'); class Pfw_Script_Template_Test extends Pfw_UnitTest_PHPUnit_FwkTestCase { function getTplDir() { return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'misc' . DIRECTORY_SEPARATOR; } function testReplace() { $tpl_file = $this->getTplDir() . "script_test_template.txt"; $ctnt = Pfw_Script_Template::createInstance($tpl_file, array('TEST_VAR' => 'FUN $STUFF')); $this->assertEquals('This is my new FUN $STUFF', $ctnt); } function testMissingFile() { $tpl_file = $this->getTplDir() . "junk.txt";
$front = Pfw_Controller_Front::getInstance(); $front->getRouter()->setRoutes($_pfw_routes)->setModules($_pfw_modules); $four_oh_four = false; try { $front->dispatch(); } catch (Pfw_Exception_System $e) { $e->emitLog(); if ($_ENVIRONMENT == "development") { objp($e); exit; } $four_oh_four = true; } catch (Pfw_Exception_User $e) { $e->emitLog(); if ($_ENVIRONMENT == "development") { objp($e); exit; } $four_oh_four = true; } catch (Exception $e) { if ($_ENVIRONMENT == "development") { objp($e); exit; } $four_oh_four = true; } if ($four_oh_four) { Pfw_Loader::loadController('ErrorController'); $c = new ErrorController(); $c->fourohfourAction(); }
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Framework * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2008 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://www.picnicphp.com * @since 0.10 */ require '../../Pfw/UnitTest/PHPUnit/FwkTestCase.php'; Pfw_Loader::loadClass('Pfw_Controller_Router_Standard'); Pfw_Loader::loadClass('Pfw_Config'); Pfw_Loader::loadClass('Pfw_Cache_Local'); class Pfw_Cache_Local_Test extends Pfw_UnitTest_PHPUnit_FwkTestCase { public function setup() { Pfw_Config::setConfig(array('local_cache' => 'Pfw_Cache_Stub')); } public function tearDown() { Pfw_Cache_Local::_reset(); } public function testSetGet() { Pfw_Cache_Local::set('test', 'ok'); $this->assertEquals('ok', Pfw_Cache_Local::get('test')); }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Exception_Script'); Pfw_Loader::loadClass('Pfw_Script_Message'); Pfw_Loader::loadClass('Pfw_Script_CLI'); Pfw_Loader::loadClass('Pfw_Exception_Script'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Script_FileSystem { public static function exists($path) { if (file_exists($path)) { return true; }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadFile('Smarty/Smarty_Compiler.class.php'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Smarty_Compiler extends Smarty_Compiler { function _compile_tag($template_tag) { /* Split tag into two three parts: command, command modifiers and the arguments. */ if (!preg_match('~^(?:(' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\\/?' . $this->_reg_obj_regexp . '|\\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*)) (?:\\s+(.*))?$ ~xs', $template_tag, $match)) { $this->_syntax_error("unrecognized tag: {$template_tag}", E_USER_ERROR, __FILE__, __LINE__); }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Exception_Script'); Pfw_Loader::loadClass('Pfw_Script_FileSystem'); Pfw_Loader::loadClass('Pfw_Db_Migrate'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Script_Migration { protected $migration_file; public function __construct($migration_file, $dry_run = false) { if (true == $dry_run) { Pfw_Db_Migrate::$_dry_run = true; }
/** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 */ function smarty_function_form_field($params, &$smarty) { list($args, $attrs) = $smarty->_filterAttrs($params); $obj_prop = $args['prop']; if ($args['confirmation']) { $obj_prop = $obj_prop . "_confirm"; } if (array_key_exists('value', $args)) { $attrs['value'] = $args['value']; } if (array_key_exists('index', $args)) { $args['for'] = $args['for'] . "[{$args['index']}]"; } $obj_path = $args['for']; if (empty($obj_path)) { error_log("missing required template variable name 'for'"); } // get the value of the property $var = ""; if (false === strpos($obj_path, '[')) { $var = $obj_path; $obj = $smarty->get_template_vars($var); } else { preg_match("/^([\\w]+)\\[?/", $obj_path, $matches); $var = $matches[1]; $obj_path = str_replace($var, 'obj', $obj_path); // not sure if this is needed $obj_path = preg_replace('/\\[(?!\')/', '[\'', $obj_path); $obj_path = preg_replace('/\\](?<!\')/', '\']', $obj_path); $e = "return \${$obj_path};"; $obj = $smarty->get_template_vars($var); $obj = eval($e); } if (empty($obj)) { Pfw_Loader::loadClass('Pfw_Form'); $obj = new Pfw_Form(); } $element = "input"; $content = null; if (!isset($args['type'])) { if (method_exists($obj, 'getSchema')) { $schema = $obj->getSchema(); switch ($schema[$obj_prop]['type']) { case Pfw_Db_Adapter::TYPE_CHARACTER: case Pfw_Db_Adapter::TYPE_INTEGER: case Pfw_Db_Adapter::TYPE_FLOAT: case Pfw_Db_Adapter::TYPE_ENUM: $attrs['type'] = "text"; if (!isset($attrs['size'])) { $attrs['size'] = 3; } break; case Pfw_Db_Adapter::TYPE_TEXT: $attrs['type'] = "textarea"; break; case Pfw_Db_Adapter::TYPE_VARCHAR: $attrs['type'] = "text"; if (!isset($attrs['size'])) { $attrs['size'] = 32; } break; case Pfw_Db_Adapter::TYPE_DATE: break; case Pfw_Db_Adapter::TYPE_TIME: break; } } else { $attrs['type'] = "text"; } } else { $attrs['type'] = $args['type']; } if (!isset($attrs['value']) and isset($obj->{$obj_prop})) { if (is_object($obj)) { $attrs['value'] = $obj->{$obj_prop}; } elseif (is_array($obj) and isset($obj[$obj_prop])) { $attrs['value'] = $obj[$obj_prop]; } } if (!array_key_exists('value', $attrs)) { if (array_key_exists('default_value', $args)) { $attrs['value'] = $args['default_value']; } else { $attrs['value'] = ""; } } if ($attrs['type'] == 'checkbox') { if ($attrs['value']) { $attrs['checked'] = "1"; } $attrs['value'] = 1; } /* elseif (empty($attrs['value'])) { $attrs['value'] = ""; } */ if ('textarea' == $attrs['type']) { $element = "textarea"; $content = $attrs['value']; unset($attrs['type']); unset($attrs['value']); } elseif ('select' == $attrs['type']) { $element = "select"; $content = "\n"; if (empty($params['options'])) { $params['options'] = array(); } $options = array_to_hash($params['options']); foreach ($options as $label => $value) { $label = empty($label) ? $value : $label; $selected = ""; if ($value == $attrs['value']) { $selected = " selected"; } $value = urlencode($value); $content .= "<option value=\"{$value}\"{$selected}>{$label}</option>\n"; } unset($attrs['type']); unset($attrs['value']); } $attrs['name'] = "{$args['for']}[{$obj_prop}]"; $err_list = ""; if (is_object($obj) and method_exists($obj, 'hasErrors') and $obj->hasErrors($args['prop']) and false !== $args['highlight_errors']) { if (isset($attrs['class'])) { $attrs['class'] = "{$attrs['class']} pfw-error"; } else { $attrs['class'] = "pfw-error"; } } $field = $smarty->_generateElement($element, $attrs, $content); return $err_list . $field; }
protected function mapAction($controller_class, $action) { try { Pfw_Loader::loadController($controller_class); } catch (Pfw_Exception_Loader $e) { throw new Pfw_Exception_NotFound("Could not find controller class '{$controller_class}'. " . "Please ensure class '{$controller_class}.php' exists within the 'controllers' directory", Pfw_Exception_NotFound::ROUTE_MISSING_ACTION); } $inst = new $controller_class(); $methods_key = '_pfw_' . strtolower($controller_class) . '_methods'; if (false === ($methods = Pfw_Cache_Local::get($methods_key))) { $methods = get_class_methods($inst); Pfw_Cache_Local::set($methods_key, $methods); } $methods = get_class_methods($inst); $n_action = $this->normalizeAct($action); foreach ($methods as $method) { if (!$this->isAlpha($method[0])) { continue; } if (self::ACTION_SUFFIX == substr($method, -6)) { $act_part = substr($method, 0, strlen($method) - 6); if ($n_action == $this->normalizeAct($act_part)) { return array('controller' => $inst, 'controller_class' => $controller_class, 'method' => $method); } } } return array(); }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Db_Router'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Db_Router_Fixed extends Pfw_Db_Router { protected $route; public function __construct($route) { $this->route = $route; } public function getReadRoute() { return $this->route;
* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Framework * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2008 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://www.picnicphp.com * @since 0.10 */ require '../../Pfw/UnitTest/PHPUnit/FwkTestCase.php'; Pfw_Loader::loadClass('Pfw_Controller_Router_Standard'); class Pfw_Controller_Router_Standard_Test extends Pfw_UnitTest_PHPUnit_FwkTestCase { function testBasic() { $pfw_routes = array('basic_route' => array('/:controller/:action', array('action' => 'index'))); $router = new Pfw_Controller_Router_Standard(); $router->setRoutes($pfw_routes); $route = $router->route('/home/stuff'); $this->assertEquals(array('controller' => 'home', 'action' => 'stuff'), $route); $this->assertEquals('basic_route', $router->getSuccessRouteName()); } function testBasicConds() { $pfw_routes = array('basic_route' => array('/:controller/:action/:var', null, array('var' => 'me'))); $router = new Pfw_Controller_Router_Standard();
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * @package Pfw * @author Sean Sitter <*****@*****.**> * @copyright 2010 The Picnic PHP Framework * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @link http://www.picnicphp.com * @since 0.10 * @filesource */ Pfw_Loader::loadClass('Pfw_Exception_User'); /** * Short description for file * * Long description for file (if any)... * * @category Framework * @package Pfw */ class Pfw_Exception_NotFound extends Pfw_Exception_User { const ROUTE_MISSING_CONTROLLER = 0; const ROUTE_MISSING_ACTION = 1; }