Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Mar 25, 2015
0 parents commit 0a93501
Show file tree
Hide file tree
Showing 45 changed files with 4,597 additions and 0 deletions.
139 changes: 139 additions & 0 deletions classes/Behavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php defined('SYSPATH') or die('No direct access allowed.');

/**
* @package KodiCMS/Behavior
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class Behavior {

/**
*
* @var array
*/
private static $behaviors = array();

/**
*
* @param string $behavior_id
* @return Behavior_Abstract
* @throws HTTP_Exception_404
*/
public static function factory($behavior_id)
{
$behavior_config = self::get($behavior_id);
if ($behavior_config === NULL)
{
throw new HTTP_Exception_404('Behavior :behavior not found!', array(
':behavior' => $behavior_id
));
}

$class_name = Arr::get($behavior_config, 'class', $behavior_id);

$behavior_class = 'Behavior_' . URL::title($class_name, '');

if (!class_exists($behavior_class))
{
return NULL;
}

return new $behavior_class($behavior_config);
}

/**
* Init behaviors
*/
public static function init()
{
$config = Kohana::$config->load('behaviors');

foreach ($config as $behavior_id => $data)
{
self::$behaviors[$behavior_id] = $data;
}
}

/**
*
* @param type $behavior_id
* @return array
*/
public static function get($behavior_id)
{
return Arr::get(self::$behaviors, $behavior_id);
}

/**
* Load a behavior and return it
*
* @param behavior_id string The Behavior plugin folder name
* @param page object Will be pass to the behavior
*
*
* @return Behavior_Abstract
*/
public static function load($behavior_id, Model_Page_Front &$page, $url, $uri)
{
$behavior = self::factory($behavior_id);

$uri = substr($uri, strlen($url));

return $behavior
->set_page($page)
->execute_uri($uri);
}

/**
* Load a behavior and return it
*
* @param behavior_id string The Behavior plugin folder name
*
* @return string class name of the page
*/
public static function load_page($behavior_id)
{
$behavior_page_class = 'Model_Page_Behavior_' . URL::title($behavior_id, '');

if (class_exists($behavior_page_class))
{
return $behavior_page_class;
}
else
{
return 'Model_Page_Behavior';
}
}

/**
*
* Find all active Behaviors id
* @return array
*/
public static function findAll()
{
return array_keys(self::$behaviors);
}

/**
*
* @param string $name
* @param array|string $selected
* @param array $attributes
* @return string
*/
public static function select_choices()
{
$options = array('' => __('none'));

foreach (self::findAll() as $behavior)
{
$options[$behavior] = __(ucfirst(Inflector::humanize($behavior)));
}

return $options;
}

}
132 changes: 132 additions & 0 deletions classes/Behavior/Abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' );

/**
* @package KodiCMS/Behavior
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
abstract class Behavior_Abstract {

/**
*
* @var Model_Page_Front
*/
protected $_page = NULL;

/**
*
* @var Behavior_Route
*/
protected $_router = NULL;

/**
*
* @var array
*/
protected $_config = array();

/**
*
* @var array
*/
protected $_settings = NULL;

/**
*
* @param array $config
*/
public function __construct(array $config = array())
{
$this->_config = $config;

$routes = $this->routes();

if (isset($this->_config['routes']) AND is_array($this->_config['routes']))
{
$routes = $this->_config['routes'] + $routes;
}

$this->_router = new Behavior_Route($routes);
}

/**
*
* @return array
*/
public function routes()
{
return array();
}

/**
*
* @return Behavior_Route
*/
public function router()
{
return $this->_router;
}

/**
*
* @param string $uri
*/
public function execute_uri($uri)
{
$method = $this->_router->find($uri);

if (strpos($method, '::') !== FALSE)
{
Callback::invoke($method, array($this));
}
else
{
$this->{$method}();
}

return $this;
}

/**
*
* @param Model_Page_Front $page
* @return \Behavior_Abstract
*/
public function set_page(Model_Page_Front &$page)
{
$this->_page = &$page;
return $this;
}

/**
*
* @return Model_Page_Front
*/
public function page()
{
return $this->_page;
}

/**
*
* @return Behavior_Settings
*/
public function settings()
{
if ($this->_settings === NULL)
{
$this->_settings = new Behavior_Settings($this->page());
}

return $this->_settings;
}

public function stub()
{

}

abstract public function execute();
}
17 changes: 17 additions & 0 deletions classes/Behavior/Protectedpage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct access allowed.');

/**
* @package KodiCMS/Pages
* @category Behavior
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class Behavior_ProtectedPage extends Behavior_Abstract
{
public function execute()
{

}
}
Loading

0 comments on commit 0a93501

Please sign in to comment.