slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.94k stars 1.95k forks source link

[develop] MiddlewareAware #1071

Closed designermonkey closed 9 years ago

designermonkey commented 9 years ago

HI,

Would it be quicker and more efficient to use SplStack as the $stack instance instead of calling array_unshift for every appended middleware?

protected $stack;

protected function seedMiddlewareStack()
{
    if (is_null($this->stack)) {
        $this->stack = new SplStack;
        $this->stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);

        $this->stack[] = $this;
    }
}
codeguy commented 9 years ago

Probably :) Forgot that little guy existed.

codeguy commented 9 years ago

Do want to send a PR or should I do this?

codeguy commented 9 years ago

I was bored. Went ahead and pushed this up https://github.com/slimphp/Slim/commit/ed994a1ee44f66b6da8c2d734a9f41b46971044c