Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
hardcoding :)
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Jul 30, 2010
1 parent 86ceccb commit c796ef7
Show file tree
Hide file tree
Showing 24 changed files with 696 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nbproject
tests
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Files ".gitignore">
Order Allow,Deny
Deny from all
</Files>
13 changes: 12 additions & 1 deletion app/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions app/modifications/Page/loader.php
Original file line number Diff line number Diff line change
@@ -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();




}
17 changes: 17 additions & 0 deletions app/modifications/Page/presenters/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php


namespace Kdyby\Modification\Page;




/**
* Description of Page
*
* @author Filip Procházka <hosiplan@kdyby.org>
*/
class Page extends \Kdyby\BasePresenter
{

}
17 changes: 17 additions & 0 deletions app/modifications/Page/presenters/PageAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php


namespace Kdyby\Modification\Page;




/**
* Description of PageAdmin
*
* @author Filip Procházka <hosiplan@kdyby.org>
*/
class PageAdmin extends \Kdyby\AdminPresenter
{

}
2 changes: 2 additions & 0 deletions app/modifications/Page/templates/Page/default.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

{block content}
6 changes: 6 additions & 0 deletions document_root/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

// load bootstrap file
require LIBS_DIR . '/Kdyby/loader.php';

// 6b) Hook callbacks
$application->hook();

// 6c) Run the application!
$application->run();
73 changes: 68 additions & 5 deletions libs/Kdyby/Application/Kdyby.php
Original file line number Diff line number Diff line change
@@ -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'));
}

}
?>
129 changes: 129 additions & 0 deletions libs/Kdyby/Application/PresenterLoader.php
Original file line number Diff line number Diff line change
@@ -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';
}

}
3 changes: 1 addition & 2 deletions libs/Kdyby/Application/Routers/ExtendableRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
/**
* Description of ExtendableRouter
*
* @author hosiplan
* @author Filip Procházka <hosiplan@kdyby.org>
*/
class ExtendableRouter extends \Nette\Application\MultiRouter
{

}
?>
Loading

0 comments on commit c796ef7

Please sign in to comment.