Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfb84ad
commit 1b6e746
Showing
9 changed files
with
622 additions
and
0 deletions.
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
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <info@peter-gribanov.ru> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\AnimeNewsNetworkBrowserBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class AnimeDbAnimeNewsNetworkBrowserBundle extends Bundle | ||
{ | ||
} |
38 changes: 38 additions & 0 deletions
38
src/DependencyInjection/AnimeDbAnimeNewsNetworkBrowserExtension.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,38 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <info@peter-gribanov.ru> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\AnimeNewsNetworkBrowserBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
class AnimeDbAnimeNewsNetworkBrowserExtension extends Extension | ||
{ | ||
/** | ||
* @param array $configs | ||
* @param ContainerBuilder $container | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
|
||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
|
||
$container->getDefinition('anime_db.anime_news_network.browser') | ||
->replaceArgument(1, $config['host']) | ||
->replaceArgument(2, $config['reports']) | ||
->replaceArgument(3, $config['details']) | ||
->replaceArgument(4, $config['client']) | ||
; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <info@peter-gribanov.ru> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\AnimeNewsNetworkBrowserBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* Config tree builder. | ||
* | ||
* Example config: | ||
* | ||
* anime_db_anime_news_network_browser: | ||
* host: 'https://cdn.animenewsnetwork.com' | ||
* reports: '/encyclopedia/reports.xml' | ||
* details: '/encyclopedia/api.xml' | ||
* client: 'My Custom Bot 1.0' | ||
* | ||
* @return ArrayNodeDefinition | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
return (new TreeBuilder()) | ||
->root('anime_db_anime_news_network_browser') | ||
->children() | ||
->scalarNode('host') | ||
->defaultValue('https://cdn.animenewsnetwork.com') | ||
->cannotBeEmpty() | ||
->end() | ||
->scalarNode('reports') | ||
->defaultValue('/encyclopedia/reports.xml') | ||
->cannotBeEmpty() | ||
->end() | ||
->scalarNode('details') | ||
->defaultValue('/encyclopedia/api.xml') | ||
->cannotBeEmpty() | ||
->end() | ||
->scalarNode('client') | ||
->defaultValue('') | ||
->cannotBeEmpty() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
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,8 @@ | ||
services: | ||
anime_db.anime_news_network.browser: | ||
class: AnimeDb\Bundle\AnimeNewsNetworkBrowserBundle\Service\Browser | ||
arguments: [ '@anime_db.anime_news_network.browser.client', ~, ~, ~, ~ ] | ||
|
||
anime_db.anime_news_network.browser.client: | ||
class: GuzzleHttp\Client | ||
public: false |
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,100 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <info@peter-gribanov.ru> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\AnimeNewsNetworkBrowserBundle\Service; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class Browser | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $host; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $reports; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $details; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $app_client; | ||
|
||
/** | ||
* @param Client $client | ||
* @param string $host | ||
* @param string $reports | ||
* @param string $details | ||
* @param string $app_client | ||
*/ | ||
public function __construct(Client $client, $host, $reports, $details, $app_client) | ||
{ | ||
$this->client = $client; | ||
$this->host = $host; | ||
$this->reports = $reports; | ||
$this->details = $details; | ||
$this->app_client = $app_client; | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @param array $options | ||
* | ||
* @return string | ||
*/ | ||
public function reports($id, array $options = []) | ||
{ | ||
$options['id'] = $id; | ||
|
||
return $this->request($this->host.$this->reports, $options); | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return string | ||
*/ | ||
public function details(array $options) | ||
{ | ||
return $this->request($this->host.$this->details, $options); | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @param array $options | ||
* | ||
* @return string | ||
*/ | ||
private function request($url, array $options) | ||
{ | ||
if ($this->app_client) { | ||
$options['headers'] = array_merge( | ||
['User-Agent' => $this->app_client], | ||
isset($options['headers']) ? $options['headers'] : [] | ||
); | ||
} | ||
|
||
$response = $this->client->request('GET', $url, $options); | ||
|
||
return $response->getBody()->getContents(); | ||
} | ||
} |
Oops, something went wrong.