public static function append($string) { if (!self::$enabled) { return; } $date = date('Y-m-d h:i:s A'); $auth = Config::getInstance()->authenticationType; file_put_contents(self::getPath(), "[{$date}] [{$auth}] {$string} \n", FILE_APPEND); }
/** * @return string Absolute path to file. * @throws \Exception */ public function getPath() { // Default cache storage path (in library root). $defaultCachePath = __DIR__ . '/../../cache/'; // Is a cache path specified in the configuration? $configCachePath = Config::getInstance()->cachePath; if (!empty($configCachePath)) { // Verify that the directory actually exists. if (!is_dir($configCachePath)) { throw new \Exception('Invalid cache path specified in configuration!'); } // Return the custom path return $configCachePath . $this->getId(); } // Return the default cache path. return $defaultCachePath . $this->getId(); }
/** * @param null $authType 'BasicHttp' or 'OAuth' * @throws \Exception */ public function __construct($authType = null) { // Inject user instance $this->user = User::getInstance(); if (!empty(Config::getInstance()->oauthToken)) { $this->injectOAuthToken(Config::getInstance()->oauthToken); } // If no $authType was passed to the constructor, return. if (null == $authType) { // Is an module type specified in the configuration? if (null != $this->getAuthType()) { // Set the authentication type from configuration. $this->setAuthenticationType($this->getAuthType()); } return; } // Set the authentication type as passed to constructor. $this->setAuthenticationType($authType); }
/** * Return a user's Basecamp Account ID. * @return bool|string * @throws \Exception */ public function getAccountId() { // If module type if basic http, return the account ID specified in the configuration. if (Config::getInstance()->authenticationType == AuthType::BASIC_HTTP) { // If using Basic Http, a specified account ID is required in the configuration. if (empty(Config::getInstance()->accountId)) { throw new \Exception('No account ID set in configuration!'); } // Return the account ID from configuration. return Config::getInstance()->accountId; } if (Config::getInstance()->authenticationType == AuthType::OAUTH) { $auth = new Authorization(); $auth->load(); foreach ($auth->accounts as $account) { if ($account->product == "bcx") { return $account->id; } } } return false; }
/** * Initialize the Basecamp class. */ public function __construct() { $this->auth = new Authorizer(); $this->api = new API(); $this->config = Config::getInstance(); }
public function setUp() { // Set configuration object. $this->config = \Zawntech\BasecampAPI\Config::getInstance(); }
public function __construct() { // Load configuration. $this->config = Config::getInstance(); }
public function __construct($baseUrl, $args = [], $method = 'GET') { // Get configuration. $config = Config::getInstance(); // Validate configuration $config->validateConfiguration(); // Assign constructor arguments to object $this->baseUrl = $baseUrl; $this->args = $args; $this->method = $method; // Create cache object. $this->cache = new RequestCache($this); /* if ( false !== $this->cache->get() ) { $this->response = $this->cache->get()->response; $this->fromCache = true; return; } */ // Initialize the curl instance. $this->curl = curl_init(); // If this is a GET request, prepare the argument string, if supplied. if ($method == 'GET') { if (!empty($args)) { // Does the base url end in a ? character? if (false === strpos($baseUrl, '?')) { // Append the ? character $baseUrl .= '?'; } // Append the query arguments string. $baseUrl .= http_build_query($args); } } // Authorize. curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); // Set the application identity as part of the request. $userAgent = "{$config->applicationName} ({$config->applicationContact})"; curl_setopt($this->curl, CURLOPT_USERAGENT, $userAgent); // Set the URL option for the curl instance. curl_setopt($this->curl, CURLOPT_URL, $baseUrl); // Return transfer curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); // Get the headers curl_setopt($this->curl, CURLOPT_HEADER, true); curl_setopt($this->curl, CURLINFO_HEADER_OUT, true); // Verify SSL connections? if (!$this->verifySSL) { curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); } // If this is a post request, assign the arguments. if (strtoupper($method) == 'POST') { curl_setopt($this->curl, CURLOPT_POST, true); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->args)); } // Put request? if (strtoupper($method) == 'PUT') { curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->args)); } }
public function setUp() { parent::setUp(); // Create the configuration object. $this->config = Config::getInstance(); }