rest-proxy.php

Simple proxy for RESTful APIs
git clone git://git.finwo.net/app/rest-proxy.php
Log | Files | Refs | README

commit 3208dcf7e32fd7b78c8ff0208541c45205e74e25
parent 991820196d870dee500650677c04bef9b047bca3
Author: finwo <finwo@pm.me>
Date:   Sun, 17 Apr 2016 03:00:28 +0200

First application launch

Diffstat:
Mconfig/config.yml | 2+-
Msrc/Finwo/Framework/Application.php | 28+++++++++++++++-------------
Msrc/Finwo/Framework/ParameterBag.php | 4++--
Msrc/Finwo/RestProxy/RestProxy.php | 5++++-
4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/config/config.yml b/config/config.yml @@ -1,6 +1,6 @@ # Application class -application: Finwo\RestProxy\RestProxy +application: Finwo\RestProxy # Note of the authors authors: diff --git a/src/Finwo/Framework/Application.php b/src/Finwo/Framework/Application.php @@ -12,11 +12,6 @@ class Application protected $container; /** - * @var ParameterBag - */ - protected $config; - - /** * @var PropertyAccessor */ protected $propertyAccessor; @@ -37,10 +32,11 @@ class Application return $this->propertyAccessor; } - public function __construct() + public function __construct( ParameterBag $container = null ) { // Don't do anything if we're an actual application - if ( get_class($this) !== 'Finwo\\Framework\\Application' ) { + if (!is_null($container)) { + $this->container = $container; return; } @@ -69,10 +65,10 @@ class Application $loader->loadFile($file) ); } - $this->config = new ParameterBag($config); + $this->container->set('config', $config); // Check if we can do something useful with the application - $app = $this->getApplicationObject( $this->config->get('application') ); + $app = $this->getApplicationObject( $this->container->get('config.application') ); if ($app === false) { throw new \Exception('Application does not exist!'); } @@ -85,13 +81,13 @@ class Application { // Try name directly if (class_exists($name)) { - return new $name(); + return new $name( $this->container ); } // Try name with ending "application" $tryname = $name . '\\Application'; if (class_exists($tryname)) { - return new $tryname(); + return new $tryname( $this->container ); } // Try name with double ending @@ -100,8 +96,9 @@ class Application array_push($tryname, $last); array_push($tryname, $last); $tryname = implode('\\', $tryname); + if (class_exists($tryname)) { - return new $tryname(); + return new $tryname( $this->container ); } return false; @@ -109,6 +106,11 @@ class Application public function launch() { - die("I've launched"); + // If we have a child, launch that instead + if( $this->app instanceof Application ) { + return $this->app->launch(); + } + + return 'tadaa'; } } \ No newline at end of file diff --git a/src/Finwo/Framework/ParameterBag.php b/src/Finwo/Framework/ParameterBag.php @@ -52,13 +52,13 @@ class ParameterBag public function set($key, $value) { $acc = $this->getAccessor(); - $acc->set($this->parameters, $key, $value); + $acc->set($this->parameters, $key, $value, '.'); return $this; } public function get($key) { $acc = $this->getAccessor(); - return $acc->get($this->parameters, $key); + return $acc->get($this->parameters, $key, '.'); } } \ No newline at end of file diff --git a/src/Finwo/RestProxy/RestProxy.php b/src/Finwo/RestProxy/RestProxy.php @@ -6,5 +6,8 @@ use Finwo\Framework\Application; class RestProxy extends Application { - + public function launch() + { + die(__CLASS__); + } } \ No newline at end of file