Skip to content

Commit

Permalink
Import from vendor directory
Browse files Browse the repository at this point in the history
  • Loading branch information
devinpitcher committed Apr 22, 2020
0 parents commit d171cee
Show file tree
Hide file tree
Showing 11 changed files with 495 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
languages:
Ruby: false
JavaScript: false
Python: false
PHP: true
exclude_paths:
- tests/*
- vendor/*
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
.idea
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- composer self-update
- composer install --prefer-source --no-interaction

script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_success:
- vendor/bin/test-reporter
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Andrew Ellis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# robots.txt Generator for Laravel 5

[![Current Release](https://img.shields.io/github/release/ellisthedev/laravel-5-robots.svg)](https://github.com/ellisthedev/laravel-5-robots/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/ellisthedev/laravel-5-robots.svg)](https://packagist.org/packages/ellisthedev/laravel-5-robots)
[![Build Status](https://travis-ci.org/ellisthedev/laravel-5-robots.svg?branch=master)](https://travis-ci.org/ellisthedev/laravel-5-robots)
[![Code Climate](https://codeclimate.com/github/ellisthedev/laravel-5-robots/badges/gpa.svg)](https://codeclimate.com/github/ellisthedev/laravel-5-robots)
[![Test Coverage](https://codeclimate.com/github/ellisthedev/laravel-5-robots/badges/coverage.svg)](https://codeclimate.com/github/ellisthedev/laravel-5-robots)

This is a fork of https://github.com/jayhealey/Robots. It appears development
has stalled on the original repository.

The purpose of this fork is to introduce Laravel 5 compatibility and PSR-4 and
PSR-2 (for Laravel 5.1).

# Installation

## Step 1: Composer

Add the package to your `composer.json`:

```
{
"require": {
"ellisthedev/laravel-5-robots": "~0.1.0"
}
}
```

## Step 2: Configuration

Add the following to your `config/app.php` in the `providers` array:

```
'EllisTheDev\Robots\RobotsServiceProvider',
```

You can also optionally add the following to the `aliases` array:

```
'Robots' => 'EllisTheDev\Robots\RobotsFacade',
```

# Usage

Add the following to your routes file:

```php
Route::get('robots.txt', function ()
{
if (App::environment() == 'production') {
// If on the live server, serve a nice, welcoming robots.txt.
Robots::addUserAgent('*');
Robots::addSitemap('sitemap.xml');
} else {
// If you're on any other server, tell everyone to go away.
Robots::addDisallow('*');
}

return Response::make(Robots::generate(), 200, ['Content-Type' => 'text/plain']);
});
```

Refer to the [Robots.php](src/Robots.php) for API usage.

# License

[MIT](LICENSE)
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ellisthedev/laravel-5-robots",
"description": "Robots.txt Generator for Laravel 5",
"license": "MIT",
"authors": [
{
"name": "Andrew Ellis",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": ">=5.0"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master",
"phpunit/phpunit": "~4.6"
},
"autoload": {
"psr-4": {
"EllisTheDev\\Robots\\": "src/"
}
},
"minimum-stability": "stable"
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
128 changes: 128 additions & 0 deletions src/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
namespace EllisTheDev\Robots;

/**
* Class Robots
*
* @package EllisTheDev\Robots
*/
class Robots
{
/**
* The lines for the robots.txt.
*
* @var array
*/
protected $lines = [];

/**
* Generate the robots.txt data.
*
* @return string
*/
public function generate()
{
return implode(PHP_EOL, $this->lines);
}

/**
* Add a Sitemap to the robots.txt.
*
* @param string $sitemap
*/
public function addSitemap($sitemap)
{
$this->addLine('Sitemap: '.$sitemap);
}

/**
* Add a User-agent to the robots.txt.
*
* @param string $userAgent
*/
public function addUserAgent($userAgent)
{
$this->addLine('User-agent: '.$userAgent);
}

/**
* Add a Host to the robots.txt.
*
* @param string $host
*/
public function addHost($host)
{
$this->addLine('Host: '.$host);
}

/**
* Add a disallow rule to the robots.txt.
*
* @param string|array $directories
*/
public function addDisallow($directories)
{
$this->addRuleLine($directories, 'Disallow');
}

/**
* Add a allow rule to the robots.txt.
*
* @param string|array $directories
*/
public function addAllow($directories)
{
$this->addRuleLine($directories, 'Allow');
}

/**
* Add a rule to the robots.txt.
*
* @param string|array $directories
* @param string $rule
*/
protected function addRuleLine($directories, $rule)
{
foreach ((array) $directories as $directory) {
$this->addLine($rule.': '.$directory);
}
}

/**
* Add a comment to the robots.txt.
*
* @param string $comment
*/
public function addComment($comment)
{
$this->addLine('# '.$comment);
}

/**
* Add a spacer to the robots.txt.
*/
public function addSpacer()
{
$this->addLine('');
}

/**
* Add a line to the robots.txt.
*
* @param string $line
*/
protected function addLine($line)
{
$this->lines[] = (string) $line;
}

/**
* Reset the lines.
*
* @return void
*/
public function reset()
{
$this->lines = [];
}
}
22 changes: 22 additions & 0 deletions src/RobotsFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace EllisTheDev\Robots;

use Illuminate\Support\Facades\Facade;

/**
* Class RobotsFacade
*
* @package EllisTheDev\Robots
*/
class RobotsFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'robots';
}
}
32 changes: 32 additions & 0 deletions src/RobotsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace EllisTheDev\Robots;

use Illuminate\Support\ServiceProvider;

/**
* Class RobotsServiceProvider
*
* @package EllisTheDev\Robots
*/
class RobotsServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('robots', function ()
{
return new Robots;
});
}
}
Loading

0 comments on commit d171cee

Please sign in to comment.