Archived
1
0
Fork 0

Composer PSR-4 autoloader

This commit is contained in:
Alexander Yakovlev 2019-07-29 13:35:32 +07:00
parent b964c061c0
commit 886ea58b45
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
30 changed files with 367 additions and 581 deletions

15
bot.php
View file

@ -17,9 +17,11 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
require "vendor/autoload.php";
require_once ("vendor/autoload.php");
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Oreolek\Game;
use Oreolek\Source;
use Oreolek\Publisher;
use Revolution\Mastodon\MastodonClient; use Revolution\Mastodon\MastodonClient;
use \GuzzleHttp\Client as GuzzleClient; use \GuzzleHttp\Client as GuzzleClient;
use Mremi\UrlShortener\Provider\Bitly\BitlyProvider; use Mremi\UrlShortener\Provider\Bitly\BitlyProvider;
@ -29,15 +31,6 @@ $config = Yaml::parse(file_get_contents('config.yml'));
define('STYLE',$config['STYLE']); define('STYLE',$config['STYLE']);
define('FORMAT',$config['FORMAT']); define('FORMAT',$config['FORMAT']);
require_once "Game.php";
require_once "Source.php";
require_once "Publisher.php";
require_once "_download.php";
$loader = new \Aura\Autoload\Loader;
$loader->register();
$loader->addPrefix('Source', 'Source');
$loader->addPrefix('Publisher', 'Publisher');
$mastodon = new Publisher\Mastodon($config); $mastodon = new Publisher\Mastodon($config);
$jabber = new Publisher\Jabber($config); $jabber = new Publisher\Jabber($config);
$telegram = new Publisher\Telegram($config); $telegram = new Publisher\Telegram($config);

View file

@ -1,7 +1,6 @@
{ {
"minimum-stability": "dev", "minimum-stability": "dev",
"require": { "require": {
"aura/autoload": "^2.0",
"sabre/xml": "^2.0", "sabre/xml": "^2.0",
"addwiki/mediawiki-api": "^0.7.2", "addwiki/mediawiki-api": "^0.7.2",
"symfony/dom-crawler": "^4.0", "symfony/dom-crawler": "^4.0",
@ -18,5 +17,10 @@
}, },
"scripts": { "scripts": {
"test": "./vendor/bin/phpunit" "test": "./vendor/bin/phpunit"
},
"autoload": {
"psr-4": {
"Oreolek\\": "src/"
}
} }
} }

743
composer.lock generated

File diff suppressed because it is too large Load diff

13
run.php
View file

@ -17,17 +17,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
use Symfony\Component\Yaml\Yaml;
require "vendor/autoload.php"; require "vendor/autoload.php";
require "Game.php"; use Symfony\Component\Yaml\Yaml;
require "Source.php"; use Oreolek\Game;
use Oreolek\Source;
$config = Yaml::parse(file_get_contents('config.yml')); $config = Yaml::parse(file_get_contents('config.yml'));
define('STYLE',$config['STYLE']); define('STYLE',$config['STYLE']);
define('FORMAT',$config['FORMAT']); define('FORMAT',$config['FORMAT']);
$loader = new \Aura\Autoload\Loader;
$loader->register();
$loader->addPrefix('Source', 'Source');
$parsers = 'all'; $parsers = 'all';
if (PHP_SAPI !== 'cli') { if (PHP_SAPI !== 'cli') {
@ -66,7 +63,7 @@ if ($parsers === 'all') {
function check($classname, $command) { function check($classname, $command) {
global $parsers; global $parsers;
if (is_array($parsers) && in_array($command, $parsers)) { if (is_array($parsers) && in_array($command, $parsers)) {
$cname = 'Source\\'.$classname; $cname = 'Oreolek\\Source\\'.$classname;
(new $cname())->check(); (new $cname())->check();
} }
} }

View file

@ -15,28 +15,31 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Oreolek;
function get_text($url) { class Downloader {
$curl = curl_init(); public static function get_text($url) {
curl_setopt_array($curl, array( $curl = curl_init();
CURLOPT_RETURNTRANSFER => 1, curl_setopt_array($curl, array(
CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1,
)); CURLOPT_URL => $url,
$resp = curl_exec($curl); ));
curl_close($curl); $resp = curl_exec($curl);
return $resp; curl_close($curl);
} return $resp;
}
function download($url, $outFile) {
$options = array( public static function download($url, $outFile) {
CURLOPT_FILE => fopen($outFile, 'w'), $options = array(
CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files CURLOPT_FILE => fopen($outFile, 'w'),
CURLOPT_URL => $url CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files
); CURLOPT_URL => $url
);
$ch = curl_init();
curl_setopt_array($ch, $options); $ch = curl_init();
curl_exec($ch); curl_setopt_array($ch, $options);
curl_close($ch); curl_exec($ch);
curl_close($ch);
}
} }

View file

@ -15,7 +15,9 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Oreolek;
use \Pandoc\Pandoc; use \Pandoc\Pandoc;
class Game { class Game {

View file

@ -1,4 +1,6 @@
<?php <?php
namespace Oreolek;
class Publisher { class Publisher {
public $text; public $text;
protected $dry_run = true; protected $dry_run = true;

View file

@ -1,4 +1,7 @@
<?php <?php
namespace Oreolek\Publisher;
use \Oreolek\Publisher;
class Jabber extends Publisher { class Jabber extends Publisher {
protected $client; protected $client;
protected $text; protected $text;

View file

@ -1,4 +1,7 @@
<?php <?php
namespace Oreolek\Publisher;
use \Oreolek\Publisher;
class Mastodon extends Publisher { class Mastodon extends Publisher {
protected $client; protected $client;

View file

@ -1,4 +1,7 @@
<?php <?php
namespace Oreolek\Publisher;
use \Oreolek\Publisher;
class Telegram extends Publisher { class Telegram extends Publisher {
protected $client; protected $client;
protected $chat_id; protected $chat_id;

View file

@ -16,11 +16,11 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek;
use \Symfony\Component\DomCrawler\Crawler; use \Symfony\Component\DomCrawler\Crawler;
use \Game;
use \GuzzleHttp\Client as GuzzleClient; use \GuzzleHttp\Client as GuzzleClient;
use Game;
abstract class Source { abstract class Source {
// Title // Title

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Anivisual extends Source { class Anivisual extends Source {
public $title = "Anivisual"; public $title = "Anivisual";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
/** /**
* Парсер для Apero.ru * Парсер для Apero.ru

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
/** /**
* And here's the problem: there are no publication dates. * And here's the problem: there are no publication dates.

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Gamejolt extends Source { class Gamejolt extends Source {
public $title = "GameJolt"; public $title = "GameJolt";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Hyperbook extends Source { class Hyperbook extends Source {
public $title = "Гиперкнига"; public $title = "Гиперкнига";

View file

@ -16,7 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Oreolek\Game;
use \Oreolek\Source;
class HyperbookEn extends Hyperbook { class HyperbookEn extends Hyperbook {
public $title = "Гиперкнига"; public $title = "Гиперкнига";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class IFDB extends Source { class IFDB extends Source {
public $title = "IFDB"; public $title = "IFDB";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Instead extends Source { class Instead extends Source {
public $title = "INSTEAD репозиторий"; public $title = "INSTEAD репозиторий";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Instory extends Source { class Instory extends Source {
public $title = "Instory"; public $title = "Instory";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
use \Pandoc\Pandoc; use \Pandoc\Pandoc;
class Itch extends Source { class Itch extends Source {

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Kvester extends Source { class Kvester extends Source {
public $title = "Квестер"; public $title = "Квестер";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Qsp extends Source { class Qsp extends Source {
public $title = "Библиотека QSP"; public $title = "Библиотека QSP";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Questbook extends Source { class Questbook extends Source {
public $title = "Сторигеймы"; public $title = "Сторигеймы";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
use \Symfony\Component\DomCrawler\Crawler; use \Symfony\Component\DomCrawler\Crawler;
use \GuzzleHttp\Cookie\CookieJar; use \GuzzleHttp\Cookie\CookieJar;
use \GuzzleHttp\Cookie\SetCookie; use \GuzzleHttp\Cookie\SetCookie;

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
use \Symfony\Component\DomCrawler\Crawler; use \Symfony\Component\DomCrawler\Crawler;
class Textadventures extends Source { class Textadventures extends Source {

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class Urq extends Source { class Urq extends Source {
public $title = "Библиотека URQ"; public $title = "Библиотека URQ";

View file

@ -16,9 +16,10 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Source; namespace Oreolek\Source;
use \Game; use \Oreolek\Game;
use \Oreolek\Source;
class VNDB extends Source { class VNDB extends Source {
public $title = "VNDB"; public $title = "VNDB";

View file

@ -79,8 +79,8 @@ class Wikipage {
]); ]);
if (empty($pagetitle)) { if (empty($pagetitle)) {
echo 'ERROR: Page has no title.'; echo 'ERROR: Page has no title.';
var_dump($this->game); print_r($this->game);
die(); return;
} }
$exists = $this->exists($pagetitle); $exists = $this->exists($pagetitle);
if (!$config['DRY_RUN'] && !$exists) { if (!$config['DRY_RUN'] && !$exists) {

View file

@ -17,17 +17,13 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
use Symfony\Component\Yaml\Yaml;
require "vendor/autoload.php"; require "vendor/autoload.php";
require "Game.php"; use Symfony\Component\Yaml\Yaml;
require "Source.php"; use Oreolek\Game;
require "Wikipage.php"; use Oreolek\Source;
$config = Yaml::parse(file_get_contents('config.yml')); use Oreolek\Wikipage;
$loader = new \Aura\Autoload\Loader;
$loader->register();
$loader->addPrefix('Source', 'Source');
$config = Yaml::parse(file_get_contents('config.yml'));
if (!isset($argv[1])) { if (!isset($argv[1])) {
echo 'Please provide the direct URL to the game page.'.PHP_EOL; echo 'Please provide the direct URL to the game page.'.PHP_EOL;
die(); die();