Skip to content
Permalink
Browse files

Moving methods down and adding some tests.

  • Loading branch information...
markstory committed Jul 2, 2010
1 parent 6db3dbc commit 9fd881cb00d8ce865b462cc91c0cf902c6a12d1d
@@ -357,46 +357,6 @@ public function detach($name) {
$this->_attached = array_values(array_diff($this->_attached, (array)$name));
}
/**
* Enables callbacks on a behavior or array of behaviors
*
* @param mixed $name CamelCased name of the behavior(s) to enable (string or array)
* @return void
*/
public function enable($name) {
$this->_disabled = array_diff($this->_disabled, (array)$name);
}
/**
* Disables callbacks on a behavior or array of behaviors. Public behavior methods are still
* callable as normal.
*
* @param mixed $name CamelCased name of the behavior(s) to disable (string or array)
* @return void
*/
public function disable($name) {
foreach ((array)$name as $behavior) {
if (in_array($behavior, $this->_attached) && !in_array($behavior, $this->_disabled)) {
$this->_disabled[] = $behavior;
}
}
}
/**
* Gets the list of currently-enabled behaviors, or, the current status of a single behavior
*
* @param string $name Optional. The name of the behavior to check the status of. If omitted,
* returns an array of currently-enabled behaviors
* @return mixed If $name is specified, returns the boolean status of the corresponding behavior.
* Otherwise, returns an array of all enabled behaviors.
*/
public function enabled($name = null) {
if (!empty($name)) {
return (in_array($name, $this->_attached) && !in_array($name, $this->_disabled));
}
return array_diff($this->_attached, $this->_disabled);
}
/**
* Dispatches a behavior method
*
@@ -477,18 +437,4 @@ public function methods() {
return $this->__methods;
}
/**
* Gets the list of attached behaviors, or, whether the given behavior is attached
*
* @param string $name Optional. The name of the behavior to check the status of. If omitted,
* returns an array of currently-attached behaviors
* @return mixed If $name is specified, returns the boolean status of the corresponding behavior.
* Otherwise, returns an array of all attached behaviors.
*/
public function attached($name = null) {
if (!empty($name)) {
return (in_array($name, $this->_attached));
}
return $this->_attached;
}
}
@@ -35,4 +35,59 @@ abstract class ObjectCollection {
*/
protected $_disabled = array();
/**
* Enables callbacks on a behavior or array of behaviors
*
* @param mixed $name CamelCased name of the behavior(s) to enable (string or array)
* @return void
*/
public function enable($name) {
$this->_disabled = array_diff($this->_disabled, (array)$name);
}
/**
* Disables callbacks on a object or array of objects. Public object methods are still
* callable as normal.
*
* @param mixed $name CamelCased name of the objects(s) to disable (string or array)
* @return void
*/
public function disable($name) {
foreach ((array)$name as $object) {
if (in_array($object, $this->_attached) && !in_array($object, $this->_disabled)) {
$this->_disabled[] = $object;
}
}
}
/**
* Gets the list of currently-enabled objects, or, the current status of a single objects
*
* @param string $name Optional. The name of the object to check the status of. If omitted,
* returns an array of currently-enabled object
* @return mixed If $name is specified, returns the boolean status of the corresponding object.
* Otherwise, returns an array of all enabled objects.
*/
public function enabled($name = null) {
if (!empty($name)) {
return (in_array($name, $this->_attached) && !in_array($name, $this->_disabled));
}
return array_diff($this->_attached, $this->_disabled);
}
/**
* Gets the list of attached behaviors, or, whether the given behavior is attached
*
* @param string $name Optional. The name of the behavior to check the status of. If omitted,
* returns an array of currently-attached behaviors
* @return mixed If $name is specified, returns the boolean status of the corresponding behavior.
* Otherwise, returns an array of all attached behaviors.
*/
public function attached($name = null) {
if (!empty($name)) {
return (in_array($name, $this->_attached));
}
return $this->_attached;
}
}
@@ -57,7 +57,10 @@ public function load($helper, $settings = array()) {
if (!class_exists($helperClass)) {
throw new MissingHelperClassException($helperClass);
}
$this->{$name} = new $helperClass($this->_View, $settings);
}
$this->{$name} = new $helperClass($this->_View, $settings);
if (!in_array($name, $this->_attached)) {
$this->_attached[] = $name;
}
return $this->{$name};
}
@@ -50,6 +50,11 @@ function testLoad() {
$result = $this->Helpers->load('Html');
$this->assertType('HtmlHelper', $result);
$this->assertType('HtmlHelper', $this->Helpers->Html);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Helpers->enabled('Html'));
}
/**

0 comments on commit 9fd881c

Please sign in to comment.
You can’t perform that action at this time.