Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

harikt/conduit-skelton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conduit Experiments

Check conduit the middleware for PHP.

This is pretty simple configuring some of the components of aura with conduit. Currently have application middleware and authentication middleware.

Installation

git clone https://github.com/harikt/conduit-skelton
cd conduit-skelton
composer install
php -S localhost:8000 web/index.php

Usage

Configure your routes.

<?php
// config/routes.php
$router = $di->get('router');
$router->add('home', '/')
    ->addValues(array('controller' => function ($response) {
            return $response->getBody()->write("<p>Home page in html. Please <a href=\"blog\">Browse</a> and <a href=\"blog/12\">view post</a></p>")->withHeader('Content-Type', 'text/html');
        }
    ));

// or

$router->add('greet', '/greet')
    ->addValues(array(
        'controller' => 'Controller\Greet',
        'action' => 'hello'
    ));
namespace Controller;

use Psr\Http\Message\ResponseInterface;
use Response\Payload;

class Blog
{
    public function hello()
    {
        $available = array(
            'text/html' => '.html',
            'application/json' => '.json',
        );
        // $data, $view, $layout, $available
        return new Payload(array('name' => 'Hari KT'), 'greet', null, $available);
    }

    public function returnString()
    {
        return "Hello World";
    }

    public function returnResponse(ResponseInterface $response)
    {
        return $response->withStatus(200)
                    ->withHeader('Content-Type', 'text/html')
                    ->write("returns response");
    }
}

Some conventions

Your view name expected is greet.html.php, greet.json.php, greet.html.twig, greet.json.twig formats.

Same for the layouts.

Configuring authentication middleware

Try http://localhost:8000/admin . If you are not logged in it will redirect you to http://localhost:8000/login page.

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL COMMENT 'Username',
  `email` varchar(255) NOT NULL COMMENT 'Email',
  `password` varchar(255) NOT NULL COMMENT 'Password',
  `fullname` varchar(255) NOT NULL COMMENT 'Full name',
  `website` varchar(255) DEFAULT NULL COMMENT 'Website',
  `active` int(11) NOT NULL COMMENT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Environmental variables are used with the help of vlucas/phpdotenv. Rename env_dist to .env and change database name, username and password according to yours.

Play and enjoy!

Thanks

About

A micro framework on top of conduit, which supports PSR-7 in core

Resources

License

Stars

Watchers

Forks

Packages

No packages published