Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kolinger/square-framework
base: 8ebbd1e33d
...
head fork: kolinger/square-framework
compare: d67a12a5b4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
145 Application/UI/Presenter.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
+namespace Square\Application\UI;
+
+use Nette\Reflection\Property;
+use Nette\Reflection\ClassType;
+
+
+
+/**
+ * @author Tomáš Kolinger <tomas@kolinger.name>
+ */
+class Presenter extends \Nette\Application\UI\Presenter
+{
+
+ /**
+ * @var array
+ */
+ private $autowire = array();
+
+ /**
+ * @var \Nette\DI\Container
+ */
+ private $serviceLocator;
+
+
+
+ /**
+ * @param \Nette\DI\Container $dic
+ * @throws \Nette\InvalidStateException
+ * @throws \Nette\MemberAccessException
+ * @throws \Nette\DI\MissingServiceException
+ */
+ public function injectProperties(\Nette\DI\Container $dic)
+ {
+ if (!$this instanceof \Nette\Application\UI\PresenterComponent) {
+ throw new \Nette\MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
+ }
+
+ $this->serviceLocator = $dic;
+ $cache = new \Nette\Caching\Cache($this->serviceLocator->getByType('Nette\Caching\IStorage'), 'Presenter.Autowire');
+ if (($this->autowire = $cache->load($presenterClass = get_class($this))) === NULL) {
+ $this->autowire = array();
+
+ $rc = ClassType::from($this);
+ $ignore = class_parents('Nette\Application\UI\Presenter') + array('ui' => 'Nette\Application\UI\Presenter');
+ foreach ($rc->getProperties(Property::IS_PUBLIC | Property::IS_PROTECTED) as $prop) {
+ /** @var Property $prop */
+ if (in_array($prop->getDeclaringClass()->getName(), $ignore) || !$prop->hasAnnotation('autowire')) {
+ continue;
+ }
+
+ if (!$type = ltrim($prop->getAnnotation('var'), '\\')) {
+ throw new \Nette\InvalidStateException("Missing annotation @var with typehint on $prop.");
+ }
+
+ if (!class_exists($type) && !interface_exists($type)) {
+ if (substr($prop->getAnnotation('var'), 0, 1) === '\\') {
+ throw new \Nette\InvalidStateException("Class \"$type\" was not found, please check the typehint on $prop");
+ }
+
+ if (!class_exists($type = $prop->getDeclaringClass()->getNamespaceName() . '\\' . $type) && !interface_exists($type)) {
+ throw new \Nette\InvalidStateException("Neither class \"" . $prop->getAnnotation('var') . "\" or \"$type\" was found, please check the typehint on $prop");
+ }
+ }
+
+ if (empty($this->serviceLocator->classes[strtolower($type)])) {
+ throw new \Nette\DI\MissingServiceException("Service of type \"$type\" not found for $prop.");
+ }
+
+ // unset property to pass control to __set() and __get()
+ unset($this->{$prop->getName()});
+ $this->autowire[$prop->getName()] = array(
+ 'value' => NULL,
+ 'type' => ClassType::from($type)->getName()
+ );
+ }
+
+ $files = array_map(function ($class) {
+ return ClassType::from($class)->getFileName();
+ }, array_diff(array_values(class_parents($presenterClass) + array('me' => $presenterClass)), $ignore));
+
+ $cache->save($presenterClass, $this->autowire, array(
+ $cache::FILES => $files,
+ ));
+
+ } else {
+ foreach ($this->autowire as $propName => $tmp) {
+ unset($this->{$propName});
+ }
+ }
+ }
+
+
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @throws \Nette\MemberAccessException
+ * @return mixed
+ */
+ public function __set($name, $value)
+ {
+ if (!isset($this->autowire[$name])) {
+ return parent::__set($name, $value);
+
+ } elseif ($this->autowire[$name]['value']) {
+ throw new \Nette\MemberAccessException("Property \$$name has already been set.");
+
+ } elseif (!$value instanceof $this->autowire[$name]['type']) {
+ throw new \Nette\MemberAccessException("Property \$$name must be an instance of " . $this->autowire[$name]['type'] . ".");
+ }
+
+ return $this->autowire[$name]['value'] = $value;
+ }
+
+
+
+ /**
+ * @param $name
+ * @throws \Nette\MemberAccessException
+ * @return mixed
+ */
+ public function &__get($name)
+ {
+ if (!isset($this->autowire[$name])) {
+ return parent::__get($name);
+ }
+
+ if (empty($this->autowire[$name]['value'])) {
+ $this->autowire[$name]['value'] = $this->serviceLocator->getByType($this->autowire[$name]['type']);
+ }
+
+ return $this->autowire[$name]['value'];
+ }
+
+}
View
14 Config/Configurator.php
@@ -1,12 +1,23 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Config;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*/
class Configurator extends \Nette\Config\Configurator
{
+
/**
* @return \Nette\Config\Compiler
*/
@@ -19,4 +30,5 @@ protected function createCompiler()
return $compiler;
}
+
}
View
32 Console/Extension.php
@@ -1,19 +1,34 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Console;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*/
class Extension extends \Nette\Config\CompilerExtension
{
- /** @var array */
+
+ /**
+ * @var array
+ */
private $defaults = array(
'name' => 'Square Command Line Interface',
'version' => '1.0',
'catchExceptions' => TRUE,
);
+
+
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
@@ -35,8 +50,10 @@ public function loadConfiguration()
->addSetup('offsetSet', array(NULL, $this->prefix('@router')));
}
+
+
/**
- * @param \Nette\DI\Container
+ * @param \Nette\DI\Container $container
* @return \Symfony\Component\Console\Helper\HelperSet
*/
public static function createHelperSet(\Nette\DI\Container $container)
@@ -51,10 +68,12 @@ public static function createHelperSet(\Nette\DI\Container $container)
return $helperSet;
}
+
+
/**
- * @param array
- * @param \Nette\DI\Container
- * @param \Symfony\Component\Console\Helper\HelperSet
+ * @param array $config
+ * @param \Nette\DI\Container $container
+ * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
* @return \Symfony\Component\Console\Application
*/
public static function createApplication(array $config, \Nette\DI\Container $container, \Symfony\Component\Console\Helper\HelperSet $helperSet)
@@ -70,4 +89,5 @@ public static function createApplication(array $config, \Nette\DI\Container $con
return $application;
}
+
}
View
36 Console/Router.php
@@ -1,26 +1,43 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Console;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*/
class Router extends \Nette\Object implements \Nette\Application\IRouter
{
- /** @var \Symfony\Component\Console\Application */
+
+ /**
+ * @var \Symfony\Component\Console\Application
+ */
private $console;
+
+
/**
- * @param \Symfony\Component\Console\Application
+ * @param \Symfony\Component\Console\Application $console
*/
public function __construct(\Symfony\Component\Console\Application $console)
{
$this->console = $console;
}
+
+
/**
- * @param \Nette\Http\IRequest
- * @return \Nette\Http\IRequest|NULL
+ * @param \Nette\Http\IRequest $httpRequest
+ * @return \Nette\Application\Request|NULL
*/
public function match(\Nette\Http\IRequest $httpRequest)
{
@@ -30,13 +47,16 @@ public function match(\Nette\Http\IRequest $httpRequest)
return NULL;
}
+
+
/**
- * @param \Nette\Application\Request
- * @param \Nette\Http\Url
- * @return string|NULL
+ * @param \Nette\Application\Request $appRequest
+ * @param \Nette\Http\Url $refUrl
+ * @return NULL|string
*/
public function constructUrl(\Nette\Application\Request $appRequest, \Nette\Http\Url $refUrl)
{
return NULL;
}
+
}
View
58 Doctrine/Cache.php
@@ -1,26 +1,43 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Doctrine;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*/
class Cache extends \Doctrine\Common\Cache\CacheProvider
{
- /** @var \Nette\Caching\IStorage */
+
+ /**
+ * @var \Nette\Caching\IStorage
+ */
private $storage;
+
+
/**
- * @param \Nette\Caching\IStorage
+ * @param \Nette\Caching\IStorage $storage
*/
public function __construct(\Nette\Caching\IStorage $storage)
{
$this->storage = new \Nette\Caching\Cache($storage, 'Square.Doctrine');
}
+
+
/**
- * @param string
- * @return FALSE|string
+ * @param string $id
+ * @return string|FALSE
*/
protected function doFetch($id)
{
@@ -31,9 +48,11 @@ protected function doFetch($id)
return FALSE;
}
+
+
/**
- * @param string
- * @return boolean
+ * @param string $id
+ * @return bool
*/
protected function doContains($id)
{
@@ -43,11 +62,13 @@ protected function doContains($id)
return FALSE;
}
+
+
/**
- * @param string
- * @param string
- * @param boolean
- * @return boolean
+ * @param string $id
+ * @param string $data
+ * @param bool $lifeTime
+ * @return bool
*/
protected function doSave($id, $data, $lifeTime = FALSE)
{
@@ -63,9 +84,11 @@ protected function doSave($id, $data, $lifeTime = FALSE)
return TRUE;
}
+
+
/**
- * @param string
- * @return boolean
+ * @param string $id
+ * @return bool
*/
protected function doDelete($id)
{
@@ -73,8 +96,10 @@ protected function doDelete($id)
return TRUE;
}
+
+
/**
- * @return boolean
+ * @return bool
*/
protected function doFlush()
{
@@ -84,11 +109,14 @@ protected function doFlush()
return TRUE;
}
+
+
/**
- * @return NULL|array
+ * @return array|null
*/
protected function doGetStats()
{
return NULL;
}
+
}
View
34 Doctrine/Extension.php
@@ -1,13 +1,26 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Doctrine;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*/
class Extension extends \Nette\Config\CompilerExtension
{
- /** @var array */
+
+ /**
+ * @var array
+ */
private $defaults = array(
'entitiesDirs' => array('%appDir%'),
'proxyDir' => '%appDir%/proxies',
@@ -24,6 +37,8 @@ class Extension extends \Nette\Config\CompilerExtension
),
);
+
+
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
@@ -79,10 +94,12 @@ public function loadConfiguration()
->addTag('consoleCommand');
}
+
+
/**
- * @param array
- * @param Logger
- * @param \Doctrine\ORM\Configuration
+ * @param array $config
+ * @param Logger $logger
+ * @param \Doctrine\ORM\Configuration $configuration
* @return \Doctrine\DBAL\Connection
*/
public static function createConnection(array $config, Logger $logger, \Doctrine\ORM\Configuration $configuration)
@@ -107,9 +124,11 @@ public static function createConnection(array $config, Logger $logger, \Doctrine
return $connection;
}
+
+
/**
- * @param array
- * @param \Nette\Caching\Cache
+ * @param array $entitiesDirs
+ * @param Cache $cache
* @return \Doctrine\ORM\Mapping\Driver\AnnotationDriver
*/
public static function createAnnotationDriver(array $entitiesDirs, Cache $cache)
@@ -122,4 +141,5 @@ public static function createAnnotationDriver(array $entitiesDirs, Cache $cache)
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedReader, $entitiesDirs);
}
+
}
View
8 Doctrine/Logger.php
@@ -1,5 +1,13 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Doctrine;
use Nette\Diagnostics\Debugger,
View
24 Model/Entity.php
@@ -1,18 +1,29 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Model;
use Doctrine\ORM\Mapping as orm;
+
+
/**
* @orm\MappedSuperclass
*
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*
* @property-read int $id
*/
abstract class Entity extends \Nette\Object
{
+
/**
* @orm\Id
* @orm\GeneratedValue
@@ -22,17 +33,21 @@
*/
private $id;
+
+
/**
- * @return string
+ * @return int
*/
public function getId()
{
return $this->id;
}
+
+
/**
- * @param string
- * @return NULL|string
+ * @param string $string
+ * @return null|string
*/
protected static function normalizeString($string)
{
@@ -42,4 +57,5 @@ protected static function normalizeString($string)
}
return $string;
}
+
}
View
48 Model/Facade.php
@@ -1,24 +1,41 @@
<?php
+/**
+ * This file is part of the Square CMS
+ *
+ * Copyright (c) 2011, 2012 Tomáš Kolinger <tomas@kolinger.name>
+ *
+ * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
+ */
+
namespace Square\Model;
+
+
/**
- * @author Tomáš Kolinger
+ * @author Tomáš Kolinger <tomas@kolinger.name>
*
* @property-read \Doctrine\ORM\EntityManager $entityManager
* @property-read \Doctrine\ORM\EntityRepository $repository
*/
abstract class Facade extends \Nette\Object
{
+
const FLUSH = true;
const WITHOUT_FLUSH = false;
- /** @var \Doctrine\ORM\EntityManager */
+ /**
+ * @var \Doctrine\ORM\EntityManager
+ */
private $entityManager;
- /** @var \Doctrine\ORM\EntityRepository */
+ /**
+ * @var \Doctrine\ORM\EntityRepository
+ */
private $repository;
+
+
/**
* @param \Doctrine\ORM\EntityRepository
* @param \Doctrine\ORM\EntityManager
@@ -29,6 +46,8 @@ public function __construct(\Doctrine\ORM\EntityRepository $repository, \Doctrin
$this->repository = $repository;
}
+
+
/**
* @return \Doctrine\ORM\EntityManager
*/
@@ -37,6 +56,8 @@ public function getEntityManager()
return $this->entityManager;
}
+
+
/**
* @return \Doctrine\ORM\EntityRepository
*/
@@ -45,6 +66,8 @@ public function getRepository()
return $this->repository;
}
+
+
/**
* @return object
*/
@@ -55,9 +78,11 @@ public function create()
return $entity;
}
+
+
/**
- * @param object
- * @param boolean
+ * @param object $entity
+ * @param boolean $flush
*/
public function save($entity, $flush = self::FLUSH)
{
@@ -71,9 +96,11 @@ public function save($entity, $flush = self::FLUSH)
// }
}
+
+
/**
- * @param object
- * @param boolean
+ * @param object $entity
+ * @param boolean $flush
*/
public function remove($entity, $flush = self::FLUSH)
{
@@ -87,6 +114,8 @@ public function remove($entity, $flush = self::FLUSH)
// }
}
+
+
/**
* @return array
*/
@@ -95,12 +124,15 @@ public function findAll()
return $this->repository->findAll();
}
+
+
/**
- * @param string
+ * @param string $alias
* @return \Doctrine\ORM\QueryBuilder
*/
protected function createQueryBuilder($alias)
{
return $this->repository->createQueryBuilder($alias);
}
+
}

No commit comments for this range

Something went wrong with that request. Please try again.