Permalink
Browse files

hi

  • Loading branch information...
alganet committed Feb 18, 2012
0 parents commit 17fa81c8d89ca939a99ed25cf0f7f782b6383965
Showing with 2,968 additions and 0 deletions.
  1. +7 −0 config/app.ini
  2. +9 −0 config/config.ini
  3. +8 −0 config/router.ini
  4. +4 −0 config/template.ini
  5. +209 −0 library/Respect/Config/Container.php
  6. +181 −0 library/Respect/Config/Instantiator.php
  7. +55 −0 library/Respect/Loader.php
  8. +107 −0 library/Respect/Rest/Request.php
  9. +9 −0 library/Respect/Rest/Routable.php
  10. +192 −0 library/Respect/Rest/Router.php
  11. +146 −0 library/Respect/Rest/Routes/AbstractRoute.php
  12. +44 −0 library/Respect/Rest/Routes/Callback.php
  13. +56 −0 library/Respect/Rest/Routes/ClassName.php
  14. +48 −0 library/Respect/Rest/Routes/Factory.php
  15. +42 −0 library/Respect/Rest/Routes/Instance.php
  16. +37 −0 library/Respect/Rest/Routes/StaticValue.php
  17. +97 −0 library/Respect/Rest/Routines/AbstractAccept.php
  18. +23 −0 library/Respect/Rest/Routines/AbstractRoutine.php
  19. +30 −0 library/Respect/Rest/Routines/AbstractSyncedRoutine.php
  20. +24 −0 library/Respect/Rest/Routines/Accept.php
  21. +9 −0 library/Respect/Rest/Routines/AcceptCharset.php
  22. +10 −0 library/Respect/Rest/Routines/AcceptEncoding.php
  23. +29 −0 library/Respect/Rest/Routines/AcceptLanguage.php
  24. +16 −0 library/Respect/Rest/Routines/By.php
  25. +52 −0 library/Respect/Rest/Routines/ContentType.php
  26. +32 −0 library/Respect/Rest/Routines/LastModified.php
  27. +10 −0 library/Respect/Rest/Routines/ParamSynced.php
  28. +12 −0 library/Respect/Rest/Routines/ProxyableBy.php
  29. +12 −0 library/Respect/Rest/Routines/ProxyableThrough.php
  30. +12 −0 library/Respect/Rest/Routines/ProxyableWhen.php
  31. +17 −0 library/Respect/Rest/Routines/Through.php
  32. +9 −0 library/Respect/Rest/Routines/Unique.php
  33. +16 −0 library/Respect/Rest/Routines/When.php
  34. +48 −0 library/Respect/Template/Adapter.php
  35. +32 −0 library/Respect/Template/Adapters/A.php
  36. +76 −0 library/Respect/Template/Adapters/AbstractAdapter.php
  37. +16 −0 library/Respect/Template/Adapters/Dom.php
  38. +24 −0 library/Respect/Template/Adapters/HtmlElement.php
  39. +24 −0 library/Respect/Template/Adapters/String.php
  40. +50 −0 library/Respect/Template/Adapters/Traversable.php
  41. +36 −0 library/Respect/Template/Decorators/AbstractDecorator.php
  42. +14 −0 library/Respect/Template/Decorators/Append.php
  43. +17 −0 library/Respect/Template/Decorators/Clean.php
  44. +15 −0 library/Respect/Template/Decorators/CleanAppend.php
  45. +16 −0 library/Respect/Template/Decorators/Replace.php
  46. +89 −0 library/Respect/Template/Document.php
  47. +81 −0 library/Respect/Template/Html.php
  48. +60 −0 library/Respect/Template/HtmlElement.php
  49. +43 −0 library/Respect/Template/Query.php
  50. +23 −0 library/Resplendor/Application.php
  51. +13 −0 library/Resplendor/Controllers/Index.php
  52. +146 −0 library/Zend/Dom/Css2Xpath.php
  53. +36 −0 library/Zend/Dom/Exception.php
  54. +37 −0 library/Zend/Dom/Exception/RuntimeException.php
  55. +188 −0 library/Zend/Dom/NodeList.php
  56. +298 −0 library/Zend/Dom/Query.php
  57. +9 −0 public/index.php
  58. +13 −0 templates/main.html
@@ -0,0 +1,7 @@
+;This is the only file you have to edit to tweak the application!
+
+;Application settings
+virtual_host = /resplendor/public/index.php
+
+;Routes for every controller
+routes[] = [any, /, Resplendor\Controllers\Index]
@@ -0,0 +1,9 @@
+;You do not need to edit this file unless you know what you're doing!
+
+;This file is responsible for loading every other
+;config file in order.
+
+[container Respect\Config\Container]
+loadFile[] = 'config/app.ini'
+loadFile[] = 'config/router.ini'
+loadFile[] = 'config/template.ini'
@@ -0,0 +1,8 @@
+;You do not need to edit this file unless you know what you're doing!
+
+[request Respect\Rest\Request]
+
+[router Respect\Rest\Router]
+virtualHost = [virtual_host]
+autoDispatched = false
+classRoute = [routes]
@@ -0,0 +1,4 @@
+;You do not need to edit this file unless you know what you're doing!
+
+[template Respect\Template\Html]
+templateFileOrString = "templates/main.html"
@@ -0,0 +1,209 @@
+<?php
+
+namespace Respect\Config;
+
+use UnexpectedValueException as Value;
+use InvalidArgumentException as Argument;
+use ArrayObject;
+
+class Container extends ArrayObject
+{
+
+ public function __construct($configurator=null)
+ {
+ if (is_null($configurator))
+ return;
+
+ if (is_array($configurator))
+ return $this->loadArray($configurator);
+
+ if (file_exists($configurator) && is_file($configurator))
+ return $this->loadFile($configurator);
+
+ if (is_string($configurator))
+ return $this->loadString($configurator);
+
+ throw new Argument("Invalid input. Must be a valid file or array");
+ }
+
+ public function __isset($name)
+ {
+ return parent::offsetExists($name);
+ }
+
+ public function getItem($name, $raw=false)
+ {
+ if (!isset($this[$name]))
+ throw new Argument("Item $name not found");
+
+ if ($raw || !is_callable($this[$name]))
+ return $this[$name];
+
+ return $this->lazyLoad($name);
+ }
+
+ public function loadString($configurator)
+ {
+ $iniData = parse_ini_string($configurator, true);
+ if (false === $iniData || count($iniData) == 0)
+ throw new Argument("Invalid configuration string");
+
+ return $this->loadArray($iniData);
+ }
+
+ public function loadFile($configurator)
+ {
+ $iniData = parse_ini_file($configurator, true);
+ if (false === $iniData)
+ throw new Argument("Invalid configuration INI file");
+
+ return $this->loadArray($iniData);
+ }
+
+ public function loadArray(array $configurator)
+ {
+ foreach ($configurator as $key => $value)
+ $this->parseItem($key, $value);
+ }
+
+ public function __get($name)
+ {
+ return $this->getItem($name);
+ }
+
+ public function __set($name, $value)
+ {
+ if (isset($this[$name]) && $this[$name] instanceof Instantiator)
+ $this[$name]->setInstance($value);
+ $this[$name] = $value;
+ }
+
+ protected function keyHasInstantiator($key)
+ {
+ return false !== stripos($key, ' ');
+ }
+
+ protected function parseItem($key, $value)
+ {
+ $key = trim($key);
+ if ($this->keyHasInstantiator($key))
+ $this->parseInstantiator($key, $value);
+ else
+ $this->parseStandardItem($key, $value);
+ }
+
+ protected function parseSubValues(&$value)
+ {
+ foreach ($value as &$subValue)
+ $subValue = $this->parseValue($subValue);
+ return $value;
+ }
+
+ protected function parseStandardItem($key, &$value)
+ {
+ if (is_array($value))
+ $this->parseSubValues($value);
+ else
+ $value = $this->parseValue($value);
+
+ $this->offsetSet($key, $value);
+ }
+
+ protected function removeDuplicatedSpaces($string)
+ {
+ return preg_replace('/\s+/', ' ', $string);
+ }
+
+ protected function parseInstantiator($key, $value)
+ {
+ $key = $this->removeDuplicatedSpaces($key);
+ list($keyName, $keyClass) = explode(' ', $key);
+ $instantiator = new Instantiator($keyClass);
+
+ if (is_array($value))
+ foreach ($value as $property => $pValue)
+ $instantiator->setParam($property, $this->parseValue($pValue));
+ else
+ $instantiator->setParam('__construct', $this->parseValue($value));
+
+ $this->offsetSet($keyName, $instantiator);
+ }
+
+ protected function parseValue($value)
+ {
+ if (is_array($value))
+ return $this->parseSubValues($value);
+ elseif (empty($value))
+ return null;
+ else
+ return $this->parseSingleValue($value);
+ }
+
+ protected function hasCompleteBrackets($value)
+ {
+ return false !== strpos($value, '[') && false !== strpos($value, ']');
+ }
+
+ protected function parseSingleValue($value)
+ {
+ $value = trim($value);
+ if ($this->hasCompleteBrackets($value))
+ return $this->parseBrackets($value);
+ else
+ return $this->parseConstants($value);
+ }
+
+ protected function parseConstants($value)
+ {
+ if (preg_match('/^[A-Z_]+([:]{2}[A-Z_]+)?$/', $value) && defined($value))
+ return constant($value);
+ else
+ return $value;
+ }
+
+ protected function matchSequence(&$value)
+ {
+ if (preg_match('/^\[(.*?,.*?)\]$/', $value, $match))
+ return (boolean) ($value = $match[1]);
+ }
+
+ protected function matchReference(&$value)
+ {
+ if (preg_match('/^\[(\w+)+\]$/', $value, $match))
+ return (boolean) ($value = $match[1]);
+ }
+
+ protected function parseBrackets($value)
+ {
+ if ($this->matchSequence($value))
+ return $this->parseArgumentList($value);
+ elseif ($this->matchReference($value))
+ return $this->getItem($value, true);
+ else
+ return $this->parseVariables($value);
+ }
+
+ protected function parseVariables($value)
+ {
+ $self = $this;
+ return preg_replace_callback(
+ '/\[(\w+)\]/',
+ function($match) use(&$self) {
+ return $self[$match[1]] ? : '';
+ }, $value
+ );
+ }
+
+ protected function parseArgumentList($value)
+ {
+ $subValues = explode(',', $value);
+ return $this->parseSubValues($subValues);
+ }
+
+ protected function lazyLoad($name)
+ {
+ $callback = $this[$name];
+ return $this[$name] = $callback();
+ }
+
+}
Oops, something went wrong.

0 comments on commit 17fa81c

Please sign in to comment.