Archived
1
0
Fork 0

Autoloading

This commit is contained in:
Alexander Yakovlev 2017-01-23 14:15:26 +07:00
parent 279ca0d6ad
commit 10d29714e2
8 changed files with 85 additions and 14 deletions

View file

@ -1,8 +1,12 @@
<?php
namespace Source;
use \Game;
class Apero extends Source {
public $title = "Apero";
protected function parse() {
$formatter = new IntlDateFormatter( 'ru', IntlDateFormatter::LONG, IntlDateFormatter::NONE );
$formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE );
$this->dom->loadFromUrl('http://apero.ru/');
$games = $this->dom->find('.tabled-game-block');
foreach ($games as $gameBlock) {

View file

@ -1,4 +1,8 @@
<?php
namespace Source;
use \Game;
class Hyperbook extends Source {
public $title = "Гиперкнига";
protected function parse() {
@ -31,7 +35,7 @@ class Hyperbook extends Source {
}
}
foreach ($games as $game) {
$date = DateTime::createFromFormat('d.m.y', $game->date);
$date = \DateTime::createFromFormat('d.m.y', $game->date);
if ($date === false) continue;
$date = $date->format('U');
if ($date < $this->period) continue;

View file

@ -1,4 +1,8 @@
<?php
namespace Source;
use \Game;
class Instead extends Source {
public $title = "Неофициальный INSTEAD репозиторий";
protected function insteadfeed($url) {
@ -6,7 +10,7 @@ class Instead extends Source {
$games = $this->dom->find('.game');
foreach ($games as $gameBlock) {
$date = trim($gameBlock->find('.b .date b')->innerHtml);
$date = DateTime::createFromFormat('Y.m.d', $date);
$date = \DateTime::createFromFormat('Y.m.d', $date);
$date = $date->format('U');
if ($date < $this->period) continue;
$game = new Game;

View file

@ -1,5 +1,9 @@
<?php
use PHPHtmlParser\Dom;
namespace Source;
use \PHPHtmlParser\Dom;
use \Game;
abstract class Source {
public $title;
protected $dom;

View file

@ -1,4 +1,8 @@
<?php
namespace Source;
use \Game;
class Storymaze extends Source {
public $title = "Storymaze";
protected function parse() {

View file

@ -1,6 +1,7 @@
{
"require": {
"paquettg/php-html-parser": "^1.7",
"cebe/markdown": "^1.1"
"cebe/markdown": "^1.1",
"aura/autoload": "^2.0"
}
}

53
composer.lock generated
View file

@ -4,9 +4,58 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "db0ca71f544576b897008cce65e8915f",
"content-hash": "c3fea45556544fd0076bae094fb1aa1a",
"hash": "ed82f7845fcffd3eb53e85992c271a96",
"content-hash": "452359d12c8b2c082eb4e9436c8538c9",
"packages": [
{
"name": "aura/autoload",
"version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/auraphp/Aura.Autoload.git",
"reference": "306a7f8d3cb58fb6f94bcff1dddf20c543f68668"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/auraphp/Aura.Autoload/zipball/306a7f8d3cb58fb6f94bcff1dddf20c543f68668",
"reference": "306a7f8d3cb58fb6f94bcff1dddf20c543f68668",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"aura": {
"type": "library"
}
},
"autoload": {
"psr-4": {
"Aura\\Autoload\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Aura.Autoload Contributors",
"homepage": "https://github.com/auraphp/Aura.Autoload/contributors"
}
],
"description": "Provides a PSR-4 compliant autoloader implementation.",
"homepage": "https://github.com/auraphp/Aura.Autoload",
"keywords": [
"PSR-4",
"SPL autoloader",
"autoload",
"autoloader",
"class loader"
],
"time": "2016-10-03 19:36:19"
},
{
"name": "cebe/markdown",
"version": "1.1.1",

View file

@ -1,10 +1,11 @@
<?php
require "vendor/autoload.php";
spl_autoload_register(function ($class_name) {
include $class_name . '.php';
});
require "Game.php";
$loader = new \Aura\Autoload\Loader;
$loader->register();
$loader->addPrefix('Source', 'Source');
(new Apero())->print();
(new Instead())->print();
(new Storymaze())->print();
(new Hyperbook())->print();
(new Source\Apero())->print();
(new Source\Instead())->print();
(new Source\Storymaze())->print();
(new Source\Hyperbook())->print();