Coder Social home page Coder Social logo

Exception before redirect about clockwork HOT 8 CLOSED

diffmike avatar diffmike commented on May 15, 2024
Exception before redirect

from clockwork.

Comments (8)

itsgoingd avatar itsgoingd commented on May 15, 2024

Hey, looks like you are firing the "clockwork.controller.end", without firing "clockwork.controller.start" beforehand. Are you using this feature?

from clockwork.

diffmike avatar diffmike commented on May 15, 2024

Yes, of course.
Here is my code of BaseController construct:

        $this->beforeFilter('csrf', array('on' => 'post'));

        $this->beforeFilter(function()
        {
            Event::fire('clockwork.controller.start');
        });

        $this->afterFilter(function()
        {
            Event::fire('clockwork.controller.end');
        });

from clockwork.

rdpascua avatar rdpascua commented on May 15, 2024

I encountered this issue as well, I have this in my BaseController contructor:

    /**
     * Create new instance of BaseController
     */
    public function __construct()
    {
        $this->beforeFilter('csrf', array('on' => 'POST'));
        $this->beforeFilter('auth', ['except' => 'login']);

        $this->beforeFilter(function()
        {
            Event::fire('clockwork.controller.start');
        });

        $this->afterFilter(function()
        {
            Event::fire('clockwork.controller.end');
        });
    }

Well I just solved this by putting first the clockwork events it looks like this:

        $this->beforeFilter(function()
        {
            Event::fire('clockwork.controller.start');
        });

        $this->afterFilter(function()
        {
            Event::fire('clockwork.controller.end');
        });

        $this->beforeFilter('csrf', array('on' => 'POST'));
        $this->beforeFilter('auth', ['except' => 'login']);

from clockwork.

AkenRoberts avatar AkenRoberts commented on May 15, 2024

This problem is due to application filters not being registered in the proper order. If I register an App::before() filter in a service provider before Clockwork's service provider is registered, my filter's closure will run before Clockwork. If my filter returns a response, Clockwork's will never be called, thus never calling startEvent().

A solution would be to circumvent registering events using things like $this->app->before(), and target the direct event you want to register a listener for via $this->app['events']->listen() (how it's being done in most places already). Then, you'll also want to specify a priority for, at minimum, the early-on listeners (particularly router.before), which ensures Clockwork's filter(s) run as early as possible, before any user-set listeners.

from clockwork.

diffmike avatar diffmike commented on May 15, 2024

thanks!

from clockwork.

AkenRoberts avatar AkenRoberts commented on May 15, 2024

@diffmike I would reopen this, as the above solution should be implemented by @itsgoingd / Clockwork, not the user end. I can PR it soon, if desired.

from clockwork.

diffmike avatar diffmike commented on May 15, 2024

Ok. It's reopen

from clockwork.

itsgoingd avatar itsgoingd commented on May 15, 2024

Fixed in dev-master, calling endEvent for non-existing event no longer throws exception, as it's not exceptional enough to tear down the whole app imo.

I would like to capture the controller runtime automatically, without the need to add code to the base controller at all, the closest events to use would be afaik router.matched as controller start time and router.after as controller end time, this would still include route filters runtime though. If you have a better idea feel free to reopen.

from clockwork.

Related Issues (20)

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.