Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed method names to match the new conventions

  • Loading branch information...
commit db626e0620d73ab6001de6acfa74d33796833772 1 parent cb62f61
@milesj milesj authored
View
38 tests/titon/core/EventTest.php
@@ -33,14 +33,14 @@ protected function setUp() {
public function testExecute() {
// test events by name
$event1 = new \titon\core\Event();
- $event1->registerListener(new MockListener());
- $event1->registerListener(new MockListener());
- $event1->registerCallback(function() {}, array('startup', 'shutdown', 'testEvent1'));
- $event1->registerCallback(function() {}, array('startup', 'testEvent1', 'testEvent2'));
- $event1->execute('startup');
- $event1->execute('shutdown');
- $event1->execute('testEvent1');
- $event1->execute('testEvent2');
+ $event1->addListener(new MockListener());
+ $event1->addListener(new MockListener());
+ $event1->addCallback(function() {}, array('startup', 'shutdown', 'testEvent1'));
+ $event1->addCallback(function() {}, array('startup', 'testEvent1', 'testEvent2'));
+ $event1->notify('startup');
+ $event1->notify('shutdown');
+ $event1->notify('testEvent1');
+ $event1->notify('testEvent2');
$listeners = $event1->getListeners();
$startup = 0;
@@ -74,10 +74,10 @@ public function testExecute() {
// test events by scope
/* @todo
* $event2 = new \titon\core\Event();
- $event2->registerListener(new MockListener(), array('controller' => 'test'));
- $event2->registerListener(new MockListener());
- $event2->registerCallback(function() {}, array(), array('action' => 'action'));
- $event2->registerCallback(function() {});
+ $event2->addListener(new MockListener(), array('controller' => 'test'));
+ $event2->addListener(new MockListener());
+ $event2->addCallback(function() {}, array(), array('action' => 'action'));
+ $event2->addCallback(function() {});
$_SERVER['PHP_SELF'] = 'index.php/test/index/action/';
$_SERVER['REQUEST_URI'] = 'http://localhost/test/index/action/';
@@ -91,8 +91,8 @@ public function testExecute() {
*/
public function testListeners() {
$event = new \titon\core\Event();
- $event->registerListener(new MockListener());
- $event->registerCallback(function() {});
+ $event->addListener(new MockListener());
+ $event->addCallback(function() {});
$listeners = $event->getListeners();
@@ -112,8 +112,8 @@ public function testListeners() {
*/
public function testRegisterListener() {
$event = new \titon\core\Event();
- $event->registerListener(new MockListener());
- $event->registerListener(new MockListener());
+ $event->addListener(new MockListener());
+ $event->addListener(new MockListener());
$listeners = $event->getListeners();
@@ -133,9 +133,9 @@ public function testRegisterListener() {
*/
public function testRegisterCallback() {
$event = new \titon\core\Event();
- $event->registerCallback(function() {});
- $event->registerCallback(function() {});
- $event->registerCallback(function() {});
+ $event->addCallback(function() {});
+ $event->addCallback(function() {});
+ $event->addCallback(function() {});
$listeners = $event->getListeners();
View
2  vendors/titon/Titon.php
@@ -37,7 +37,7 @@ class Titon {
* @var string
* @static
*/
- public static $version = '0.0.1.1';
+ public static $version = '0.4.0';
/**
* Installed objects that can not be uninstalled.
View
12 vendors/titon/constant/Http.php
@@ -206,7 +206,7 @@ class Http {
* @throws \titon\constant\ConstantException
* @static
*/
- public static function contentType($type) {
+ public static function getContentType($type) {
if (isset(self::$contentTypes[$type])) {
return self::$contentTypes[$type];
}
@@ -221,7 +221,7 @@ public static function contentType($type) {
* @return array
* @static
*/
- public static function contentTypes() {
+ public static function getContentTypes() {
return self::$contentTypes;
}
@@ -232,7 +232,7 @@ public static function contentTypes() {
* @return array
* @static
*/
- public static function headerTypes() {
+ public static function getHeaderTypes() {
return self::$headerTypes;
}
@@ -243,7 +243,7 @@ public static function headerTypes() {
* @return array
* @static
*/
- public static function methodTypes() {
+ public static function getMethodTypes() {
return self::$methodTypes;
}
@@ -256,7 +256,7 @@ public static function methodTypes() {
* @throws \titon\constant\ConstantException
* @static
*/
- public static function statusCode($code) {
+ public static function getStatusCode($code) {
if (isset(self::$statusCodes[$code])) {
return self::$statusCodes[$code];
}
@@ -271,7 +271,7 @@ public static function statusCode($code) {
* @return array
* @static
*/
- public static function statusCodes() {
+ public static function getStatusCodes() {
return self::$statusCodes;
}
View
152 vendors/titon/core/Event.php
@@ -40,66 +40,33 @@ class Event {
protected $_listeners = array();
/**
- * Cycles through the listenerss for the specified event, and executes the related method.
- * If a scope is defined, and the listener doesn't match the scope, it will be bypassed.
+ * Register a basic callback using a Closure. This callback can be restricted in scope and a per event basis.
+ * Can drill down the event to only execute during a certain scope.
*
* @access public
- * @param string $event
- * @param object $object
- * @return void
+ * @param \Closure $callback
+ * @param array $events
+ * @param array $scope
+ * @return \titon\core\Event
+ * @chainable
*/
- public function execute($event, $object = null) {
- if (empty($this->_listeners)) {
- return;
- }
-
- $route = Titon::router()->current();
-
- foreach ($this->_listeners as &$listener) {
- if (isset($listener['executed'][$event])) {
- continue;
- }
-
- foreach (array('module', 'controller', 'action') as $action) {
- if ($listener['scope'][$action] !== $route->param($action) || $listener['scope'][$action] !== '*') {
- continue;
- }
- }
-
- $obj = $listener['object'];
-
- if ($obj instanceof Closure && in_array($event, $listener['events'])) {
- $obj($event, $object);
-
- } else if (method_exists($obj, $event)) {
- $obj->{$event}($object);
-
- } else {
- continue;
- }
-
- $listener['executed'][$event] = true;
+ public function addCallback(Closure $callback, array $events = array(), array $scope = array()) {
+ if (empty($events)) {
+ $events = $this->_events;
}
- }
- /**
- * Return all assigned events.
- *
- * @access public
- * @return array
- */
- public function getEvents() {
- return $this->_events;
- }
+ $this->_listeners[] = array(
+ 'object' => $callback,
+ 'executed' => array(),
+ 'events' => $events,
+ 'scope' => $scope + array(
+ 'module' => '*',
+ 'controller' => '*',
+ 'action' => '*'
+ )
+ );
- /**
- * Return all registered listeners.
- *
- * @access public
- * @return array
- */
- public function getListeners() {
- return $this->_listeners;
+ return $this;
}
/**
@@ -112,7 +79,7 @@ public function getListeners() {
* @return \titon\core\Event
* @chainable
*/
- public function registerListener(Listener $listener, array $scope = array()) {
+ public function addListener(Listener $listener, array $scope = array()) {
$this->_listeners[] = array(
'object' => $listener,
'executed' => array(),
@@ -128,33 +95,66 @@ public function registerListener(Listener $listener, array $scope = array()) {
}
/**
- * Register a basic callback using a Closure. This callback can be restricted in scope and a per event basis.
- * Can drill down the event to only execute during a certain scope.
+ * Return all assigned events.
*
* @access public
- * @param \Closure $callback
- * @param array $events
- * @param array $scope
- * @return \titon\core\Event
- * @chainable
+ * @return array
*/
- public function registerCallback(Closure $callback, array $events = array(), array $scope = array()) {
- if (empty($events)) {
- $events = $this->_events;
+ public function getEvents() {
+ return $this->_events;
+ }
+
+ /**
+ * Return all registered listeners.
+ *
+ * @access public
+ * @return array
+ */
+ public function getListeners() {
+ return $this->_listeners;
+ }
+
+ /**
+ * Cycles through the listenerss for the specified event, and executes the related method.
+ * If a scope is defined, and the listener doesn't match the scope, it will be bypassed.
+ *
+ * @access public
+ * @param string $event
+ * @param object $object
+ * @return void
+ */
+ public function notify($event, $object = null) {
+ if (empty($this->_listeners)) {
+ return;
}
- $this->_listeners[] = array(
- 'object' => $callback,
- 'executed' => array(),
- 'events' => $events,
- 'scope' => $scope + array(
- 'module' => '*',
- 'controller' => '*',
- 'action' => '*'
- )
- );
+ $route = Titon::router()->current();
- return $this;
+ foreach ($this->_listeners as &$listener) {
+ if (isset($listener['executed'][$event])) {
+ continue;
+ }
+
+ foreach (array('module', 'controller', 'action') as $action) {
+ if ($listener['scope'][$action] !== $route->getParam($action) || $listener['scope'][$action] !== '*') {
+ continue;
+ }
+ }
+
+ $obj = $listener['object'];
+
+ if ($obj instanceof Closure && in_array($event, $listener['events'])) {
+ $obj($event, $object);
+
+ } else if (method_exists($obj, $event)) {
+ $obj->{$event}($object);
+
+ } else {
+ continue;
+ }
+
+ $listener['executed'][$event] = true;
+ }
}
/**
View
166 vendors/titon/core/G11n.php
@@ -79,88 +79,6 @@ class G11n {
protected $_translator;
/**
- * Apple the locale using PHPs built in setlocale().
- *
- * @link http://php.net/setlocale
- * @link http://php.net/manual/locale.setdefault.php
- *
- * @access public
- * @param string $key
- * @return \titon\core\G11n
- * @throws \titon\core\CoreException
- * @chainable
- */
- public function apply($key) {
- $key = $this->canonicalize($key);
-
- if (!isset($this->_locales[$key])) {
- throw new CoreException(sprintf('Locale %s does not exist.', $key));
- }
-
- $bundle = $this->_locales[$key];
- $locale = $bundle->locale();
-
- // Build array of options to set
- $options = array(
- $locale['id'] . '.UTF8',
- $locale['id'] . '.UTF-8',
- $locale['id']
- );
-
- if (!empty($locale['iso3'])) {
- $options = array_merge($options, array(
- $locale['iso3'] . '.UTF8',
- $locale['iso3'] . '.UTF-8',
- $locale['iso3']
- ));
- }
-
- if (!empty($locale['iso2'])) {
- $options = array_merge($options, array(
- $locale['iso2'] . '.UTF8',
- $locale['iso2'] . '.UTF-8',
- $locale['iso2']
- ));
- }
-
- // Use fallback options
- $fallbackLocale = $this->getFallback()->locale();
-
- $options = array_merge($options, array(
- $fallbackLocale['id'] . '.UTF8',
- $fallbackLocale['id'] . '.UTF-8',
- $fallbackLocale['id']
- ));
-
- // Set environment
- putenv('LC_ALL=' . $locale['id']);
- setlocale(LC_ALL, $options);
- Locale::setDefault($locale['id']);
-
- if (!empty($locale['timezone'])) {
- $this->applyTimezone($locale['timezone']);
- }
-
- $this->_current = $bundle;
-
- return $this;
- }
-
- /**
- * Apply the timezone.
- *
- * @access public
- * @param string $timezone
- * @return \titon\core\G11n
- * @chainable
- */
- public function applyTimezone($timezone) {
- date_default_timezone_set($timezone);
-
- return $this;
- }
-
- /**
* Convert a locale key to 3 possible formats.
*
* FORMAT_1 - en-us
@@ -298,7 +216,7 @@ public function initialize() {
}
// Apply the locale
- $this->apply($current);
+ $this->set($current);
// Check for a translator
if (empty($this->_translator)) {
@@ -365,6 +283,74 @@ public function loadBundle($key, array $config = array()) {
}
/**
+ * Set the locale using PHPs built in setlocale().
+ *
+ * @link http://php.net/setlocale
+ * @link http://php.net/manual/locale.setdefault.php
+ *
+ * @access public
+ * @param string $key
+ * @return \titon\core\G11n
+ * @throws \titon\core\CoreException
+ * @chainable
+ */
+ public function set($key) {
+ $key = $this->canonicalize($key);
+
+ if (!isset($this->_locales[$key])) {
+ throw new CoreException(sprintf('Locale %s does not exist.', $key));
+ }
+
+ $bundle = $this->_locales[$key];
+ $locale = $bundle->locale();
+
+ // Build array of options to set
+ $options = array(
+ $locale['id'] . '.UTF8',
+ $locale['id'] . '.UTF-8',
+ $locale['id']
+ );
+
+ if (!empty($locale['iso3'])) {
+ $options = array_merge($options, array(
+ $locale['iso3'] . '.UTF8',
+ $locale['iso3'] . '.UTF-8',
+ $locale['iso3']
+ ));
+ }
+
+ if (!empty($locale['iso2'])) {
+ $options = array_merge($options, array(
+ $locale['iso2'] . '.UTF8',
+ $locale['iso2'] . '.UTF-8',
+ $locale['iso2']
+ ));
+ }
+
+ // Use fallback options
+ $fallbackLocale = $this->getFallback()->locale();
+
+ $options = array_merge($options, array(
+ $fallbackLocale['id'] . '.UTF8',
+ $fallbackLocale['id'] . '.UTF-8',
+ $fallbackLocale['id']
+ ));
+
+ // Set environment
+ putenv('LC_ALL=' . $locale['id']);
+ setlocale(LC_ALL, $options);
+ Locale::setDefault($locale['id']);
+
+ if (!empty($locale['timezone'])) {
+ $this->setTimezone($locale['timezone']);
+ }
+
+ $this->_current = $bundle;
+
+ return $this;
+ }
+
+ /**
* Sets up the application with the defined locale key; the key will be formatted to a lowercase dashed URL friendly format.
* The system will then attempt to load the locale resource bundle and finalize configuration settings.
*
@@ -386,6 +372,20 @@ public function setup($key, array $config = array()) {
return $this;
}
+
+ /**
+ * Set the timezone.
+ *
+ * @access public
+ * @param string $timezone
+ * @return \titon\core\G11n
+ * @chainable
+ */
+ public function setTimezone($timezone) {
+ date_default_timezone_set($timezone);
+
+ return $this;
+ }
/**
* Sets the translator to use in the string locating and translating process.
View
2  vendors/titon/libs/controllers/ControllerAbstract.php
@@ -156,7 +156,7 @@ public function runAction(Action $action) {
public function throwError($action, array $args = array()) {
if (empty($args['pageTitle'])) {
if (is_numeric($action)) {
- $args['pageTitle'] = $action . ' - ' . Http::statusCode($action);
+ $args['pageTitle'] = $action . ' - ' . Http::getStatusCode($action);
} else {
$args['pageTitle'] = Inflector::normalize($action);
}
View
12 vendors/titon/libs/dispatchers/front/FrontDevDispatcher.php
@@ -35,11 +35,11 @@ public function run() {
$event = Titon::event();
Benchmark::start('Dispatcher');
- $event->execute('preDispatch');
+ $event->notify('preDispatch');
Benchmark::start('Controller');
$controller->preProcess();
- $event->execute('preProcess', $controller);
+ $event->notify('preProcess', $controller);
Benchmark::start('Action');
@@ -58,7 +58,7 @@ public function run() {
Benchmark::stop('Action');
$controller->postProcess();
- $event->execute('postProcess', $controller);
+ $event->notify('postProcess', $controller);
Benchmark::stop('Controller');
if ($controller->hasObject('engine') && $controller->engine->config('render')) {
@@ -66,16 +66,16 @@ public function run() {
Benchmark::start('View');
$engine->preRender();
- $event->execute('preRender', $engine);
+ $event->notify('preRender', $engine);
$engine->run();
$engine->postRender();
- $event->execute('postRender', $engine);
+ $event->notify('postRender', $engine);
Benchmark::stop('View');
}
- $event->execute('postDispatch');
+ $event->notify('postDispatch');
Benchmark::stop('Dispatcher');
}
View
12 vendors/titon/libs/dispatchers/front/FrontDispatcher.php
@@ -33,10 +33,10 @@ public function run() {
$controller = $this->controller;
$event = Titon::event();
- $event->execute('preDispatch');
+ $event->notify('preDispatch');
$controller->preProcess();
- $event->execute('preProcess', $controller);
+ $event->notify('preProcess', $controller);
try {
$controller->dispatchAction();
@@ -51,21 +51,21 @@ public function run() {
}
$controller->postProcess();
- $event->execute('postProcess', $controller);
+ $event->notify('postProcess', $controller);
if ($controller->hasObject('engine') && $controller->engine->config('render')) {
$engine = $controller->engine;
$engine->preRender();
- $event->execute('preRender', $engine);
+ $event->notify('preRender', $engine);
$engine->run();
$engine->postRender();
- $event->execute('postRender', $engine);
+ $event->notify('postRender', $engine);
}
- $event->execute('postDispatch');
+ $event->notify('postDispatch');
}
}
View
2  vendors/titon/libs/exceptions/HttpException.php
@@ -33,7 +33,7 @@ public function __construct($message, $code = 0, $previous) {
}
if ($code && empty($message)) {
- $message = Http::statusCode($code);
+ $message = Http::getStatusCode($code);
}
parent::__construct($message, $code, $previous);
View
42 vendors/titon/libs/routes/RouteAbstract.php
@@ -172,6 +172,27 @@ public function compile() {
return $this->_compiled;
}
+
+ /**
+ * Grab a param from the route.
+ *
+ * @access public
+ * @param string $key
+ * @return string|null
+ */
+ public function getParam($key = null) {
+ return isset($this->_route[$key]) ? $this->_route[$key] : null;
+ }
+
+ /**
+ * Return all route params.
+ *
+ * @access public
+ * @return string|null
+ */
+ public function getParams() {
+ return $this->_route;
+ }
/**
* Compile the route and attach the request object.
@@ -318,25 +339,4 @@ public function match($url) {
return ($this->isMatch($url) && $this->isMethod() && $this->isSecure());
}
- /**
- * Grab a param from the route.
- *
- * @access public
- * @param string $key
- * @return string|null
- */
- public function param($key = null) {
- return isset($this->_route[$key]) ? $this->_route[$key] : null;
- }
-
- /**
- * Return all route params.
- *
- * @access public
- * @return string|null
- */
- public function params() {
- return $this->_route;
- }
-
}
View
42 vendors/titon/log/Benchmark.php
@@ -39,27 +39,6 @@ class Benchmark {
private function __construct() { }
/**
- * Outputs and formats a benchmark directly as a string.
- *
- * @access public
- * @param string $key
- * @return string
- * @static
- */
- public static function display($key = null) {
- if (empty(self::$_benchmarks[$key])) {
- return false;
- }
-
- $benchmark = self::get($key);
- $result = 'Benchmark [' . $key . '] - ';
- $result .= 'Time: ' . number_format($benchmark['avgTime'], 4) . ' - ';
- $result .= 'Memory: ' . $benchmark['avgMemory'] . ' (Max: ' . $benchmark['peakMemory'] . ')';
-
- return $result;
- }
-
- /**
* Grab a list of all benchmarks or a single benchmark and return an array.
* Will calculate the averages of the time and memory if $calculate is true.
*
@@ -92,6 +71,27 @@ public static function get($key = null) {
}
/**
+ * Outputs and formats a benchmark directly as a string.
+ *
+ * @access public
+ * @param string $key
+ * @return string
+ * @static
+ */
+ public static function output($key = null) {
+ if (empty(self::$_benchmarks[$key])) {
+ return false;
+ }
+
+ $benchmark = self::get($key);
+ $result = 'Benchmark [' . $key . '] - ';
+ $result .= 'Time: ' . number_format($benchmark['avgTime'], 4) . ' - ';
+ $result .= 'Memory: ' . $benchmark['avgMemory'] . ' (Max: ' . $benchmark['peakMemory'] . ')';
+
+ return $result;
+ }
+
+ /**
* Start the benchmarking process by logging the micro seconds and memory usage.
*
* @access public
View
2  vendors/titon/net/Request.php
@@ -76,7 +76,7 @@ class Request extends Base {
* @throws \titon\net\NetException
*/
public function accepts($type = 'html') {
- $contentType = (array) Http::contentType($type);
+ $contentType = (array) Http::getContentType($type);
foreach ($this->_accepts('Accept') as $aType) {
if (in_array(strtolower($aType['type']), $contentType)) {
View
4 vendors/titon/net/Response.php
@@ -195,7 +195,7 @@ public function respond() {
header(sprintf('%s %d %s',
Http::HTTP_11,
$this->_status,
- Http::statusCode($this->_status)
+ Http::getStatusCode($this->_status)
));
// Content type
@@ -245,7 +245,7 @@ public function status($code = 302) {
*/
public function type($type = null) {
if (strpos($type, '/') === false) {
- $contentType = Http::contentType($type);
+ $contentType = Http::getContentType($type);
if (is_array($contentType)) {
$type = $contentType[0];
Please sign in to comment.
Something went wrong with that request. Please try again.