Skip to content

raphael-homann/efroggWebservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

htaccess

Créer un fichier .htaccess :

RewriteBase /
RewriteRule ^api/(.*)$ webservice.php [QSA,L]

index

Créer un fichier webservice.php :

<?php

$autoloader = require "vendor/autoload.php";

$options = array("allow_debug"=>true);

$bootstrap = new WebserviceBootstrap($options);
$bootstrap->setAuthenticator(new SimpleAuthenticator("XXX"));
$bootstrap->addProvider("/api",new WebserviceCmsProvider($bootstrap->getApp()));
//$bootstrap->setDb(new PrestashopDbAdapter(\Db::getInstance()));

$bootstrap->run();

#Provider on ajoute un ou plusieurs Providers,qui dispatch sous un dossier (ici /api) un certain nombre de services

<?php
namespace efrogg\Simplecms\Webservice\Provider;

use efrogg\Simplecms\Webservice\WebservicePage;
use Silex\Api\ControllerProviderInterface;
use Silex\Application;
use Silex\ControllerCollection;

class WebserviceCmsProvider implements ControllerProviderInterface
{

    /**
     * Returns routes to connect to the given application.
     *
     * @param Application $app An Application instance
     *
     * @return ControllerCollection A ControllerCollection instance
     */
    public function connect(Application $app)
    {
        /** @var ControllerCollection $controllers */
        $controllers = $app['controllers_factory'];

        // order (erp)
        $app["webservice.cms.page"] = function($app) {
            return new WebservicePage($app['db']);
        };
        $controllers->get("/cms/page", "webservice.cms.page:test");


        return $controllers;

    }
}

services

on crée des services

<?php
namespace efrogg\Simplecms\Webservice;

use Efrogg\Db\Adapters\DbAdapter;
use Efrogg\Webservice\WebserviceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class WebservicePage implements WebserviceInterface
{

    protected $db;

    /**
     * @return Response
     */
    public function setDb(DbAdapter $db)
    {
        $this->db = $db;
    }

    public function test() {
        return new JsonResponse(array("123","456"=>"789"));
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages