protected function doFixture($method) { $name = $this->name === "" ? get_class($this) : $this->name; $fixtureDir = RUN_BASE . DS . "tests" . DS . "fixture"; $reflection = new Sabel_Reflection_Class($name); $annotation = $reflection->getAnnotation("fixture"); if (isset($annotation[0])) { if ($method === "downFixture") { $annotation[0] = array_reverse($annotation[0]); } try { foreach ($annotation[0] as $fixtureName) { Sabel::fileUsing($fixtureDir . DS . $this->getFixturePath($fixtureName), true); $className = "Fixture_" . $fixtureName; $fixture = new $className(); $fixture->{$method}(); } } catch (Exception $e) { if ($reflection->hasMethod($method . "Exception")) { $reflection->getMethod($method . "Exception")->invoke(null, $e); } else { throw $e; } } } }
public function getProcessors() { $baseDir = RUN_BASE . DS . LIB_DIR_NAME . DS . "processor" . DS; foreach (array_keys($this->processors) as $name) { Sabel::fileUsing($baseDir . ucfirst($name) . ".php", true); } return $this->processors; }
public static function suite() { $bus = new Sabel_Bus(); Sabel::fileUsing(dirname(__FILE__) . DS . "paginators" . DS . "Base.php", true); $suite = new self(); $suite->add("Paginators_Status"); $suite->add("Paginators_Follower"); return $suite; }
public function getLogic($name) { $className = "Logics_" . ucfirst($name); if (Sabel::using($className)) { return Sabel_Container::load($className, new Logics_DI()); } $message = __METHOD__ . "() logic class not found."; throw new Sabel_Exception_ClassNotFound($message); }
public static function suite() { Sabel::fileUsing(dirname(__FILE__) . DS . "models" . DS . "Base.php", true); $suite = new self(); $suite->add("Models_User"); $suite->add("Models_Status"); $suite->add("Models_Request"); $suite->add("Models_Follower"); return $suite; }
public static function suite() { Sabel::fileUsing(dirname(__FILE__) . DS . "logics" . DS . "Base.php", true); $suite = new self(); $suite->add("Logics_Register"); $suite->add("Logics_Status"); $suite->add("Logics_Follow"); $suite->add("Logics_User"); return $suite; }
public static function getTableList($connectionName = "default") { $className = "Schema_" . ucfirst($connectionName) . "TableList"; if (Sabel::using($className)) { $sc = new $className(); return $sc->get(); } else { return Sabel_Db::createMetadata($connectionName)->getTableList(); } }
/** * @param string $mdlName * * @return array */ public static function getColumnNames($mdlName) { if (defined("MODELS_DIR_PATH")) { Sabel::fileUsing(MODELS_DIR_PATH . DS . $mdlName . ".php", true); } if (isset(self::$columnNames[$mdlName])) { return self::$columnNames[$mdlName]; } else { return array(); } }
/** * @param string $connectionName * * @throws Sabel_Exception_ClassNotFound * @return Sabel_Db_Abstract_Migration */ public static function createMigration($connectionName = "default") { $className = self::classPrefix($connectionName) . "Migration"; if (Sabel::using($className)) { return new $className(); } elseif ($baseClass = self::getBaseClassName($connectionName, "Migration")) { return new $baseClass(); } else { $message = __METHOD__ . "() Class '{$className}' not Found."; throw new Sabel_Exception_ClassNotFound($message); } }
protected function createController($destination) { list($module, $controller, ) = $destination->toArray(); $class = ucfirst($module) . "_Controllers_" . ucfirst($controller); if (Sabel::using($class)) { l("create controller '{$class}'"); return new $class(); } else { l("controller '{$class}' not found", SBL_LOG_WARN); return null; } }
public function execute($bus) { Sabel_Db_Config::initialize($bus->getConfig("database")); Sabel::fileUsing(RUN_BASE . DS . LIB_DIR_NAME . DS . "db" . DS . "utility.php", true); if (!defined("SBL_BATCH")) { // start session. $session = $bus->get("session"); $session->start(); l("START SESSION: " . $session->getName() . "=" . $session->getId()); } // default page title. $bus->get("response")->setResponse("pageTitle", "Phwittr"); // $request = $bus->get("request"); // if ($request->isPost()) $this->trim($request); }
public function execute($bus) { $destination = $bus->get("destination"); $moduleName = $destination->getModule(); $controllerName = $destination->getController(); $sharedHelper = "application"; $commonHelpers = MODULES_DIR_PATH . DS . HELPERS_DIR_NAME; $moduleHelpers = MODULES_DIR_PATH . DS . $moduleName . DS . HELPERS_DIR_NAME; $helpers = array(); $helpers[] = $commonHelpers . DS . $sharedHelper; $helpers[] = $moduleHelpers . DS . $sharedHelper; $helpers[] = $moduleHelpers . DS . $controllerName; foreach ($helpers as $helper) { Sabel::fileUsing($helper . ".php", true); } }
public function add($testName) { $dir = RUN_BASE . DS . "tests" . DS . "functional" . DS; $parts = explode("_", $testName); $last = array_pop($parts); if (count($parts) > 0) { $dir .= strtolower(implode(DS, $parts)) . DS; } $className = "Functional_" . $testName; Sabel::fileUsing($dir . $last . ".php", true); $reflection = new ReflectionClass($className); if ($reflection->isSubClassOf("Sabel_Test_TestSuite")) { $this->addTest($reflection->getMethod("suite")->invoke(null)); } else { $this->addTest(new self($className)); } }
public function run() { if (count($this->arguments) < 2) { $this->usage(); exit; } $method = $this->getFixtureMethod(); $this->defineEnvironment($this->arguments[0]); Sabel_Db_Config::initialize(new Config_Database()); if (Sabel_Console::hasOption("export", $this->arguments)) { unset($this->arguments[array_search("--export", $this->arguments, true)]); return $this->export("fixture"); } elseif (Sabel_Console::hasOption("export-csv", $this->arguments)) { $dir = Sabel_Console::getOption("export-csv", $this->arguments); if ($dir === null) { $dir = RUN_BASE . DS . "data"; } return $this->export("csv", $dir); } $fixtureName = $this->arguments[1]; if ($fixtureName === "all") { foreach (scandir(FIXTURE_DIR) as $item) { if ($item === "." || $item === "..") { continue; } Sabel::fileUsing(FIXTURE_DIR . DS . $item, true); $className = "Fixture_" . substr($item, 0, strlen($item) - 4); $instance = new $className(); $instance->initialize(); $instance->{$method}(); } } else { $filePath = FIXTURE_DIR . DS . $fixtureName . ".php"; if (Sabel::fileUsing($filePath, true)) { $className = "Fixture_" . $fixtureName; $instance = new $className(); $instance->initialize(); $instance->{$method}(); $this->success(ucfirst($method) . " " . $fixtureName); } else { $this->error("no such fixture file. '{$filePath}'"); } } }
public function setUp() { if (self::$setup) { return; } $dir = TEST_APP_DIR . DS . LIB_DIR_NAME . DS . "processor" . DS; Sabel::fileUsing($dir . "Addon.php", true); Sabel::fileUsing($dir . "Session.php", true); Sabel::fileUsing($dir . "Executer.php", true); Sabel::fileUsing($dir . "Helper.php", true); Sabel::fileUsing($dir . "Initializer.php", true); Sabel::fileUsing($dir . "Controller.php", true); Sabel::fileUsing($dir . "Response.php", true); Sabel::fileUsing($dir . "Request.php", true); Sabel::fileUsing($dir . "Router.php", true); Sabel::fileUsing($dir . "View.php", true); unshift_include_paths(array(MODULES_DIR_NAME, LIB_DIR_NAME, MODULES_DIR_NAME . DS . "models", ADDON_DIR_NAME), TEST_APP_DIR . DS); self::$setup = true; }
public function getTest($suiteClassName, $suiteClassFile = "", $syntaxCheck = true) { Sabel::fileUsing($suiteClassFile, true); $testClass = new ReflectionClass($suiteClassName); if ($testClass->hasMethod(self::SUITE_METHODNAME)) { $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME); if (!$suiteMethod->isStatic()) { throw new Sabel_Exception_Runtime("suite() method must be static."); } try { $test = $suiteMethod->invoke(NULL, $testClass->getName()); } catch (ReflectionException $e) { $message = sprintf("Failed to invoke suite() method.\n%s", $e->getMessage()); throw new Sabel_Exception_Runtime($message); } } else { $test = new Sabel_Test_TestSuite($testClass); } $this->clearStatus(); return $test; }
public static function suite() { Sabel::fileUsing(PROCESSORS_DIR . DS . "Controller.php", true); return self::createSuite("Test_Processor_Controller"); }
public static function init() { $path = "sabel" . DIRECTORY_SEPARATOR . "Sabel"; $cache = Sabel_Util_VariableCache::create($path); if ($files = $cache->read("readableFiles")) { self::$readableFiles = $files; self::$readableFilesNum = count($files); } }
define("SBL_LOG_ERR", 0x8); define("SBL_LOG_ALL", 0xff); ############################################################ define("TPL_SUFFIX", ".tpl"); define("DS", DIRECTORY_SEPARATOR); define("NO_REWRITE_PREFIX", "_uri"); define("MODULES_DIR_NAME", "app"); define("VIEW_DIR_NAME", "views"); define("HELPERS_DIR_NAME", "helpers"); define("LIB_DIR_NAME", "lib"); define("ADDON_DIR_NAME", "addon"); define("CONFIG_DIR_PATH", RUN_BASE . DS . "config"); define("MODULES_DIR_PATH", RUN_BASE . DS . MODULES_DIR_NAME); define("MODELS_DIR_PATH", MODULES_DIR_PATH . DS . "models"); define("LOG_DIR_PATH", RUN_BASE . DS . "logs"); define("CACHE_DIR_PATH", RUN_BASE . DS . "cache"); define("COMPILED_DIR_PATH", CACHE_DIR_PATH . DS . "templates"); define("DEFAULT_LAYOUT_NAME", "layout"); ################# INCLUDE_PATH SETTINGS #################### unshift_include_paths(array(MODULES_DIR_PATH, RUN_BASE . DS . LIB_DIR_NAME, MODELS_DIR_PATH, RUN_BASE . DS . ADDON_DIR_NAME)); unshift_include_path(Sabel::getPath()); ############### INCLUDE CONFIGURATION FILES ################ Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Bus.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Map.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Addon.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Database.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Mail.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "DI.php", true); ################## APPLICATION CONSTANTS ################### define("DEFAULT_IMAGE_NAME", "default.png"); define("FRIENDS_ICON_LIMIT", 36);
<?php Sabel::fileUsing("tasks" . DS . "Tests.php", true); /** * UnitTest * * @category Sakle * @package org.sabel.sakle * @author Mori Reo <*****@*****.**> * @author Ebine Yutaka <*****@*****.**> * @copyright 2004-2008 Mori Reo <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License */ class UnitTest extends Tests { public function run() { Sabel_Db_Config::initialize(new Config_Database()); $runner = Sabel_Test_Runner::create(); $runner->setClassPrefix("Unit_"); $testsDir = RUN_BASE . DS . "tests" . DS . "unit"; if (count($this->arguments) === 0) { foreach (scandir($testsDir) as $file) { if (preg_match("/^[A-Z].+\\.php\$/", $file)) { $testName = str_replace(".php", "", $file); $runner->start($testName, $testsDir . DS . $file); } } } else { $testName = $this->arguments[0]; $runner->start($testName, $testsDir . DS . $testName . ".php");
public static function suite() { Sabel::fileUsing(PROCESSORS_DIR . DS . "Request.php", true); return self::createSuite("Test_Processor_Request"); }
<?php ob_start(); define("RUN_BASE", dirname(realpath("."))); //require ("Sabel" . DIRECTORY_SEPARATOR . "Sabel.php"); require RUN_BASE . DIRECTORY_SEPARATOR . "Sabel" . DIRECTORY_SEPARATOR . "Sabel.php"; require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "INIT.php"; require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "environment.php"; if (!defined("ENVIRONMENT")) { echo "SABEL FATAL ERROR: must define ENVIRONMENT in config/environment.php"; exit; } if ((ENVIRONMENT & PRODUCTION) > 0) { Sabel::init(); echo Sabel_Bus::create()->run(new Config_Bus()); Sabel::shutdown(); } else { echo Sabel_Bus::create()->run(new Config_Bus()); } ob_flush();
protected function exists($className) { return Sabel::using($className) || interface_exists($className); }
public function validate($ignores = array()) { $this->ignores = $ignores; $this->errors = array(); $messages = $this->messages; $model = $this->model; $columns = $this->getColumns(); foreach ($columns as $name => $column) { if (in_array($name, $ignores)) { continue; } $value = $column->value; if ($column->increment) { if ($value === self::OMITTED || $value === null || $this->isUpdate) { continue; } $message = __METHOD__ . "() don't set a value in '{$column->name}'(sequence column)."; throw new Sabel_Db_Exception($message); } if ($this->nullable($column)) { if ($value === self::OMITTED) { $column->value = $value = null; } } else { $this->errors[] = $this->errorMessage($name, $value, "nullable"); continue; } if (!$this->type($column)) { if ($column->isNumeric()) { $this->errors[] = $this->errorMessage($name, $value, "numeric"); } else { $this->errors[] = $this->errorMessage($name, $value, "type"); } continue; } if ($column->isString()) { if (!$this->length($column, "max")) { $message = $this->errorMessage($name, $value, "maxlength"); $this->errors[] = str_replace("%MAX%", $column->max, $message); continue; } elseif (!$this->length($column, "min")) { $message = $this->errorMessage($name, $value, "minlength"); $this->errors[] = str_replace("%MIN%", $column->min, $message); continue; } } if ($column->isNumeric() && $value !== null) { if (!$this->maximum($column)) { $message = $this->errorMessage($name, $value, "maximum"); $this->errors[] = str_replace("%MAX%", $column->max, $message); } elseif (!$this->minimum($column)) { $message = $this->errorMessage($name, $value, "minimum"); $this->errors[] = str_replace("%MIN%", $column->min, $message); } } } if ($uniques = $model->getMetadata()->getUniques()) { $this->unique($model, $uniques); } Sabel::using("Db_Validate_Config"); if ($this->validateConfig === null && !class_exists("Db_Validate_Config", false)) { return $this->errors; } if ($this->validateConfig !== null) { $config = $this->validateConfig; } else { $config = new Db_Validate_Config(); } $config->configure(); $this->doCustomValidate($config, $columns); return $this->errors; }
function MODEL($mdlName, $id = null) { static $cache = array(); if (isset($cache[$mdlName])) { if ($cache[$mdlName]) { return new $mdlName($id); } else { return new Sabel_Db_Model_Proxy($mdlName, $id); } } if (!($exists = class_exists($mdlName, false))) { $path = MODELS_DIR_PATH . DS . $mdlName . ".php"; $exists = Sabel::fileUsing($path, true); } $cache[$mdlName] = $exists; if ($exists) { return new $mdlName($id); } else { return new Sabel_Db_Model_Proxy($mdlName, $id); } }
/** * Load the connection adapter * * While this method is not called more than one for a client, it is * seperated from ->request() to preserve logic and readability * * @param Zend_Http_Client_Adapter_Interface|string $adapter * @return null * @throws Zend_Http_Client_Exception */ public function setAdapter($adapter) { if (is_string($adapter)) { if (!Sabel::using($adapter)) { throw new Sabel_Exception_ClassNotFound($adapter); } $adapter = new $adapter(); } if (!$adapter instanceof Sabel_Http_Client_Adapter_Interface) { $message = __METHOD__ . "() Passed adapter is not a HTTP connection adapter."; throw new Sabel_Exception_InvalidArgument($message); } $this->adapter = $adapter; $config = $this->config; unset($config["adapter"]); $this->adapter->setConfig($config); }
define("SBL_LOG_INFO", 0x1); define("SBL_LOG_DEBUG", 0x2); define("SBL_LOG_WARN", 0x4); define("SBL_LOG_ERR", 0x8); define("SBL_LOG_ALL", 0xff); ############################################################ define("TPL_SUFFIX", ".tpl"); define("DS", DIRECTORY_SEPARATOR); define("MODULES_DIR_NAME", "app"); define("VIEW_DIR_NAME", "views"); define("HELPERS_DIR_NAME", "helpers"); define("LIB_DIR_NAME", "lib"); define("ADDON_DIR_NAME", "addon"); define("CONFIG_DIR_PATH", RUN_BASE . DS . "config"); define("MODULES_DIR_PATH", RUN_BASE . DS . MODULES_DIR_NAME); define("MODELS_DIR_PATH", MODULES_DIR_PATH . DS . "models"); define("LOG_DIR_PATH", RUN_BASE . DS . "logs"); define("CACHE_DIR_PATH", RUN_BASE . DS . "cache"); define("COMPILED_DIR_PATH", CACHE_DIR_PATH . DS . "templates"); define("APP_ENCODING", mb_internal_encoding()); define("DEFAULT_LAYOUT_NAME", "layout"); ################# INCLUDE_PATH SETTINGS #################### unshift_include_paths(array(MODULES_DIR_PATH, RUN_BASE . DS . LIB_DIR_NAME, MODELS_DIR_PATH, RUN_BASE . DS . ADDON_DIR_NAME)); unshift_include_path(Sabel::getPath()); ############### INCLUDE CONFIGURATION FILES ################ Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Bus.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Map.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Addon.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Database.php", true); Sabel::fileUsing(CONFIG_DIR_PATH . DS . "Container.php", true);