Skip to content
Browse files

Initial implementation of behaviors functionality.

  • Loading branch information...
1 parent cf20cf3 commit 659b347b6e171b44cb015d40fabad95c48bd9680 @nateabele committed Sep 20, 2010
View
19 config/bootstrap.php
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+use lithium\core\Libraries;
+
+/**
+ * This adds the `'behavior'` type to the list of recognized class types. You can look up the
+ * behaviors available to your application by running `Libraries::locate('behavior')`.
+ */
+Libraries::paths(array(
+ 'behavior' => array('{:library}\extensions\data\behavior\{:name}')
+));
+
+?>
View
28 extensions/Model.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_behaviors\extensions;
+
+use li3_behaviors\extensions\model\Behaviors;
+
+class Model extends \lithium\data\Model {
+
+ protected $_actsAs = array();
+
+ public static function __init() {
+ static::_isBase(__CLASS__, true);
+ parent::__init();
+ $class = get_called_class();
+
+ if (!static::_isBase($class) && $behaviors = static::_object()->_actsAs) {
+ Behaviors::apply($class, $behaviors);
+ }
+ }
+}
+
+?>
View
28 extensions/model/Behaviors.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace li3_behaviors\extensions\model;
+
+use lithium\core\Libraries;
+
+class Behaviors extends \lithium\core\StaticObject {
+
+ public static function apply($model, array $behaviors) {
+ foreach ($behaviors as $name => $config) {
+ if (is_string($config)) {
+ $name = $config;
+ $config = array();
+ }
+ if ($class = Libraries::locate('behavior', $name)) {
+ $class::bind($model, $config);
+ }
+ }
+ }
+}
+
+?>
View
0 tests/cases/controllers/empty
No changes.
View
0 tests/cases/extensions/adapter/empty
No changes.
View
0 tests/cases/extensions/command/empty
No changes.
View
1 tests/cases/extensions/data/source/empty
@@ -0,0 +1 @@
+
View
0 tests/cases/extensions/helper/empty
No changes.
View
0 tests/cases/models/empty
No changes.
View
0 tests/functional/empty
No changes.
View
0 tests/integration/empty
No changes.
View
0 tests/mocks/empty
No changes.

0 comments on commit 659b347

Please sign in to comment.
Something went wrong with that request. Please try again.