From b9e866fd18c6f8d90938f9a672f004db10973d44 Mon Sep 17 00:00:00 2001 From: devosc Date: Wed, 24 May 2017 17:26:31 -0500 Subject: [PATCH] tidy up --- view/overview/index.phtml | 80 ++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/view/overview/index.phtml b/view/overview/index.phtml index ce193cb..c90ee72 100644 --- a/view/overview/index.phtml +++ b/view/overview/index.phtml @@ -35,7 +35,7 @@
(new Web(include __DIR__ . '/../config/config.php', null, true))();
 
-

A default configuration is provided with the minimum configuration required to run a web application. It contains configurations for PSR 7 compatible request and response objects, templates and routes. The third parameter passed to the web class binds the scope of the anonymous functions, within the service configuration, to the application class.

+

A default configuration is provided with the minimum configuration required to run a web application. It contains configurations for PSR-7 compatible request and response classes, templates and routes. The third parameter passed to the web class binds the scope of the anonymous functions, within the service configuration, to the application class.

Console Application

A simple console application can be created by passing command line arguments to the service call method.

@@ -50,7 +50,7 @@ -

The first argument is the name of the function or object to call and the remaining arguments are its parameters, e.g Console\Example.

+

The first argument is the name of the function to call and the remaining arguments are its parameters, e.g Console\Example.

namespace Console;
 
@@ -104,7 +104,7 @@ class Example
 
-

For example, the development config file config/dev/config.php can include the main production config file config/config.php and override the name of the database to use in the development environment.

+

For example, the development config file config/dev/config.php can include the production config file config/config.php and override the name of the database to use in the development environment.

Models and ArrayAccess

Value objects use a model interface to provide a common set of access methods.

@@ -145,22 +145,22 @@ trait ReadOnly function offsetSet($name, $value) { - throw new \Exception('Invalid operation: object cannot be modified'); + throw new \Exception; } function offsetUnset($name) { - throw new \Exception('Invalid operation: object cannot be modified'); + throw new \Exception; } function __set($name, $value) { - throw new \Exception('Invalid operation: object cannot be modified'); + throw new \Exception; } function __unset($name) { - throw new \Exception('Invalid operation: object cannot be modified'); + throw new \Exception; } } @@ -199,7 +199,7 @@ $request->with(Arg::NAME, 'home'); //Immutable -

Models can also be made mutable by applying their traits to an instance of a configuration object.

+

Models can also be made mutable by applying their traits to an instance of a configuration object.

class ViewModel
     extends \Mvc5\Config
@@ -233,7 +233,7 @@ $request->with(Arg::NAME, 'home'); //Immutable
 
         

The regular expression can use group names that are assigned as request parameters when the route is matched. Consequently, the parameter names must be alphanumeric. The path configuration provides a simpler format for specifying regular expressions and group names. For example, if the matched url is /about, the app route configuration assigns the value about as the controller request parameter.

-

Short names can also be assigned to regular expressions and be used in a path configuration by prefixing them with a single colon or two colons when assigned to parameter name. Below are the default short-named regular expressions available to use.

+

Short names can also be assigned to regular expressions and be used in a path configuration by prefixing them with a single colon or two colons when assigned to a parameter name. Below are the default short-named regular expressions available to use.

[
     'a' => '[a-zA-Z0-9]++',
@@ -264,24 +264,23 @@ $request->with(Arg::NAME, 'home'); //Immutable
         

Custom routes can also be configured by adding a class name to the array, or the configuration can be a route object.

Automatic Routes

-

A controller can be automatically matched to a url by using the controller match function and a route configuration like the one below.

+

A controller can be automatically matched to a url with the controller match function and using a single route configuration.

return [
-    'name' => 'app',
-    'route' => '/[{controller::*$}]',
-    'defaults' => [
-        'controller' => 'home'
-    ],
-    'options' => [
-        'prefix' => 'App\\',
-        'suffix' => '\Controller',
-        'strict' => false,
+    'app' => [
+        'defaults' => ['controller' => 'home'],
+        'options' => [
+            'prefix' => 'App',
+            'suffix' => '\Controller'
+            'strict' => false,
+        ],
+        'path' => '/[{controller::*$}]'
     ]
 ];
 
-

The controller match function will change the first letter of each word separated by a forward slash in the url into an uppercase letter. It then replace the forward slash with a back slash to create a fully qualified class name and will try to load a matching controller. In order to ensure that it is a valid controller, the configuration should prepend a namespace and append a suffix.

+

The controller match function will change the first letter of each word separated by a forward slash in the url into an uppercase letter. It then replaces the forward slash with a back slash to create a fully qualified class name and will try to load a matching controller. In order to ensure that it is a valid controller, the configuration should prepend a namespace and append a suffix.

Strict mode does not change the case sensitivity of the controller name. However, most urls are lower case and file names and directories typically begin with an uppercase. This prevents controllers from being auto-loaded. This can be resolved by using a service loader and having a service configuration with a matching lower case name. The service configuration will then specify the name of the class to use, e.g 'home\controller' => Home\Controller::class.

@@ -290,7 +289,7 @@ $request->with(Arg::NAME, 'home'); //Immutable

Controller names prefixed with the @ symbol will be directly invoked because they are either a function or a static class method.

Url Generator

-

The url plugin can generate urls with or without a route configuration and are RFC 3986 encoded.

+

The url plugin can generate urls with or without a route configuration and are RFC 3986 encoded.

'dashboard' => [
     'path'      => '/dashboard/{user}',
@@ -310,28 +309,28 @@ $request->with(Arg::NAME, 'home'); //Immutable
 
-

Route configurations must be named and child routes of the current parent route can automatically use their parent route parameters, e.g /dashboard/phpdev/add.

+

Route configurations must be named and child routes of the current parent route can automatically use their parent route parameters, e.g /dashboard/phpdev/add.

echo $this->url('dashboard/add');
 
-

Wild card parameters can added by using the {wildcard::*$} route expression and enabling it with 'wildcard' => true. The parameters are appended to the url and will be added to the parameters for that request, e.g /dashboard/phpdev/add/type/tasks.

+

Wild card parameters can be added by using the {wildcard::*$} route expression and enabling it with 'wildcard' => true. The parameters are appended to the url and will be added to the parameters for that request, e.g /dashboard/phpdev/add/type/tasks.

echo $this->url(['dashboard/add', 'type' => 'tasks']);
 
-

Urls can also be generated without having or using a route configuration by prefixin the path with a forward slash.

+

Urls can also be generated without having or using a route configuration by prefixing the path with a forward slash.

-
echo $this->url('/dashboard/phpdev/list', ['order' => 'desc'], ['absolute' => true]);
+        
echo $this->url('/dashboard/phpdev/list', ['order' => 'desc'], '', ['absolute' => true]);
 
-

The second parameter of the url plugin function is for query string arguments, e.g /dashboard/phpdev/list?order=desc and the third parameter can be used to generate an absolute url; the current scheme, host and port will be used if not provided. The url plugin can also be configured to always generate an absolute url.

+

The second parameter of the url plugin function is for query string arguments, e.g /dashboard/phpdev/list?order=desc. The third parameter is for the fragment and the fourth parameter can be used to generate an absolute url; the current scheme, host and port will be used if not provided. The url plugin class can also be configured to always generate an absolute url.

REST API Methods

-

Routes can be configured with actions for specific HTTP methods. The default action is specified with the controller configuration.

+

Routes can be configured with actions for specific HTTP methods. The default action is specified with the controller configuration.

'resource' => [
     'route' => '/resource',
@@ -356,7 +355,7 @@ $request->with(Arg::NAME, 'home'); //Immutable
 
-

A controller is a function. It can also be an event or a plugin that resolves to a callable function. If the value returned from the controller is not a Http\Response and it is not null, it will be set as the value of the response body for the remaining components to transform into a value that can be sent to the client.

+

A controller is a function, it can also be an event or a plugin that resolves to a callable function. If the value returned from the controller is not a Http\Response and it is not null, it will be set as the value of the response body for the remaining components to transform into a value that can be sent to the client.

'web' => [
     'route\dispatch',
@@ -398,7 +397,7 @@ $request->with(Arg::NAME, 'home'); //Immutable
 
-

The Middleware demo can be enabled by uncommenting the web configuration in the web application service configuration file.

+

The PSR-7 Middleware demo can be enabled by uncommenting the web configuration in the web application service config file.

//middleware demo
 //'web' => 'web\middleware',
@@ -601,7 +600,7 @@ $app->call('dashboard->home', ['form' => []]);
 
-

A container can contain any type of value, except for null. A parent container can also pass itself to a child container as the service provider to use when the child container can not retrieve or resolve a particular value. The parent container can also specify what object to use as the scope of an anonymous function within the child container.

+

A container can contain any type of value, except for null. A parent container can also pass itself to a child container as the service provider to use when the child container can not retrieve or resolve a particular value. The parent container can also specify what object to use as the scope of an anonymous service function within the child container.

Autowiring

The required arguments of a class constructor are automatically resolved by a service manager when it instantiates a class that

@@ -919,21 +918,18 @@ new Invoke(function() { var_dump(func_get_args()); }),

Service Providers

Custom plugins can implement the resolvable interface and extend an existing plugin or have their own service provider. A service provider is a callable function that is invoked when a plugin can not be resolved by default.

-
use Plugin\Controller;
-use Service\ServiceProvider;
-use Service\ServiceManager;
+        
use Mvc5\Plugin\Config;
+use Plugin\Controller;
+use Service\Provider;
 
 return [
     'Home\Controller'  => new Controller(Home\Controller::class),
-    'service\provider' => new Service(
-        ServiceProvider::class, [], [Arg::SERVICE => new Plugin('service\manager')]
-    ),
-    'service\manager'  => new Manager(ServiceManager::class),
+    'service\provider' => [Service\Provider::class, new Config],
 ];
 
-

For example, the home controller uses a custom controller plugin and a service provider has been added to the service resolver event.

+

For example, the home controller uses a custom controller plugin with a service provider for the service resolver event.

function resolve($config, array $args = [])
 {
@@ -948,7 +944,7 @@ return [
 
-

A service resolver is used to call the service provider and an exception is thrown if the plugin can not be resolved.

+

The service resolver event is used to call the service provider and an exception is thrown if the plugin can not be resolved.

'service\resolver' => [
     'service\provider',
@@ -993,12 +989,10 @@ return [
     function($model) {
         return $model . '<h1>Remove</h1>';
     },
-    function($layout, $model = null) {
+    function(TemplateLayout $layout, $model = null) {
         $model .= '<h1>Respond</h1>';
 
-        $layout->model($model);
-
-        return $layout;
+        return $layout->withModel($model);
     }
 ]