public function __construct($shop_domain, $token, $api_key, $secret) { $this->name = "ShopifyClient"; $this->shop_domain = $shop_domain; $this->token = $token; $this->api_key = $api_key; $this->secret = $secret; \Erdiko::log(null, "{$shop_domain}, {$token}, {$api_key}, {$secret}"); }
/** Before */ public function _before() { $this->setThemeName('bootstrap'); $this->prepareTheme(); $this->cacheObj = \Erdiko::getCache(); // \Erdiko::log(null, "GET: ".print_r($_GET, true)); \Erdiko::log(null, "code (0): " . $this->cacheObj->get('shopify_code')); \Erdiko::log(null, "shop (0): " . $this->cacheObj->get('shopify_shop')); \Erdiko::log(null, "token (0): " . $this->cacheObj->get('shopify_token')); if (isset($_GET['code'])) { $this->cacheObj->put('shopify_code', $_GET['code']); $this->cacheObj->put('shopify_shop', $_GET['shop']); } if (empty($this->cacheObj->get('shopify_code'))) { $shop = $this->returnSite(); //var_dump($shop); $this->cacheObj->put('shopify_shop', $shop); $this->shopify = new Shopify($shop, "", $this->returnApiKey(), $this->returnSecret()); // get the URL to the current page $pageURL = 'http'; // if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } // Redirect to Shopfy to get authorization header("Location: " . $this->shopify->getAuthorizeUrl($this->returnScope(), $pageURL)); } $this->shopify = new Shopify($this->cacheObj->get('shopify_shop'), "", $this->returnApiKey(), $this->returnSecret()); // Check for an existing token, if not present request one using the code if (empty($this->cacheObj->get('shopify_token'))) { $token = $this->shopify->getAccessToken($this->cacheObj->get('shopify_code')); $this->cacheObj->put('shopify_token', $token); } \Erdiko::log(null, "code (1): " . $this->cacheObj->get('shopify_code')); \Erdiko::log(null, "shop (1): " . $this->cacheObj->get('shopify_shop')); \Erdiko::log(null, "token (1): " . $this->cacheObj->get('shopify_token')); // Set the token within shopify so we can use the API $this->shopify->setToken($this->cacheObj->get('shopify_token')); }
/** * Hooks */ ToroHook::add("404", function ($vars = array()) { // error_log("vars: ".print_r($vars, true)); if (empty($vars['message'])) { $vars['message'] = "Sorry, we cannot find that page."; } if (empty($vars['error'])) { $vars['error'] = $vars['message']; } if (!isset($vars['path_info'])) { $vars['path_info'] = ""; } Erdiko::log(\Psr\Log\LogLevel::ERROR, "404 {$vars['path_info']} {$vars['error']}"); // For a simple text only 404 page use this... // echo "Sorry, we cannot find that URL"; // die; // don't let the calling controller continue // For a themed 404 page... $theme = new \erdiko\core\Theme('bootstrap'); $theme->addCss('//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css'); $theme->addCss('/themes/bootstrap/css/font-awesome-animation.css'); $response = new \erdiko\core\Response($theme); $response->setContent(\Erdiko::getView('404', $vars)); $response->send(); }); ToroHook::add("500", function ($vars = array()) { // error_log("vars: ".print_r($vars, true)); Erdiko::log(\Psr\Log\LogLevel::ERROR, "500 {$vars['path_info']} {$vars['error']}"); echo "Sorry, something went wrong"; });
public function testLogs() { //Initialize a File object locally $fileObj = new \erdiko\core\datasource\File(); $logFolder = \ROOT . "/var/logs"; $sampleText = "This is a sample log for Erdiko class test"; /** * First test * * Log a regular message */ Erdiko::log($sampleText); $return = $fileObj->read("system.log", $logFolder); $this->assertTrue(strpos($return, $sampleText) !== false); /** * First test * * Log a exception message */ $sampleText = "This is a sample EXCEPTION log for Erdiko class test"; Erdiko::log($sampleText, null, 'exception'); $return = $fileObj->read("exception.log", $logFolder); $this->assertTrue(strpos($return, $sampleText) !== false); //Clean up $fileObj->delete("system.log", $logFolder); $fileObj->delete("exception.log", $logFolder); }