Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Wanted : SlimFramework 3 #311

Open
VincentSurelle opened this issue Dec 13, 2017 · 4 comments
Open

Help Wanted : SlimFramework 3 #311

VincentSurelle opened this issue Dec 13, 2017 · 4 comments

Comments

@VincentSurelle
Copy link

Hi,

I'm trying to build a SlimFramework Bridge for PPM. For now I'm able to run it, but I'm having issues with caching.

First, I don't know how to manage request caching. If I run a request that could change over the time, I will always have the same result.

Next is for JWT protected requests. If I run a protected request without my token in the header. I obviously get a 401 Unauthorized response. So I run another request on the same path but, this time, with a JWT, I get the ressources I asked for. For now it's absolutely legit.
Let's run a third request, still on the same path but without JWT. I expect another 401 error. But no, I get the ressource I asked for, without authentication.

Can someone give help to destroy data between requests ?

Obviously when finished I'll push it to PPM Github

@VincentSurelle
Copy link
Author

VincentSurelle commented Dec 18, 2017

Today I'm having something like this (not finished). Which work well but I'm still facing the same (cache?) issue.

<?php

namespace Boostrap;

use Interop\Http\Server\RequestHandlerInterface;
use PHPPM\Bootstraps\ApplicationEnvironmentAwareInterface;
use PHPPM\Bootstraps\BootstrapInterface;
use PHPPM\Bootstraps\HooksInterface;
use PHPPM\Bootstraps\RequestClassProviderInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;
use Slim\Container;
use Slim\Http\Response;

class SlimBootstrap implements ApplicationEnvironmentAwareInterface, RequestHandlerInterface
{
    protected $appenv;
    protected $debug = false;

    /**
     * @var App
     */
    protected $app;

    public function initialize($appenv, $debug)
    {
        $this->appenv = $appenv;
        $this->debug = $debug;

        $app = new App($this->getContainer());

        include 'app/routes.php';
        include 'app/middlewares.php';

        $this->app = $app;
    }

    private function getContainer()
    {
        $logger = function($container) {
            $logger = new Logger(getenv('APP_NAME') ?? 'Slim');

            $logger->pushHandler(new RotatingFileHandler('/log.txt'));

            return $logger;
        };

        return new Container([
            'settings' => [
                'displayErrorDetails' => ($this->appenv !== 'prod')
            ],
            'logger' => $logger
        ]);
    }

    public function handle(ServerRequestInterface $request)
    {
        $response = $this->app->process(
            $request,
            new Response());
        return $response;
    }
}

For testing, I tried unsetting $app and rebuild it on every request but it doesn't seem to do anything.
I really don't know where to look at to remove request caching across multiple clients.

@andig
Copy link
Contributor

andig commented Jan 9, 2018

It might help asking at the Slim repo/forums.

@code-runner-2017
Copy link

Slim 3 supports PSR-7, right?
I found this: https://github.com/php-pm/php-pm-psr7, marked as obsolete because "PSR-7 compatibility is now built into php-pm directly".
As far as I understand, it should be possible to use Slim directly with PHP-PM, but I couldn't find any reference in the documentation.

Anyone successful running Slim 3 with PHP-PM without any bridge?

@andig
Copy link
Contributor

andig commented Jan 11, 2018

Slim 3 supports PSR-7, right?

If it does we still need a way to pass the request into the framework. The base repo has 2 middleware bridges for that purpose but- looking at the code above- interacting with Slim takes more and we'll require Slim kx to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants