2017 © Pedro Peláez
 

library stack-robots

StackRobots Middleware for StackPHP

image

league/stack-robots

StackRobots Middleware for StackPHP

  • Tuesday, February 11, 2014
  • by alexbilbie
  • Repository
  • 9 Watchers
  • 70 Stars
  • 3,144 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

League\StackRobots

Build Status Total Downloads Latest Stable Version, (*1)

StackRobots is a middleware for StackPHP. It provides a default robots.txt for non-production environments., (*2)

Install Via Composer

{
    "require": {
        "league/stack-robots": "~1.0"
    }
}

Usage

StackRobots is a very simple middleware. By default it looks at the SERVER_ENV environment variable, and if the SERVER_ENV does not equal production, it captures the response and sets an X-Robots-Tag header with a value of noindex, nofollow, noarchive., (*3)

When you push the middleware on to the stack, you can pass 2 additional parameters, $env and $envVar. The $env parameter is the environment in which you want this middleware to not do anything, typically production. The $envVar parameter is the environment variable that holds the environment of the current server; it defaults to SERVER_ENV., (*4)

If the value of SERVER_ENV matches the value that is passed, this middleware will just pass control on to the next middleware. However, if it does not match, then StackRobots will set the X-Robots-Tag. Additionally, if the incoming request is for your /robots.txt file, then StackRobots will stop the request and send the following response., (*5)

return new Response("User-Agent: *\nDisallow: /", 200, array('Content-Type' => 'text/plain'));

And this is what the browser receives., (*6)

User-Agent: *
Disallow: /

More info on the X-Robots-Tag is available here., (*7)

Example

include_once '../vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use League\StackRobots\Robots;

$app = new Stack\CallableHttpKernel(function (Request $request) {
    return new Response('Hello World!');
});

putenv('SERVER_ENV=dev');

$app = (new Stack\Builder)
    ->push('League\\StackRobots\\Robots')
    ->resolve($app);

Stack\run($app);

Authors

The Versions

11/02 2014

dev-master

9999999-dev

StackRobots Middleware for StackPHP

  Sources   Download

MIT

The Requires

 

The Development Requires

01/02 2014

v1.1.1

1.1.1.0

StackRobots Middleware for StackPHP

  Sources   Download

MIT

The Requires

 

The Development Requires

02/11 2013

v1.1

1.1.0.0

StackRobots Middleware for StackPHP

  Sources   Download

MIT

The Requires

 

The Development Requires

02/11 2013

1.0

1.0.0.0

StackRobots Middleware for StackPHP

  Sources   Download

MIT

The Requires

 

The Development Requires