Permalink
Browse files

Added the Controller & History.

Also added the SymfonyServiceContainer.

Fixed a few tests.
  • Loading branch information...
enyo committed Jul 14, 2011
1 parent 8b7d49b commit 6dd1d842c303535cd80d7fdd422560e6d542dd66
Showing with 4,172 additions and 85 deletions.
  1. +422 −0 library/Controller/Controller.php
  2. +30 −0 library/Controller/ControllerExceptions.php
  3. +106 −0 library/Controller/ControllerFactory.php
  4. +103 −0 library/Controller/LocationDelegate.php
  5. +25 −0 library/Controller/LocationDelegateDomainProvider.php
  6. +49 −0 library/Controller/MessageDelegate.php
  7. +98 −71 library/Dao/Dao.php
  8. +0 −1 library/Dao/DaoKeyListIterator.php
  9. +161 −0 library/History/History.php
  10. +108 −0 library/SymfonyServiceContainer/services.xsd
  11. +359 −0 library/SymfonyServiceContainer/sfServiceContainer.php
  12. +49 −0 library/SymfonyServiceContainer/sfServiceContainerAutoloader.php
  13. +351 −0 library/SymfonyServiceContainer/sfServiceContainerBuilder.php
  14. +45 −0 library/SymfonyServiceContainer/sfServiceContainerDumper.php
  15. +231 −0 library/SymfonyServiceContainer/sfServiceContainerDumperGraphviz.php
  16. +23 −0 library/SymfonyServiceContainer/sfServiceContainerDumperInterface.php
  17. +359 −0 library/SymfonyServiceContainer/sfServiceContainerDumperPhp.php
  18. +213 −0 library/SymfonyServiceContainer/sfServiceContainerDumperXml.php
  19. +201 −0 library/SymfonyServiceContainer/sfServiceContainerDumperYaml.php
  20. +39 −0 library/SymfonyServiceContainer/sfServiceContainerInterface.php
  21. +113 −0 library/SymfonyServiceContainer/sfServiceContainerLoader.php
  22. +101 −0 library/SymfonyServiceContainer/sfServiceContainerLoaderFile.php
  23. +50 −0 library/SymfonyServiceContainer/sfServiceContainerLoaderFileIni.php
  24. +282 −0 library/SymfonyServiceContainer/sfServiceContainerLoaderFileXml.php
  25. +216 −0 library/SymfonyServiceContainer/sfServiceContainerLoaderFileYaml.php
  26. +23 −0 library/SymfonyServiceContainer/sfServiceContainerLoaderInterface.php
  27. +243 −0 library/SymfonyServiceContainer/sfServiceDefinition.php
  28. +44 −0 library/SymfonyServiceContainer/sfServiceParameter.php
  29. +44 −0 library/SymfonyServiceContainer/sfServiceReference.php
  30. +73 −0 library/SymfonyServiceContainer/sfServiceSimpleXMLElement.php
  31. +0 −2 phpunit/library/Config/ConfigTest.php
  32. +0 −2 phpunit/library/File/ImageFileTest.php
  33. +6 −3 phpunit/library/Record/Record.CoerceTest.php
  34. +4 −4 phpunit/library/Record/Record.LazyLoading.php
  35. +0 −2 phpunit/library/Record/RecordTest.php
  36. +1 −0 phpunit/setup.php

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * This file contains all ControllerExceptions
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+
+/**
+ * The ControllerException
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+class ControllerException extends Exception {
+
+}
+
+/**
+ * Is thrown on errors.
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+class Error extends ControllerException {
+
+}
+
@@ -0,0 +1,106 @@
+<?php
+
+/**
+ * This file contains the ControllerFactory definition.
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+
+/**
+ * Thrown when a Controller is not found.
+ */
+class ControllerFactoryException extends Exception {
+
+}
+
+/**
+ * The ControllerFactory is the way to get a Controller for a site.
+ * It handles dependency injection and whatnot.
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2009, Matthias Loitsch
+ * @package Controller
+ */
+abstract class ControllerFactory {
+
+ /**
+ * @var sfServiceContainer
+ */
+ protected $container;
+ /**
+ * Defines where the controllers reside.
+ * @var string
+ */
+ protected $controllerRootPath;
+ /**
+ * @var array
+ */
+ protected $availableAutowiredServices = array();
+
+ /**
+ * @param sfServiceContainer $container
+ * @param array $availableAutowiredServices A list of services the controller factory should autowire (dependency injection).
+ * @param string $controllerRootPath if you do not set it in the constructor,
+ * make sure you set it via setControllerRootPath
+ * before calling get() because this will result
+ * in an error otherwise.
+ */
+ public function __construct($container, $availableAutowiredServices = array(), $controllerRootPath = null) {
+ $this->container = $container;
+ $this->availableAutowiredServices = $availableAutowiredServices;
+ $this->setControllerRootPath($controllerRootPath);
+ }
+
+ /**
+ * Has to be called before get()
+ * @param string $path
+ */
+ public function setControllerRootPath($path) {
+ $this->controllerRootPath = $path;
+ }
+
+ /**
+ * Returns a specific controller, passing on all the objects the Factory got in the constructor.
+ *
+ * This method also takes care of dependency injections. If it finds a method
+ * called setShopDaoFactory() on the siteController for instance, it injects the factory.
+ *
+ * @param string $controllerName
+ * @param bool $skipInitialization If true, neither authorize(), initialize() nor validate() is called on the Controller.
+ * @return Controller
+ */
+ public function get($controllerName, $skipInitialization = false) {
+ if ( ! $this->controllerRootPath) trigger_error('The controller root path was not defined.', E_USER_ERROR);
+
+ $className = $controllerName . 'Controller';
+
+ $classUri = $this->controllerRootPath . $className . '.php';
+
+ if ( ! file_exists($classUri)) throw new ControllerFactoryException('File for controller does not exist.');
+
+ include $classUri;
+
+ if ( ! class_exists($className, false)) throw new ControllerFactoryException('File for controller did exist, but class was not defined.');
+
+ $siteController = $this->getController($className);
+
+ // Dependency injections
+ foreach ($this->availableAutowiredServices as $service) {
+ if (property_exists($siteController, $service)) {
+ $siteController->$service = $this->container->$service;
+ }
+ }
+
+ return $siteController;
+ }
+
+
+ /**
+ * @param string $className
+ * @return Controller
+ */
+ abstract protected function getController($className);
+
+}
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * This file contains the LocationDelegate interface definition.
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+
+/**
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2009, Matthias Loitsch
+ * @package Controller
+ */
+interface LocationDelegate {
+
+ /**
+ * @param Controller $controller
+ */
+ public function setController(Controller $controller);
+
+ /**
+ * A call to this could look like this:
+ *
+ * getUrl('address', 'delete', 2, array('confirmed' => true))
+ *
+ * This would result in:
+ * /address/delete/2?confirmed=true
+ * or
+ * ?controller=address&action=delete/2&confirmed=true
+ *
+ * If you want to redirect to the current url, use:
+ * getUrl()
+ * or if you want to pass get parameters to the current url, use:
+ * getUrl(null, array('confirmed' => true))
+ *
+ * @param string $targetControllerName if null, the current url is used.
+ * @param string,... $action A list of possible action strings.
+ * @param array $get
+ */
+ public function getUrl($targetControllerName = null);
+
+ /**
+ * The same as getUrl, but without session ID information, and with
+ * http://linktosite/ prepended.
+ *
+ * @param string $targetControllerName if null, the current url is used.
+ * @param string,... $action A list of possible action strings.
+ * @param array $get
+ * @see getUrl()
+ */
+ public function getLink($targetControllerName = null);
+
+ /**
+ * Uses getUrl to get the url, and redirect there.
+ *
+ * @param string $targetControllerName if null, the current url is used.
+ * @param [string..] $action A list of possible action strings.
+ * @param array $get
+ * @uses getUrl()
+ */
+ public function redirect($targetControllerName = null);
+
+ /**
+ * The same as redirect, but adds an encrypted error as get variable.
+ *
+ * @param string $error
+ * @param string $targetControllerName if null, the current url is used.
+ * @param [string..] $action A list of possible action strings.
+ * @param array $get
+ */
+ public function redirectWithError($error, $targetControllerName = null);
+
+ /**
+ * Returns an url error if set.
+ * @return string null if none
+ */
+ public function getUrlErrorMessage();
+
+ /**
+ * Returns an url success if set.
+ * @return string null if none
+ */
+ public function getUrlSuccessMessage();
+
+ /**
+ * The same as redirect, but adds an encrypted success as get variable.
+ *
+ * @param string $success
+ * @param string $targetControllerName if null, the current url is used.
+ * @param [string..] $action A list of possible action strings.
+ * @param array $get
+ */
+ public function redirectWithSuccess($success, $targetControllerName = null);
+
+ /**
+ * Redirects to url, and exits.
+ *
+ * @param string $url
+ */
+ public function redirectToUrl($url);
+}
@@ -0,0 +1,25 @@
+<?php
+/**
+ * This file contains the LocationDomainProviderInterface definition.
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2010, I-Netcompany
+ * @package Controller
+ */
+
+/**
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2009, Matthias Loitsch
+ * @package Controller
+ */
+interface LocationDelegateDomainProvider {
+
+ /**
+ * This method should cache the domain, so calling it multiple times does not
+ * impact performance.
+ *
+ * @return string the domain. Eg: www.shop.com:8080
+ */
+ public function getDomain();
+
+}
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * The file for the message delegate
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2011, Matthias Loitsch
+ * @package Controller
+ * @subpackage Message
+ */
+
+/**
+ * The MessageDelegate ist used to store messages that should appear on screen.
+ *
+ * @author Matthias Loitsch <matthias@loitsch.com>
+ * @copyright Copyright (c) 2011, Matthias Loitsch
+ * @package Controller
+ * @subpackage Message
+ */
+interface MessageDelegate {
+
+ /**
+ * If you pass an array, every value will be added as message. This way
+ * you can pass multiple messages at once.
+ *
+ * @param string|array $message
+ */
+ public function addErrorMessage($message);
+
+ /**
+ * If you pass an array, every value will be added as message. This way
+ * you can pass multiple messages at once.
+ *
+ * @param string|array $message
+ */
+ public function addSuccessMessage($message);
+
+ /**
+ * @return array
+ */
+ public function getErrorMessages();
+
+ /**
+ * @return array
+ */
+ public function getSuccessMessages();
+
+}
+
Oops, something went wrong.

0 comments on commit 6dd1d84

Please sign in to comment.