private function parseResponse($data) { $res = json_decode($data); if (!$res) { return null; } foreach ($res->query->pages as $page) { if (!isset($page->revisions[0])) { return null; } $content = trim($page->revisions[0]->{'*'}); if (substr($content, 0, 9) == '#REDIRECT') { $x = explode(' ', $content, 2); $redirectTo = self::stripMediawikiLinks($x[1]); nfo('REDIRECT: ' . $redirectTo); return $this->fetchArticle($redirectTo); } return new Article($content); } return null; }
<?php require __DIR__ . '/../vendor/autoload.php'; $ipProvider = MartinLindhe\MyIp\IpProvider\IpProvider::factory(); $ip = $ipProvider->getIPv4(); nfo("ip " . $ip); do { sleep(30); try { $newIp = $ipProvider->getIPv4(); if ($ip != $newIp) { nfo("ip changed to " . $newIp); $ip = $newIp; } else { echo "."; } } catch (Exception $e) { nfo('EXCEPTION ' . $e->getMessage()); } } while (1);
<?php require_once __DIR__ . '/../vendor/autoload.php'; putenv('DEBUG=0'); dbgTime('hej'); nfoTime('hej'); errTime('hej'); dbg('hej'); nfo('hej'); err('hej');
<?php require_once __DIR__ . '/../vendor/autoload.php'; use MartinLindhe\Traits\DiskCacheTrait; class Brain { use DiskCacheTrait; public function __construct() { $this->cacheTtlSeconds(1); $this->store('name', 'mr cool'); } } $brain = new Brain(); $res = $brain->load('name'); nfo("got " . $res); sleep(2); $res = $brain->load('name'); nfo("got " . $res);
<?php require __DIR__ . '/../vendor/autoload.php'; $ipProvider = MartinLindhe\MyIp\IpProvider\IpProvider::factory(); $ip = $ipProvider->getIPv4(); nfo("ip " . $ip);