Skip to content
Browse files

hardcoding :)

  • Loading branch information...
1 parent 86ceccb commit c796ef747e93fb1f19dfe335cc268f52eea2f9b1 @fprochazka fprochazka committed Jul 31, 2010
View
1 .gitignore
@@ -1 +1,2 @@
+nbproject
tests
View
4 .htaccess
@@ -0,0 +1,4 @@
+<Files ".gitignore">
+ Order Allow,Deny
+ Deny from all
+</Files>
View
13 app/config.ini
@@ -12,14 +12,25 @@ php.date.timezone = "Europe/Prague"
variable.tempDir = %wwwDir%/../temp
variable.logDir = %tempDir%/log
variable.sessionsDir = %tempDir%/sessions
+variable.backupDir = %wwwDir%/../backup
; services
service.Nette-Loaders-RobotLoader.option.directory[] = %appDir%
service.Nette-Loaders-RobotLoader.option.directory[] = %libsDir%
service.Nette-Loaders-RobotLoader.run = TRUE
-
[production < common]
[development < common]
+
+
+[database]
+engine = mysqli
+encoding = utf8
+
+
+[development.database]
+username = HosipLan
+password = heslo
+database = kdyby_fcms
View
23 app/modifications/Page/loader.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Kdyby\Modification\Page;
+
+
+/**
+ * Description of loader
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class Loader extends \Kdyby\ModificationLoader
+{
+
+ protected $addonClasses = array();
+
+ protected $modificationClasses = array();
+
+ protected $dependencies = array();
+
+
+
+
+}
View
17 app/modifications/Page/presenters/Page.php
@@ -0,0 +1,17 @@
+<?php
+
+
+namespace Kdyby\Modification\Page;
+
+
+
+
+/**
+ * Description of Page
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class Page extends \Kdyby\BasePresenter
+{
+
+}
View
17 app/modifications/Page/presenters/PageAdmin.php
@@ -0,0 +1,17 @@
+<?php
+
+
+namespace Kdyby\Modification\Page;
+
+
+
+
+/**
+ * Description of PageAdmin
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class PageAdmin extends \Kdyby\AdminPresenter
+{
+
+}
View
2 app/modifications/Page/templates/Page/default.phtml
@@ -0,0 +1,2 @@
+
+{block content}
View
6 document_root/index.php
@@ -11,3 +11,9 @@
// load bootstrap file
require LIBS_DIR . '/Kdyby/loader.php';
+
+// 6b) Hook callbacks
+$application->hook();
+
+// 6c) Run the application!
+$application->run();
View
73 libs/Kdyby/Application/Kdyby.php
@@ -1,19 +1,82 @@
<?php
+
namespace Kdyby\Application;
+use Nette\Environment;
+
+
/**
* Description of Kdyby
*
- * @author hosiplan
+ * @author Filip Procházka <hosiplan@kdyby.org>
*/
-class Kdyby extends \Nette\Application\Application
+final class Kdyby extends \Nette\Application\Application
{
- public function register()
+ /** @var array of function(Application $sender); Occurs before the application loads itself */
+ public $onLoad;
+
+ /** @var bool */
+ private $hooked = FALSE;
+
+
+ //public $errorPresenter = 'Error';
+
+ //public $catchExceptions = TRUE;
+
+
+
+ public function hook()
+ {
+ $this->onLoad[] = callback($this, 'hookServices');
+
+ $this->onLoad[] = callback($this, 'hookFillLoader');
+
+ $this->hooked = TRUE;
+ }
+
+
+ public function run()
+ {
+ if( !$this->hooked ){
+ throw new \InvalidStateException("Call \$application->hook(); first!");
+ }
+
+ $this->onLoad($this);
+
+ parent::run();
+ }
+
+
+ public function getLoader()
+ {
+ return \Kdyby\KdybyLoader::getInstance();
+ }
+
+
+ public function hookFillLoader()
+ {
+ $this->getLoader()->loadCache();
+ }
+
+
+ public function hookServices()
+ {
+ $locator = $this->getServiceLocator();
+
+ // Nette\Application\IRouter override
+ $locator->addService('Nette\Application\IRouter', 'Kdyby\Application\ExtendableRouter');
+
+ // Nette\Security\IAuthenticator
+ //$locator->addService("Nette\Security\IAuthenticator", "");
+ }
+
+
+ public static function createPresenterLoader()
{
-
+ // Kdyby\Application\PresenterLoader
+ return new PresenterLoader($this->getLoader(), Environment::getVariable('appDir'));
}
}
-?>
View
129 libs/Kdyby/Application/PresenterLoader.php
@@ -0,0 +1,129 @@
+<?php
+
+
+namespace Kdyby\Application;
+
+use Nette;
+
+
+
+/**
+ * Description of PresenterLoader
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class PresenterLoader extends \Nette\Object implements \Nette\Application\IPresenterLoader
+{
+ /** @var bool */
+ public $caseSensitive = FALSE;
+
+ /** @var string */
+ private $baseDir;
+
+ /** @var Kdyby\KdybyLoader */
+ private $loader;
+
+ /** @var array */
+ private $cache = array();
+
+
+
+ /**
+ *
+ * @param <type> $loader
+ * @param <type> $baseDir
+ */
+ public function __construct(\Kdyby\KdybyLoader $loader, $baseDir)
+ {
+ $this->loader = $loader;
+ $this->baseDir = $baseDir;
+ }
+
+
+
+ /**
+ * @param string presenter name
+ * @return string class name
+ * @throws InvalidPresenterException
+ */
+ public function getPresenterClass(& $name)
+ {
+ if (isset($this->cache[$name])) {
+ list($class, $name) = $this->cache[$name];
+ return $class;
+ }
+
+ if (!is_string($name) || !Nette\String::match($name, "#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*$#")) {
+ throw new InvalidPresenterException("Presenter name must be alphanumeric string, '$name' is invalid.");
+ }
+
+ $class = $this->formatPresenterClass($name);
+
+ if (!class_exists($class)) {
+ // internal autoloading
+ $file = $this->formatPresenterFile($name);
+ if (is_file($file) && is_readable($file)) {
+ Nette\Loaders\LimitedScope::load($file);
+ }
+
+ if (!class_exists($class)) {
+ throw new InvalidPresenterException("Cannot load presenter '$name', class '$class' was not found in '$file'.");
+ }
+ }
+
+ // canonicalize presenter name
+ $realName = $this->unformatPresenterClass($class);
+ if ($name !== $realName) {
+ if ($this->caseSensitive) {
+ throw new InvalidPresenterException("Cannot load presenter '$name', case mismatch. Real name is '$realName'.");
+ } else {
+ $this->cache[$name] = array($class, $realName);
+ $name = $realName;
+ }
+ } else {
+ $this->cache[$name] = array($class, $realName);
+ }
+
+ return $class;
+ }
+
+
+
+ /**
+ * Formats presenter class name from its name.
+ * @param string
+ * @return string
+ */
+ public function formatPresenterClass($presenter)
+ {
+ /*5.2*return strtr($presenter, ':', '_') . 'Presenter';*/
+ return str_replace(':', 'Modification\\', $presenter) . 'Presenter';
+ }
+
+
+
+ /**
+ * Formats presenter name from class name.
+ * @param string
+ * @return string
+ */
+ public function unformatPresenterClass($class)
+ {
+ /*5.2*return strtr(substr($class, 0, -9), '_', ':');*/
+ return str_replace('Modification\\', ':', substr($class, 0, -9));
+ }
+
+
+
+ /**
+ * Formats presenter class file name.
+ * @param string
+ * @return string
+ */
+ public function formatPresenterFile($presenter)
+ {
+ $path = '/' . str_replace(':', 'Module/', $presenter);
+ return $this->baseDir . substr_replace($path, '/presenters', strrpos($path, '/'), 0) . 'Presenter.php';
+ }
+
+}
View
3 libs/Kdyby/Application/Routers/ExtendableRouter.php
@@ -9,10 +9,9 @@
/**
* Description of ExtendableRouter
*
- * @author hosiplan
+ * @author Filip Procházka <hosiplan@kdyby.org>
*/
class ExtendableRouter extends \Nette\Application\MultiRouter
{
}
-?>
View
62 libs/Kdyby/Application/Routers/SeoRouter.php
@@ -0,0 +1,62 @@
+<?php
+
+
+namespace Kdyby\Application;
+
+
+
+/**
+ * Description of SeoRouter
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class SeoRouter extends \Nette\Application\Route
+{
+
+ public function match(IHttpRequest $httpRequest)
+ {
+ $request = parent::match($httpRequest);
+
+ if( $request === NULL ){ return NULL; }
+
+ $params = $request->getParams();
+
+ $data = dibi::fetch(
+ 'SELECT [modul],[presenter] FROM %n', $this->table,
+ 'WHERE %n = %s', 'id', $params['id']
+ );
+
+ if( empty($data) ){ return NULL; }
+
+ return new PresenterRequest(
+ $data->modul.':'.$data->presenter,
+ $httpRequest->getMethod(),
+ $params,
+ $httpRequest->getPost(),
+ $httpRequest->getFiles(),
+ array('secured' => $httpRequest->isSecured())
+ );
+
+ }
+
+
+ public function constructUrl(PresenterRequest $httpRequest, IHttpRequest $context)
+ {
+
+ $actualParams = $httpRequest->getParams();
+
+ $data = dibi::fetch(
+ 'SELECT [uri],[lang] FROM %n', $this->table,
+ 'WHERE %n = %s', 'id', $actualParams['id']
+ );
+ if (empty($data)) return NULL;
+
+ $uri = $context->getUri()->basePath.$data['lang'].'/'.$actualParams['id'].'-'.$data['uri'];
+ //unset($actualParams['lang'], $actualParams['id'],$actualParams['uri']);
+ //$query = http_build_query($actualParams, '', '&');
+ //if ($query !== '') $uri .= '?' . $query;
+
+ return $uri;
+
+ }
+}
View
55 libs/Kdyby/Dependencies.php
@@ -0,0 +1,55 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of Dependencies
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class Dependencies extends \Nette\Object
+{
+
+ /**
+ * Package version
+ */
+ const VERSION = 10000; // 1.0.0
+
+ /**
+ * Unique key generated by system for specific extension
+ */
+ const DEP_KEY = NULL;
+
+ /**
+ * List of dependencies that must be met for appropriate behaviour
+ */
+ protected $dependencies = array(
+ //'extensionName:dependencyKey' => array('>=', 'version');
+ );
+
+
+
+ final public function getMissingDependencies()
+ {
+ $missing = array();
+
+ foreach( (array)$this->dependencies AS $extension => $version ){
+ if( !$this->isDependencyMet($depKey, $version) ){
+ $missing[$depKey] = $version;
+ }
+ }
+
+ return $missing;
+ }
+
+
+ final public function isDependencyMet($depKey, $version)
+ {
+
+ }
+
+}
View
18 libs/Kdyby/Hooks.php
@@ -0,0 +1,18 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+
+/**
+ * Description of Hooks
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+class Hooks extends \Nette\Object
+{
+
+}
View
28 libs/Kdyby/Loaders/AddonLoader.php
@@ -0,0 +1,28 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of AddonLoader
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class AddonLoader extends Dependencies implements IAddonLoader
+{
+
+ static $addonLoaders = array();
+
+ protected $addonClasses = array();
+
+
+
+ public function getAddon($addon)
+ {
+ return self::$addonLoaders[$addon];
+ }
+
+}
View
18 libs/Kdyby/Loaders/IAddonLoader.php
@@ -0,0 +1,18 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+interface IAddonLoader
+{
+
+ protected $addonClasses;
+
+}
View
18 libs/Kdyby/Loaders/IModificationLoader.php
@@ -0,0 +1,18 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+interface IModificationLoader
+{
+
+ protected $modificationClasses;
+
+}
View
115 libs/Kdyby/Loaders/KdybyLoader.php
@@ -1,28 +1,77 @@
<?php
+
namespace Kdyby;
+use Nette\Loaders\LimitedScope;
+
+
/**
* Description of KdybyLoader
*
- * @author hosiplan
+ * @author Filip Procházka <hosiplan@kdyby.org>
*/
-class KdybyLoader extends \Nette\Loaders\AutoLoader
+final class KdybyLoader extends \Nette\Loaders\AutoLoader
{
- /** @var NetteLoader */
+ /** @var KdybyLoader */
private static $instance;
/** @var array */
public $list = array(
- 'Kdyby\Application\ExtendableRouter' => '/Application/Routers/ExtendableRouter.php',
- 'Kdyby\Application\Kdyby' => '/Application/Kdyby.php',
+ 'kdyby\application\extendablerouter' => '/Application/Routers/ExtendableRouter.php',
+ 'kdyby\application\kdyby' => '/Application/Kdyby.php',
+ 'kdyby\application\presenterloader' => '/Application/PresenterLoader.php',
+ 'kdyby\basepresenter' => '/Presenters/BasePresenter.php',
+ 'kdyby\hooks' => '/Hooks.php',
);
+ /** @var array */
+ public $addons = array();
+
+ /** @var array */
+ private $addonsClasses = array();
+
+ /** @var int */
+ private $addonsCount = 0;
+
+
+ /** @var array */
+ public $modifications = array();
+
+ /** @var array */
+ private $modificationsClasses = array();
+
+ /** @var int */
+ private $modificationsCount = 0;
+
+
+
+ public function loadCache()
+ {
+ $c = $this->getCache();
+
+ if( isset($c['addons']) ){
+ $this->addonsClasses = $c['addons'];
+ }
+
+ if( isset($c['modifications']) ){
+ $this->modificationsClasses = $c['modifications'];
+ }
+ }
+
+
+ /**
+ * @return Nette\Caching\Cache
+ */
+ private function getCache()
+ {
+ return \Nette\Environment::getCache("KdybyLoader");
+ }
/**
* Returns singleton instance with lazy instantiation.
- * @return NetteLoader
+ * @return KdybyLoader
*/
public static function getInstance()
{
@@ -33,6 +82,49 @@ public static function getInstance()
}
+ public function loadAddon($addon)
+ {
+
+ }
+
+
+ public function loadModification($modification)
+ {
+
+ }
+
+
+ /**
+ * Appends providen classes to addons list
+ * @param array $addons
+ */
+ public function registerAddonClasses(array $classes)
+ {
+ $this->addonClasses += $classes;
+
+ if( count($this->addonClasses) != $this->addonsCount ){
+ $this->getCache()->save('addons', $this->addonClasses);
+
+ $this->addonsCount = count($this->addons);
+ }
+ }
+
+
+ /**
+ * Appends providen classes to modifications list
+ * @param array $modifications
+ */
+ public function registerModificationClasses(array $classes)
+ {
+ $this->modificationClasses += $classes;
+
+ if( count($this->modificationClasses) != $this->modificationsCount ){
+ $this->getCache()->save('modifications', $this->modificationClasses);
+
+ $this->modificationsCount = count($this->modifications);
+ }
+ }
+
/**
* Handles autoloading of classes or interfaces.
@@ -42,9 +134,18 @@ public static function getInstance()
public function tryLoad($type)
{
$type = ltrim(strtolower($type), '\\');
- if (isset($this->list[$type])) {
+
+ if( isset($this->list[$type]) ){
LimitedScope::load(KDYBY_DIR . $this->list[$type]);
self::$count++;
+
+ } elseif( isset($this->addons[$type]) ){
+ LimitedScope::load(APP_DIR . $this->addonsClasses[$type]);
+ self::$count++;
+
+ } elseif( isset($this->modifications[$type]) ){
+ LimitedScope::load(KDYBY_DIR . $this->modificationsClasses[$type]);
+ self::$count++;
}
}
View
28 libs/Kdyby/Loaders/ModificationLoader.php
@@ -0,0 +1,28 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of ModificationLoader
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class ModificationLoader extends AddonLoader implements IModificationLoader
+{
+
+ static $modificationLoaders = array();
+
+ protected $modificationClasses = array();
+
+
+
+ public function getModification($modification)
+ {
+ return self::$modificationLoaders[$modification];
+ }
+
+}
View
17 libs/Kdyby/Models/BaseModel.php
@@ -0,0 +1,17 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of BaseModel
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class BaseModel extends \Nette\Object
+{
+
+}
View
23 libs/Kdyby/Presenters/AdminPresenter.php
@@ -0,0 +1,23 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of BasePresenter
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class AdminPresenter extends BasePresenter
+{
+
+ /** @persistent */
+ public $node;
+
+
+
+
+}
View
23 libs/Kdyby/Presenters/BasePresenter.php
@@ -0,0 +1,23 @@
+<?php
+
+
+namespace Kdyby;
+
+
+
+
+/**
+ * Description of BasePresenter
+ *
+ * @author Filip Procházka <hosiplan@kdyby.org>
+ */
+abstract class BasePresenter extends \Nette\Application\Presenter
+{
+
+ /** @persistent */
+ public $node;
+
+
+
+
+}
View
46 libs/Kdyby/loader.php
@@ -14,12 +14,6 @@
require LIBS_DIR . '/dibi/dibi.php';
-if( constant("NETTE") !== TRUE ){
- throw new \Exception("Nette initialization is first!");
-}
-
-
-
/**
* Load and configure F-CMS Kdyby
*/
@@ -28,44 +22,28 @@
define('KDYBY_DIR', __DIR__);
-// Autoloader for classes
+// Step 3: configuring Kdyby
+// 3a) load AutoLoader & some other stuff
require_once KDYBY_DIR . '/Loaders/KdybyLoader.php';
+require_once KDYBY_DIR . '/shortcuts.php';
+// 3b) Register Kdyby autoloader
\Kdyby\KdybyLoader::getInstance()->register();
-
-
-// Step : Override Nette services
+// 3c) Override Nette Application Service
$locator = Environment::getServiceLocator();
-
-// Nette\Application\Application override
$locator->addService('Nette\Application\Application', 'Kdyby\Application\Kdyby');
-// Nette\Application\IRouter override
-$locator->addService('Nette\Application\IRouter', 'Kdyby\Application\ExtendableRouter');
-
-// Nette\Security\IAuthenticator
-//$locator->addService("Nette\Security\IAuthenticator", "");
-
-
-// Step 2: Configure environment
-// 2a) enable Nette\Debug for better exception and error visualisation
+// Step 4: Configure Environment
+// 4a) Enable Nette\Debug for better exception and error visualisation
Debug::enable();
Debug::$strictMode = True;
-// 2b) load configuration from config.ini file
-Environment::loadConfig();
-
-// Step 3: Configure application
-// 3a) get and setup a front controller
-$application = Environment::getApplication();
-$application->errorPresenter = 'Error';
-//$application->catchExceptions = TRUE;
+// 4b) Load configuration from app/config.ini file
+Environment::loadConfig(APP_DIR.'/config.ini');
-
-$application->register();
-
-// Step : Run the application!
-$application->run();
+// Step 6: Application
+// 4a) Get front controller
+$application = Environment::getApplication();
View
6 libs/Kdyby/shortcuts.php
@@ -0,0 +1,6 @@
+<?php
+
+function hook($bearer, $name, $defaultCallback, $args = array(), $multiple = False)
+{ // echo hook($this, 'someName', callback($this, 'myfunc'), array('damnyou'));
+ return ;
+}

0 comments on commit c796ef7

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