public function __construct($entityManager, $config) { $this->results = $config['pagination']['results']; $this->offset = $config['pagination']['offset']; $this->fields = $config['fields'][$this->resultName()]['default']; parent::__construct($entityManager, $config); }
public static function route() { //find the request method and, from the uri, get the parameters involved $uri = $_SERVER['REQUEST_URI']; $method = $_SERVER['REQUEST_METHOD']; $path = parse_url($uri); $pattern = sprintf("/^\\/api\\/v%s\\/(?P<action>[^\\/]+)(\\/.*)?\$/", \Webservice\ThisDayInMusic::VERSION); preg_match($pattern, $path['path'], $match); if (!count($match)) { return \Webservice\ThisDayInMusic::output(null, array("code" => 1, "status" => "Invalid uri supplied to the webservice. Please check the documentation.")); } $action = ucfirst($match['action']); $class = "\\Webservice\\ThisDayInMusic\\{$action}"; if (!class_exists($class)) { return \Webservice\ThisDayInMusic::output(null, array("code" => 1, "status" => "Invalid action supplied to the webservice. Please check the documentation.")); } return $class; }
<?php //cron each 2 minutes of the first hour of every day // */2 0 * * * /usr/bin/php pathtoproject/bin/artistTracks.php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../bootstrap.php"; $result = \Webservice\ThisDayInMusic::findArtistTracks($entityManager);
<?php //cron once a day at 00:00 // 0 0 * * * /usr/bin/php pathtoproject/bin/artistTracks.php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../bootstrap.php"; $str = file_get_contents(__DIR__ . "/date.txt"); #$date = new DateTime("now"); $date = new \DateTime($str); $limit = new \Datetime("2014-12-31"); if ($date > $limit) { error_log("Date out of range: " . $date->format('Y-m-d')); exit; } $result = \Webservice\ThisDayInMusic::findEvents($entityManager, $date); if ($result == 0) { error_log("All events for " . $date->format('Y-m-d') . " imported sucessfully."); } date_add($date, date_interval_create_from_date_string('1 days')); $str = file_put_contents(__DIR__ . "/date.txt", $date->format("Y-m-d"));