Code Monkey home page Code Monkey logo

aura.web_kernel's Introduction

Aura.Web_Kernel

This is a kernel for the Aura.Web_Project package.

Foreword

Requirements

This kernel requires PHP 5.4 or later; we recommend using the latest available version of PHP as a matter of principle.

Unlike Aura library packages, this kernel package has userland dependencies, which themselves may have other dependencies:

Installation

This kernel is installable and autoloadable via Composer with the following require element in your composer.json file:

"require": {
    "aura/web-kernel": "dev-develop-2"
}

Alternatively, download or clone this repository, then require or include its autoload.php file.

Tests

Build Status

To run the unit tests at the command line, issue composer install and then phpunit at the package root. This requires Composer to be available as composer, and PHPUnit to be available as phpunit.

PSR Compliance

This kernel attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Community

To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our Google Group, follow @auraphp on Twitter, or chat with us on #auraphp on Freenode.

Services

This kernel defines the following service objects in the Container:

  • aura/web-kernel:dispatcher: an instance of Aura\Dispatcher\Dispatcher
  • aura/web-kernel:request: an instance of Aura\Web\Request
  • aura/web-kernel:response: an instance of Aura\Web\Response
  • aura/web-kernel:router: an instance of Aura\Router\Router

Note that service definitions set at the kernel level may be reset at the project level.

aura.web_kernel's People

Contributors

harikt avatar mbrevda avatar renoinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aura.web_kernel's Issues

Playing with Aura.View reduced and my views on the kernel working

Hey Paul,

So invested some time to play with the new reduced branch and the way I am thinking of making use of stuffs.

You can see the commit on the aura/web-kernel https://github.com/auraphp/Aura.Web_Kernel/pull/10/files?w=1

The controller

<?php
class HelloController
{
    protected $view;

    public function setView($view)
    {
        $this->view = $view;
    }

    public function stringAction()
    {
        return "Hello as a string";
    }

    public function objAction()
    {
        $view_registry = $this->view->getViewRegistry();
        $view_registry->set('hello', function () {
            echo "Hello from view object!";
        });
        $this->view->setView('hello');
        return $this->view;
    }

    public function typesAction()
    {
        $view_registry = $this->view->getViewRegistry();
        $view_registry->set('hello', function () {
                echo "Hello {$this->name}!";
        });
        $this->view->setData(array('name' => 'World'));
        $this->view->setView('hello');
        return $this->view;
    }
}

Features are

returning $this->view the dispatcher is not dispatching. I thought the dispatcher can dispatch it. Seems a bug. Need to look into this. Fixed in https://github.com/auraphp/Aura.Dispatcher/pull/11/files?w=1

I would like to set xml, json, html view and let the view can detect the rendering needed. Seems reduced don't have the functionality as earlier.

Routes in config.

$router->add('string', '/string')
    ->setValues(
        array('controller' => 'feature', 'action' => 'stringAction')
    );
$router->add('obj', '/obj')
    ->setValues(
        array('controller' => 'feature', 'action' => 'objAction')
    );
$router->add('types', '/types')
    ->setValues(
        array('controller' => 'feature', 'action' => 'typesAction')
    );
$dispatcher->setObject('feature', function () use ($di) {
    return $di->newInstance('HelloController');
});

WebKernelTest not found issue

composer.json have "web-kernel-test": "Aura\Web_Kernel_Config\WebKernelTest" . But it is used on tests/kernel/config which is not added to autoload or autoload-dev .

In that case when having a web-kernel-test mode breaks for not loading the file even if it is not needed.

Do you think we can add to autoload-dev or we may want to move to config of the root.

Log routes always logged

Hi Paul,
I was looking at the code

protected function logRoutesTried()
{
$verb = $this->request->method->get();
$routes = $this->router->getDebug();
foreach ($routes as $tried) {
foreach ($tried->debug as $message) {
$name = $tried->name
? $tried->name
: $verb . ' ' . $tried->path;
$message = __CLASS__ . " $name $message";
$this->logger->debug($message);
}
}
}

And noticed that the log routes are always logged. Whether it is NullLogger or anything. I am sure iterating through the routes tried to find is not really needed in production .

Either we need to change according to the mode.

Use case you don't like :

My preference is move out the logger itself, and use some event handlers.

Let the users can add events and catch the events to do this .

Handling the priority in bundles.

Aura. Blog have sidebar attached to the TemplateRegistry map https://github.com/harikt/Aura.Blog/blob/cbd991d1c039c1dae67b4808d11d4d14738cee81/config/Common.php#L69

$di->params['Aura\View\TemplateRegistry']['map']['sidebar'] = dirname(__DIR__) . '/src/Web/Responder/layouts/sidebar.php';

My idea is to replace the sidebar with a different one on another bundle. In this case we don't know what order the di is taking, and overwriting the one will happen.

The exact use is to render sidebar in cocoframework example using aura/blog example with the sidebar .

Any other ideas are welcome!

Thanks

Dependency Issues on release

I noticed we have a dependency issue coming. I am not sure what will be the good way to resolve this.

Eg : Let us take https://packagist.org/packages/aura/web-kernel

The Web_Kernel requires the below packages.

    php: >=5.4.0
    aura/project-kernel: 2.*@dev
    aura/dispatcher: 2.*@dev
    aura/router: 2.*@dev
    aura/web: 2.*@dev
    psr/log: 1.*

When we release a package, the dependencies may have been released with different versions. So even we release the beta, the dependencies are development.

Eg : see the 2.0.0-beta1 https://packagist.org/packages/aura/web-kernel

May be in the composer.json we should have the latest stable release ?

But it may not be true for all cases, may be we need to test with the development version of that branch.

What will be the best way to resolve these types of conflicts ?

Ping @simensen

Benchmarking with ab

Hi,

I was trying to do a test benchmark with ab. Not sure what may be the reason the response is not send completely by apache.

$ ab -c 10 -t 3 http://aurabench.localhost/hello/World
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking aurabench.localhost (be patient)
Finished 1 requests


Server Software:        Apache/2.4.7
Server Hostname:        aurabench.localhost
Server Port:            80

Document Path:          /hello/Sunny
Document Length:        10 bytes

Concurrency Level:      10
Time taken for tests:   5.010 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      1780 bytes
HTML transferred:       100 bytes
Requests per second:    0.20 [#/sec] (mean)
Time per request:       50098.900 [ms] (mean)
Time per request:       5009.890 [ms] (mean, across all concurrent requests)
Transfer rate:          0.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  5010 5010   0.0   5010    5010
Waiting:        7    7   0.0      7       7
Total:       5010 5010   0.0   5010    5010

The response is as

public function modifyWebRouter(Container $di)
{
    $router = $di->get('aura/web-kernel:router');

    $router->add('hello', '/')
           ->setValues(array('action' => 'hello'));

   $router->add('hello_name', '/hello/{name}')
          ->setValues(array('action' => 'hello_name'));
}

public function modifyWebDispatcher($di)
{
    $dispatcher = $di->get('aura/web-kernel:dispatcher');

    $dispatcher->setObject('hello', function () use ($di) {
        $response = $di->get('aura/web-kernel:response');
        $response->content->set('Hello World!');
    });

    $dispatcher->setObject('hello_name', function ($name) use ($di) {
        $response = $di->get('aura/web-kernel:response');
        $response->content->set('Hello ' . $name);
        $response->content->setType('text/html');
    });
}

Anyone knows how to fix the same ? I remember somewhere I noticed the issue regarding this. But could not locate the same.

Signal inside WebKernel

As discusses earlier ( we talked about Middleware also ) I am thinking of having a signal on and after each

https://github.com/auraphp/Aura.Web_Kernel/blob/reduced/src/WebKernel.php#L50-L52

$this->signal->send('before_route');
$this->router->__invoke();
$this->signal->send('before_dispatch');
$this->dispatcher->__invoke();
$this->signal->send('before_respond');
$this->responder->__invoke();

I also wish if we can get the value after the dispatcher is invoked.

$this->dispatcher->__invoke();

The idea is returning some value from controller than setting the response from the controller.

return array('some_view_value' => 'Hello View');

and in the before respond send the data, which is got from the controller back. (response, request will also be send). So if we have injected a view we can render and set the content in response.

Router and Dispatcher

Hi Guys,

Yesterday Jakey69 was mentioning about so many configuration. I did thought a bit about it, and wonder whether this is possible.

$router = $di->get('aura/web-kernel:router');

$router->add('aura.blog.browse', '/blog{/page}')
    ->setValues(array(
        'action' => 'aura.blog.browse',
        'page' => 1
    ))
    ->addTokens(array(
        'page'  => '\d+',
    ));

$dispatcher = $di->get('aura/web-kernel:dispatcher');

$dispatcher->setObject(
    'aura.blog.browse',
    $di->lazyNew('Aura\Blog\Web\Action\BlogBrowseAction')
);

Can we add a bridge or something like that which have the router and dispatcher so we only need to take one service and add it. Not sure what I should call the service Eg :

$router_dispatcher = $di->get('aura/web-kernel:router_dispatcher');

$router_dispatcher->add('aura.blog.browse', '/blog{/page}')
    ->setValues(array(
        'action' => $di->lazyNew('Aura\Blog\Web\Action\BlogBrowseAction'),
        'page' => 1
    ))
    ->addTokens(array(
        'page'  => '\d+',
    ));

See we removed the dispatcher itself. But in the background we can add to the dispatcher itself. Your thoughts ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.