This repository has been archived by the owner on Aug 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86ceccb
commit c796ef7
Showing
24 changed files
with
696 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
nbproject | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<Files ".gitignore"> | ||
Order Allow,Deny | ||
Deny from all | ||
</Files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
{block content} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.