/** * Constructor * @since Version 3.9 * @param int $routeId * @param object $gtfsProvider */ public function __construct($routeId = null, $gtfsProvider = null) { if (function_exists("getRailpageConfig")) { $this->Config = getRailpageConfig(); } $this->adapter = new Adapter(array("driver" => "Mysqli", "database" => $this->Config->GTFS->PTV->db_name, "username" => $this->Config->GTFS->PTV->db_user, "password" => $this->Config->GTFS->PTV->db_pass, "host" => $this->Config->GTFS->PTV->db_host)); $this->db = new Sql($this->adapter); if (is_object($gtfsProvider)) { $this->Provider = $gtfsProvider; } /** * Fetch the route */ if (!filter_var($routeId, FILTER_VALIDATE_INT)) { return; } $query = sprintf("SELECT route_id, route_short_name, route_long_name, route_desc, route_type, route_url, route_color, route_text_color FROM %s_routes WHERE id = %s", $this->Provider->getDbPrefix(), $routeId); $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); if (!is_array($result)) { return; } foreach ($result as $row) { $row = $row->getArrayCopy(); $this->id = $routeId; $this->route_id = $row['route_id']; $this->short_name = $row['route_short_name']; $this->long_name = $row['route_long_name']; $this->desc = $row['route_desc']; $this->type = $row['route_type']; } }
/** * Constructor * @since Version 3.8.7 */ public function __construct() { if (function_exists("getRailpageConfig")) { $this->Config = getRailpageConfig(); } $this->adapter = new Adapter(array("driver" => "Mysqli", "database" => $this->Config->GTFS->PTV->db_name, "username" => $this->Config->GTFS->PTV->db_user, "password" => $this->Config->GTFS->PTV->db_pass, "host" => $this->Config->GTFS->PTV->db_host)); $this->db = new Sql($this->adapter); }
/** * Constructor * @since Version 3.8.7 * @param string $target */ public function __construct($target = false) { parent::__construct(); if (function_exists("getRailpageConfig")) { $this->Config = getRailpageConfig(); } if ($target) { $this->target = $target; } $this->format = "json"; }
/** * Update the config JSON object * @since Version 3.8.7 */ function setRailpageConfig($config = NULL) { if (!is_object($config)) { throw new Exception("Cannot set Railpage config to JSON file - parameter \$config is invalid"); } $config = json_encode($config, JSON_PRETTY_PRINT); if (RP_WRITE_CONFIG && json_encode(getRailpageConfig(), JSON_PRETTY_PRINT) != $config) { if (!file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "config.railpage.json", $config)) { throw new Exception("Cannot write to " . __DIR__ . DIRECTORY_SEPARATOR . "config.railpage.json"); } } return true; }
/** * Get RP configuration * @since Version 3.9.1 * @return \stdClass */ public static function getConfig() { $Registry = Registry::getInstance(); try { $Config = $Registry->get("config"); } catch (Exception $e) { if (function_exists("getRailpageConfig")) { Debug::logEvent(__METHOD__ . " -- found getRailpageConfig()"); $Config = getRailpageConfig(); } elseif (defined("RP_SITE_ROOT") && file_exists(RP_SITE_ROOT . DS . "config" . DS . "config.railpage.json")) { Debug::logEvent(__METHOD__ . " -- Loading " . RP_SITE_ROOT . DS . "config" . DS . "config.railpage.json"); $Config = json_decode(file_get_contents(RP_SITE_ROOT . DS . "config" . DS . "config.railpage.json")); } elseif (file_exists(dirname(__DIR__) . DS . "config.railpage.json")) { Debug::logEvent(__METHOD__ . " -- Loading " . dirname(__DIR__) . DS . "config.railpage.json"); $Config = json_decode(file_get_contents(dirname(__DIR__) . DS . "config.railpage.json")); } elseif (file_exists(dirname(__DIR__) . DS . "config" . DS . "dist.config.railpage.php")) { Debug::logEvent(__METHOD__ . " -- Loading " . dirname(__DIR__) . DS . "config" . DS . "dist.config.railpage.php"); require_once dirname(__DIR__) . DS . "config" . DS . "dist.config.railpage.php"; $Config = $RailpageConfig; } if (!isset($Config)) { $Config = array("Memcached" => array("Host" => "cache.railpage.com.au", "Port" => 11211)); $Config = json_decode(json_encode($Config)); } $Registry->set("config", $Config); } return $Config; }
/** * Constructor * @since Version 3.7 * @global object $ZendDB * @global object $ZendDB_ReadOnly */ public function __construct() { global $ZendDB, $ZendDB_ReadOnly, $PHPUnitTest; if (isset($PHPUnitTest) && $PHPUnitTest == true) { require "db.dist" . DS . "zend_db.php"; $this->db = $ZendDB; $this->destroy = true; $ZendDB_ReadOnly = $ZendDB; } else { if (isset($ZendDB)) { $this->db = $ZendDB; } elseif (file_exists("db" . DS . "zend_db.php")) { require "db" . DS . "zend_db.php"; $this->db = $ZendDB; $this->destroy = true; } elseif (file_exists(".." . DS . "db" . DS . "zend_db.php")) { require ".." . DS . "db" . DS . "zend_db.php"; $this->db = $ZendDB; $this->destroy = true; } else { // Attempt to resolve the DB connection to a stream path. If it can't be resolved, assume this is a CI environment and load a test DB connector if (stream_resolve_include_path("db" . DS . "connect.php")) { require "db" . DS . "connect.php"; throw new Exception(__CLASS__ . " needs a database object"); $this->db = $db; $this->destroy = true; } } if (isset($ZendDB_ReadOnly)) { $this->db_readonly = $ZendDB_ReadOnly; } elseif (file_exists("db" . DS . "zend_db.php")) { require "db" . DS . "zend_db.php"; $this->db_readonly = $ZendDB_ReadOnly; $this->destroy = true; } elseif (file_exists(".." . DS . "db" . DS . "zend_db.php")) { require ".." . DS . "db" . DS . "zend_db.php"; $this->db_readonly = $ZendDB_ReadOnly; $this->destroy = true; } } /** * Create Memcache object */ if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . "memcache.php")) { require __DIR__ . DIRECTORY_SEPARATOR . "memcache.php"; $this->memcache = $memcache; } /** * Build the StatsD object */ $this->StatsD = new stdClass(); $this->StatsD->target = new stdClass(); /** * Load the config */ if (function_exists("getRailpageConfig")) { $this->Config = getRailpageConfig(); } }