function getLogFileName() { $configs = api_config::getInstance()->profilelog; if (isset($configs[0]) && isset($configs[0]['cfg'])) { return $configs[0]['cfg']; } throw api_testing_exception("profilelog cannot be found in configuration"); }
public static function api_factory($name = "default", $force = false) { $jcr = api_config::getInstance()->jcr; if (empty($jcr[$name])) { return false; } return self::factory($jcr[$name], $name, $force); }
/** * Constructor. */ public function __construct() { //parent::__construct($opts); // TODO Shold session management be handled this way? $sessionid = session_id(); if (empty($sessionid)) { session_start(); } $this->config = api_config::getInstance(); $this->request = api_request::getInstance(); $this->db = api_database::factory(); }
/** Return a database connection @param $name string: name of the connection @param $force bool: force a new connection even if one already exists @return connection */ public static function factory($name = "default", $force = false) { if (isset(self::$instances[$name]) && $force == false) { return self::$instances[$name]; } $db = api_config::getInstance()->database; if (empty($db[$name])) { return false; } self::$instances[$name] = self::get($db[$name]); return self::$instances[$name]; }
function __construct($route, $request, $response) { $cfg = api_config::getInstance(); $this->config = $cfg; $this->params = $route; $this->request = $request; $this->response = $response; // $writerConfig = $cfg->log; // $this->logger = Zend_Log::factory(array($writerConfig)); $this->logger = api_log::getInstance(); $this->dispatcher = new sfEventDispatcher(); $this->init(); }
function __construct() { //$this->db = new Database("mysql:host=localhost;dbname=mapper", "mapper", "mapper"); //echo "\nCalling api_database::factory()\n"; $this->db = api_database::factory(); //echo "\nIn commands_migration_migrations - constructor\n"; //print_r( $this->db ); $this->platform = "mysql"; // get database config $this->config = api_config::getInstance()->database; $this->config = $this->config['default']; //print_r($this->config); }
/** * Reads it's configuration from the 'profilelog' * section of the configuration */ public function __construct() { if (self::$profilelogger != null) { return; } self::$profilelogger = new Zend_Log(); $configs = api_config::getInstance()->profilelog; if (is_null($configs) || count($configs) == 0) { self::$profilelogger->addWriter(new Zend_Log_Writer_Null()); return; } foreach ($configs as $cfg) { $log = $this->createLogObject($cfg['class'], $cfg); self::$profilelogger->addWriter($log); } }
function __construct($l = NULL) { $lang = api_config::getInstance()->lang; if (!$l) { $currentLang = $lang['default']; } else { if (in_array($l, $lang['languages'])) { $currentlang = $l; } else { // No language what to do? throw exception(new Exception("Language {$l} missing")); } } $langFile = PROJECT_DIR . "config/locale/" . $currentLang . ".yml"; $yaml = file_get_contents($langFile); $langYaml = sfYaml::load($yaml); $langArray = $langYaml[$currentLang]; $this->content = $langArray; }
public function __construct() { if (self::$logger !== null) { // Already initialized return; } $config = api_config::getInstance()->log; //$config['writerParams']['stream'] = PROJECT_DIR.$config['writerParams']['stream']; if (empty($config[0]['class'])) { // No Logging, Not Activated self::$logger = false; return; } self::$logger = new Zend_Log(); foreach ($config as $cfg) { $cfg['cfg'] = PROJECT_DIR . $cfg['cfg']; $log = $this->createLogObject($cfg['class'], $cfg); if ($cfg['class'] == 'Writer_Mock') { self::$mockWriter = $log; } self::$logger->addWriter($log); } }
/** * Handle a subscription request. * * @param $post * A valid PubSubHubbub subscription request. */ public function subscribe($post) { //error_log( //print_r($post); // Authenticate $received_secret = $post['secret']; api_log::log('DEBUG', "Received secret: {$received_secret}"); $cfg = api_config::getInstance()->hub; $secret = md5($cfg['secret'] . $post['hub_callback']); if ($secret == $received_secret and isset($post['hub_topic']) && isset($post['hub_callback']) && $this->verify($post)) { $this->subscriptions->save($post['hub_topic'], $post['hub_callback'], isset($post['secret']) ? $post['secret'] : ''); // header('HTTP/1.1 204 "No Content"', null, 204); // exit(); */ echo "Good"; return true; } echo "not found"; return false; //header('HTTP/1.1 404 "Not Found"', null, 404); //exit(); */ }
/** * Creates a new exception handler instances for the given class name. * * Will look up the following keys in that order in the configuration * and use the first exception handler for which a handler can be * instantiated. Uses api_exceptionhandler::getExceptionHandler(). * - $eClassname * - basename of $eClassname (see api_helpers_class::getBaseName) * - Wildcard (api_exceptionhandler::EXCEPTION_WILDCARD) * * If none of these three tests returns an exception handler then * the default handler as specified in api_exceptionhandler::DEFAULT_HANDLER * is loaded. * * @param $eClassName string: Class name of the exception to create the * exception handler for. * @return api_exceptionhandler_base instance */ private static function createInstance($eClassName) { $variations = array($eClassName, api_helpers_class::getBaseName($eClassName), self::EXCEPTION_WILDCARD); $cfg = api_config::getInstance()->exceptionhandler; if (is_array($cfg)) { foreach ($variations as $handler) { if (isset($cfg[$handler])) { $handler = self::getExceptionHandlerClassName($cfg[$handler]); return new $handler(); } } } $handler = self::getExceptionHandlerClassName(self::DEFAULT_HANDLER); return new $handler(); }
/** * Use the given host name to find it's corresponding configuration * in the configuration file. * * If the host is not found in the configuration, null is returned. * * Returns an associative array with the following keys: * @retval host string: The host name to be used for lookups in the * commandmap. This is one of the following values from the * configuration in that order: `host', `sld', hash key. * @retval sld string: Subdomain as specified in the config using `sld'. * @retval tld string: Topdomain as specified in the config using `tld'. * If tld is not specified but the sld is, then the tld is * extracted from the hostname automatically. * @retval path string: Path as specified in the config. Can be used to * "mount" the application at the specified point. Stored in * the global constants API_MOUNTPATH. * * @config <b>hosts</b> (hash): Contains all host configurations. The * hash keys specify the host name. * @config <b>host-><em>hostname</em>->host</b> (string): * Overwrite the host name from the key. * @config <b>host-><em>hostname</em>->sld</b> (string): * Specify a sublevel domain for this host. This value can be * accessed using api_request::getSld(). * @config <b>host-><em>hostname</em>->tld</b> (string): * Specify a top-level domain for this host. This value can be * accessed using api_request::getTld(). If sld is specified but * the value isn't, then the tld is computed automatically. * @config <b>host-><em>hostname</em>->path</b> (string): * Path where this application is mounted on. This has * implications for the routing engine (see api_routing). Defaults * to "/". * @param $hostname: Host name to return config for. */ public static function getHostConfig($hostname) { $hosts = array(); $host = null; // Read config $cfg = api_config::getInstance(); if ($cfg->hosts) { $hosts = $cfg->hosts; foreach ($hosts as $key => &$hostconfig) { $lookupName = $key; if (isset($hostconfig['host'])) { $lookupName = $hostconfig['host']; } else { if (isset($hostconfig['sld'])) { $lookupName = $hostconfig['sld']; } } $hostconfig['host'] = $lookupName; if ($key == $hostname) { $host = $hostconfig; break; } else { if (api_helpers_string::matchWildcard($key, $hostname)) { $host = $hostconfig; if ($lookupName == $key) { // Replace host with current hostname $host['host'] = $hostname; } break; } } } } // Host not found if (is_null($host)) { return null; } // Calculate tld from hostname if sld is set. if (isset($host['sld']) && !isset($host['tld'])) { if (strpos($hostname, $host['sld'] . '.') === 0) { // Hostname starts with sld $host['tld'] = substr($hostname, strlen($host['sld']) + 1); } } // Return values $path = !empty($host['path']) ? $host['path'] : '/'; if ($path[0] !== '/') { $path = '/' . $path; } return array('host' => $host['host'], 'tld' => @$host['tld'], 'sld' => @$host['sld'], 'path' => $path); }
/** * Gets a language from the current request. The following * positions are checked for a language: * - Path (beginning of path). * - HTTP Accept headers. * - Default. * * @param $path string: Path to parse. * @return hash: Parsed path. */ private function parseLanguage($path) { $newpath = $path; if ($retval = $this->getLanguageFromPath($path)) { return $retval; } // lang is in ACCEPT_LANGUAGE $config = api_config::getInstance(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && $config->acceptLanguage !== false) { $accls = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (is_array($accls)) { foreach ($accls as $accl) { // Does not respect coefficient $l = substr($accl, 0, 2); if (in_array($l, $this->outputLangs)) { return array('path' => $newpath, 'lang' => $l); } } } } return array('path' => $newpath, 'lang' => $this->defaultLang); }