-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nicolasmure/lib-wrap
Lib wrap
- Loading branch information
Showing
12 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
composer.lock | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: php | ||
php: | ||
- '5.3' | ||
- '7.0' | ||
|
||
env: | ||
- SYMFONY_VERSION="2.3.*" | ||
- SYMFONY_VERSION="3.0.*" | ||
|
||
before_install: | ||
- mkdir -p build/logs | ||
- composer self-update | ||
|
||
install: | ||
- composer require satooshi/php-coveralls '~1.0' | ||
|
||
after_success: | ||
- php vendor/bin/coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Nmure\CrawlerDetectBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class CrawlerDetectBundle extends Bundle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Nmure\CrawlerDetectBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class CrawlerDetectExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.xml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,81 @@ | ||
# CrawlerDetectBundle | ||
A Symfony bundle for the Crawler-Detect library (detects bots/crawlers/spiders via the user agent) | ||
|
||
[![Build Status](https://travis-ci.org/nicolasmure/CrawlerDetectBundle.svg?branch=master)](https://travis-ci.org/nicolasmure/CrawlerDetectBundle) | ||
[![Coverage Status](https://coveralls.io/repos/github/nicolasmure/CrawlerDetectBundle/badge.svg?branch=master)](https://coveralls.io/github/nicolasmure/CrawlerDetectBundle?branch=master) | ||
|
||
A Symfony bundle for the [Crawler-Detect](https://github.com/JayBizzle/Crawler-Detect) | ||
library (detects bots/crawlers/spiders via the user agent). | ||
|
||
## Table of contents | ||
|
||
- [Introduction](#introduction) | ||
- [Installation](#installation) | ||
- [Step 1 : Download the Bundle](#step-1--download-the-bundle) | ||
- [Step 2 : Enable the Bundle](#step-2--enable-the-bundle) | ||
- [Usage](#usage) | ||
- [Testing](#testing) | ||
|
||
## Introduction | ||
|
||
This Bundle integrates the [Crawler-Detect](https://github.com/JayBizzle/Crawler-Detect) library into Symfony. | ||
It is **recommended** to read the lib's documentation before continuing here. | ||
|
||
The aim of this bundle is to expose the [`CrawlerDetect`](https://github.com/JayBizzle/Crawler-Detect/blob/master/src/CrawlerDetect.php "Jaybizzle\CrawlerDetect\CrawlerDetect") | ||
class as a service (`crawler_detect`) to make it easier to use with Symfony | ||
(dependency injection, usable from a controller, etc...). | ||
|
||
## Installation | ||
|
||
### Step 1 : Download the Bundle | ||
|
||
Open a command console, enter your project directory and execute the | ||
following command to download the latest stable version of this bundle: | ||
|
||
```bash | ||
$ composer require nmure/crawler-detect-bundle "dev-master" | ||
``` | ||
|
||
This command requires you to have Composer installed globally, as explained | ||
in the [installation chapter](https://getcomposer.org/doc/00-intro.md) | ||
of the Composer documentation. | ||
|
||
### Step 2 : Enable the Bundle | ||
|
||
Then, enable the bundle by adding it to the list of registered bundles | ||
in the `app/AppKernel.php` file of your project: | ||
|
||
```php | ||
// app/AppKernel.php | ||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
$bundles = array( | ||
// ... | ||
new Nmure\CrawlerDetectBundle\CrawlerDetectBundle(), | ||
// ... | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
From a controller : | ||
```php | ||
public function indexAction() | ||
{ | ||
if ($this->get('crawler_detect')->isCrawler()) { | ||
// crawler user-agent detected :) | ||
} | ||
} | ||
``` | ||
|
||
or you can also inject this service as a dependency | ||
using the `crawler_detect` service id. | ||
|
||
## Testing | ||
|
||
```bash | ||
$ docker run --rm -v `pwd`:/app phpunit/phpunit -c /app | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="crawler_detect.class">Jaybizzle\CrawlerDetect\CrawlerDetect</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="crawler_detect" class="%crawler_detect.class%"> | ||
</service> | ||
</services> | ||
</container> |
26 changes: 26 additions & 0 deletions
26
Tests/Functional/DependencyInjection/CrawlerDetectExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Nmure\CrawlerDetectBundle\Tests\Functional\DependencyInjection; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
class CrawlerDetectExtensionTest extends KernelTestCase | ||
{ | ||
private $container; | ||
|
||
protected function setUp() | ||
{ | ||
self::bootKernel(); | ||
$this->container = static::$kernel->getContainer(); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
unset($this->container); | ||
} | ||
|
||
public function testServiceIsDefined() | ||
{ | ||
$this->assertInstanceOf('Jaybizzle\\CrawlerDetect\\CrawlerDetect', $this->container->get('crawler_detect')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerBundles() | ||
{ | ||
return array( | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \Nmure\CrawlerDetectBundle\CrawlerDetectBundle(), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__.'/config/config.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
framework: | ||
secret: crawler_detect | ||
session: | ||
storage_id: session.storage.mock_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) { | ||
throw new \LogicException('Could not find autoload.php in vendor/. Try to run "composer install"'); | ||
} | ||
|
||
require $autoloadFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "nmure/crawler-detect-bundle", | ||
"type": "symfony-bundle", | ||
"description": "A Symfony bundle for the Crawler-Detect library (detects bots/crawlers/spiders via the user agent)", | ||
"keywords": ["crawler", "bot", "detect", "user-agent", "symfony", "bundle"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nicolas MURE", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/nicolasmure" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
"symfony/framework-bundle": "~2.3|~3.0", | ||
"jaybizzle/crawler-detect": "1.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { "Nmure\\CrawlerDetectBundle\\": "" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="./Tests/bootstrap.php" colors="true"> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml" /> | ||
</logging> | ||
|
||
<testsuites> | ||
<testsuite name="functional"> | ||
<directory suffix="Test.php">./Tests/Functional</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./</directory> | ||
<exclude> | ||
<directory>./build</directory> | ||
<directory>./Resources</directory> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
|
||
<php> | ||
<server name="KERNEL_DIR" value="./Tests/Functional/Fixtures/app" /> | ||
</php> | ||
</phpunit> |