public function __destruct() { CoreHelper::logMessage('info', 'mongo destruct...'); if (method_exists($this->_mongo, 'close')) { $this->_mongo->close(true); } }
public function __destruct() { CoreHelper::logMessage('info', 'memcached destruct...'); if (method_exists($this->_memcached, 'quit')) { $this->_memcached->quit(); } }
public function __construct() { $logPath = CoreHelper::loadConfig("log_path", "config"); $logFileExtension = CoreHelper::loadConfig("log_file_extension", "config"); $logThreshold = CoreHelper::loadConfig("log_threshold", "config"); $logDateFormat = CoreHelper::loadConfig("log_date_format", "config"); $logFilePermissions = CoreHelper::loadConfig("log_file_permissions", "config"); $this->_log_path = $logPath !== '' ? $logPath : APPPATH . 'logs/'; $this->_file_ext = isset($logFileExtension) && $logFileExtension !== '' ? ltrim($logFileExtension, '.') : 'php'; file_exists($this->_log_path) || mkdir($this->_log_path, 0755, true); if (!is_dir($this->_log_path) || !CoreHelper::isWriteable($this->_log_path)) { $this->_enabled = false; } if (is_numeric($logThreshold)) { $this->_threshold = (int) $logThreshold; } elseif (is_array($logThreshold)) { $this->_threshold = 0; $this->_threshold_array = array_flip($logThreshold); } if (!empty($logDateFormat)) { $this->_date_fmt = $logDateFormat; } if (!empty($logFilePermissions) && is_int($logFilePermissions)) { $this->_file_permissions = $logFilePermissions; } }
public function __destruct() { CoreHelper::logMessage('info', 'redis destruct...'); if (method_exists($this->_redis, 'disconnect')) { $this->_redis->disconnect(); } }
public function __construct() { self::$instance =& $this; // 每个Controller持有一个单独的CoreLoader实例 $this->load = CoreHelper::loadClass("CoreLoader", '', null, false); CoreHelper::logMessage('info', 'Controller Class Initialized'); }
public function __destruct() { CoreHelper::logMessage('info', 'ssdb destruct...'); if (method_exists($this->_ssdb, 'close')) { $this->_ssdb->close(); } }
public function __construct() { parent::__construct(); if ($this->strTemplate !== null) { $this->template = $this->objTwig->loadTemplate($this->strTemplate); } }
function __construct() { CoreHelper::logMessage('debug', 'Mcurl Class Initialized'); if (!$this->isEnable()) { CoreHelper::logMessage('error', 'Mcurl Class - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.'); } else { $this->curl_parent = curl_multi_init(); } }
public function GetReportsResponse($requestParameters, $requestBody, $oauthRequestUri) { $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method"); // This step is required since the configuration settings might have been changed. $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true); $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false); $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true); $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false); // Determine dest URI $requestUri = ''; if ($requestParameters->ApiName) { // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu" $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName; } else { if ($oauthRequestUri) { // Prepare the request Uri from base Uri and resource Uri. $requestUri = $oauthRequestUri; } else { if ($requestParameters->ResourceUri) { $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri; } else { } } } $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret); $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret); $oauth->enableDebug(); $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION); $oauth->disableSSLChecks(); $httpHeaders = array(); if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) { // IDS call $httpHeaders = array('accept' => 'application/json'); // Log Request Body to a file $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE); if ($this->ResponseCompressor) { $this->ResponseCompressor->PrepareDecompress($httpHeaders); } } else { // IPP call $httpHeaders = array('accept' => 'application/json'); } try { $OauthMethod = OAUTH_HTTP_METHOD_GET; $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders); } catch (OAuthException $e) { //echo "ERROR:\n"; //print_r($e->getMessage()) . "\n"; list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth); $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE); return FALSE; } list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth); // Log Request Body to a file $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE); return array($response_code, $response_xml); }
/** * Initializes a new instance of the RestHandler class. * * @param ServiceContext $context The Service Context */ protected function __construct($context) { $this->serviceContext = $context; $this->RequestCompressor = CoreHelper::GetCompressor($this->serviceContext, true); $this->ResponseCompressor = CoreHelper::GetCompressor($this->serviceContext, false); $this->RequestSerializer = CoreHelper::GetSerializer($this->serviceContext, true); $this->ResponseSerializer = CoreHelper::GetSerializer($this->serviceContext, false); $this->RequestLogging = CoreHelper::GetRequestLogging($this->serviceContext); }
public function pub() { if (count($this->_targets) > 0) { $maps = $this->_targets; foreach ($maps as $key => $val) { $instance = CoreHelper::loadClass($key, "controllers"); if (method_exists($instance, 'process')) { $instance->process($val); } } } }
public function onTask(swoole_server $serv, $taskId, $fromId, $data) { if (isset($data["controller"])) { $controller = $data["controller"]; $method = $data["method"]; $data = $data["data"]; $instance = CoreHelper::loadClass($controller, "controllers/tasks"); if (method_exists($instance, $method)) { $instance->{$method}($serv, $taskId, $fromId, $data); } } }
protected function _process($data) { $analysises = $this->_analysisRoutes; foreach ($analysises as $key => $val) { $instance = CoreHelper::loadClass($val, "analysises"); if ($instance instanceof CoreAnalysis && method_exists($instance, "process")) { $stop = false; $data = $instance->process($data, $stop); if ($stop) { return $data; } } } return $data; }
public function route(array $params) { if (empty($params["router"])) { return; } $maps = self::$_routeMap; foreach ($maps as $key => $val) { if ($key == $params["router"]) { $val = str_replace('.php', '', trim($val, '/')); if (($lastSlash = strrpos($val, '/')) !== FALSE) { $subdir = substr($val, 0, ++$lastSlash); $router = substr($val, $lastSlash); } else { $subdir = ""; $router = $val; } $instance = CoreHelper::loadClass($router, "actions/" . $subdir); if ($instance instanceof CoreAction && method_exists($instance, 'distribute')) { $instance->distribute($params); } break; } } }
file_exists(APPPATH . "vendor/autoload.php") ? require_once APPPATH . "vendor/autoload.php" : die("composer autoload is set to TRUE but " . APPPATH . "vendor/autoload.php was not found."); } elseif (file_exists($composer)) { require_once $composer; } else { die('Could not find the specified ".$config["composer_autoload"]." path: ' . $composer); } } $charset = strtoupper(CoreHelper::loadConfig("charset", "config")); ini_set("default_charset", $charset); if (extension_loaded("mbstring")) { define("MB_ENABLED", TRUE); @ini_set("mbstring.internal_encoding", $charset); mb_substitute_character("none"); } else { define("MB_ENABLED", FALSE); } if (extension_loaded("iconv")) { define("ICONV_ENABLED", TRUE); @ini_set("iconv.internal_encoding", $charset); } else { define("ICONV_ENABLED", FALSE); } if (CoreHelper::isPHP("5.6")) { ini_set("php.internal_encoding", $charset); } require_once BASEPATH . 'CoreController.php'; function &getInstance() { $instance = CoreController::$instance; return $instance; }
function exceptionHandler($exception) { $error = CoreHelper::loadClass('CoreException'); $error->logException('error', 'Exception: ' . $exception->getMessage(), $exception->getFile(), $exception->getLine()); }
public function logException($severity, $message, $filepath, $line) { $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; CoreHelper::logMessage('error', 'Severity: ' . $severity . ' --> ' . $message . ' ' . $filepath . ' ' . $line); }
/** * Returns the response by calling REST service. * * @param ServiceContext $requestParameters The parameters * @param string $requestBody The request body * @param string $oauthRequestUri The OAuth request uri * @return array elements are 0: HTTP response code; 1: HTTP response body */ public function GetResponse($requestParameters, $requestBody, $oauthRequestUri) { $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method"); // This step is required since the configuration settings might have been changed. $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true); $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false); $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true); $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false); // Determine dest URI $requestUri = ''; if ($requestParameters->ApiName) { // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu" $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName; } else { if ($oauthRequestUri) { // Prepare the request Uri from base Uri and resource Uri. $requestUri = $oauthRequestUri; } else { if ($requestParameters->ResourceUri) { $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri; } else { } } } //minorVersion support if ($this->context->minorVersion) { if ($this->queryToArray($requestUri) == false) { $requestUri .= "?minorversion=" . $this->context->minorVersion; } else { $requestUri .= "&minorversion=" . $this->context->minorVersion; } } $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret); $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret); $oauth->enableDebug(); $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION); $oauth->disableSSLChecks(); $httpHeaders = array(); if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) { // IDS call $httpHeaders = array('host' => parse_url($requestUri, PHP_URL_HOST), 'user-agent' => CoreConstants::USERAGENT, 'accept' => '*/*', 'connection' => 'close', 'content-type' => $requestParameters->ContentType, 'content-length' => strlen($requestBody)); // Log Request Body to a file $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE); if ($requestBody && $this->RequestCompressor) { $this->RequestCompressor->Compress($httpHeaders, $requestBody); } if ($this->ResponseCompressor) { $this->ResponseCompressor->PrepareDecompress($httpHeaders); } } else { // IPP call $httpHeaders = array('user-agent' => CoreConstants::USERAGENT); } try { if ('POST' == $requestParameters->HttpVerbType) { $OauthMethod = OAUTH_HTTP_METHOD_POST; } else { if ('GET' == $requestParameters->HttpVerbType) { $OauthMethod = OAUTH_HTTP_METHOD_GET; } } $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders); } catch (OAuthException $e) { //echo "ERROR:\n"; //print_r($e->getMessage()) . "\n"; list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth); $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE); //echo "Response: {$response_code} - {$response_xml} \n"; //var_dump($oauth->debugInfo); //echo "\n"; //echo "ERROR MESSAGE: " . $oauth->debugInfo['body_recv'] . "\n"; // Useful info from Intuit //echo "\n"; return FALSE; } list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth); // Log Request Body to a file $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE); return array($response_code, $response_xml); }
public static function logMessage($level, $message) { if (self::$_log === NULL) { self::$_log = self::loadClass('CoreLog'); } self::$_log->writeLog($level, $message); }
/** * Returns List of entities changed after certain time. * @param array entityList List of entity. * @param long changedSince DateTime of timespan after which entities were changed. * @return IntuitCDCResponse Returns an IntuitCDCResponse. */ public function CDC($entityList, $changedSince) { $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called Method CDC."); // Validate parameter if (count($entityList) <= 0) { $exception = new IdsException('ParameterNotNullMessage'); $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Error, "ParameterNotNullMessage"); IdsExceptionManager::HandleException($exception); } $entityString = implode(",", $entityList); $query = NULL; $uri = NULL; $formattedChangedSince = date("Y-m-d\\TH:m:sP", $this->verifyChangedSince($changedSince)); $query = "entities=" . $entityString . "&changedSince=" . $formattedChangedSince; $uri = "company/{1}/cdc?{2}"; //$uri = str_replace("{0}", CoreConstants::VERSION, $uri); $uri = str_replace("{1}", $this->serviceContext->realmId, $uri); $uri = str_replace("{2}", $query, $uri); // Creates request parameters $requestParameters = $this->getGetRequestParameters($uri, CoreConstants::CONTENTTYPE_APPLICATIONXML); $restRequestHandler = new SyncRestHandler($this->serviceContext); try { // gets response list($responseCode, $responseBody) = $restRequestHandler->GetResponse($requestParameters, NULL, NULL); } catch (Exception $e) { } CoreHelper::CheckNullResponseAndThrowException($responseBody); $returnValue = new IntuitCDCResponse(); try { $xmlObj = simplexml_load_string($responseBody); foreach ($xmlObj->CDCResponse->QueryResponse as $oneObj) { $entities = $this->responseSerializer->Deserialize($oneObj->asXML(), FALSE); $entityName = NULL; foreach ($oneObj->children() as $oneObjChild) { $entityName = (string) $oneObjChild->getName(); break; } $returnValue->entities[$entityName] = $entities; } } catch (Exception $e) { IdsExceptionManager::HandleException($e); } $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Executing Method CDC."); return $returnValue; }
protected function _initLibrary($class, $prefix, $params = false, $objName = null) { $className = $prefix . $class; if (!class_exists($className, false)) { CoreHelper::logMessage('error', 'Non-existent class: ' . $className); } if (empty($objName)) { $objName = strtolower($class); } $CN =& getInstance(); if (isset($CN->{$objName})) { if ($CN->{$objName} instanceof $className) { CoreHelper::logMessage('debug', $className . " has already been instantiated as '" . $objName . "'. Second attempt aborted."); return; } } $this->_classes[$objName] = $class; $CN->{$objName} = isset($params) ? new $className($params) : new $className(); return $this; }
public function getResponse($notify_id) { $transport = strtolower(trim($this->transport)); $partner = trim($this->partner); if ($transport == 'https') { $veryfy_url = $this->httpsVerifyUrl; } else { $veryfy_url = $this->httpVerifyUrl; } $veryfy_url = $veryfy_url . "partner=" . $partner . "¬ify_id=" . $notify_id; $responseTxt = CoreHelper::getHttpResponseGET($veryfy_url, $this->cacert); return $responseTxt; }
public function __destruct() { CoreHelper::logMessage('info', 'nsq destruct...'); $this->_nsq = null; }
/** * This method executes the batch request. */ public function Execute() { $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Started Executing Method Execute for Batch"); // Create Intuit Batch Request $intuitBatchRequest = new IPPIntuitBatchRequest(); $intuitBatchRequest->BatchItemRequest = $this->batchRequests; $uri = "company/{1}/batch?requestid=" . rand() . rand(); $uri = str_replace('{1}', $this->serviceContext->realmId, $uri); // Creates request parameters $requestParameters = NULL; if (0) { // No JSON support here yet //$requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL); } else { $requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONXML, NULL); } $restRequestHandler = new SyncRestHandler($this->serviceContext); try { // Get literal XML representation of IntuitBatchRequest into a DOMDocument $httpsPostBodyPreProcessed = XmlObjectSerializer::getPostXmlFromArbitraryEntity($intuitBatchRequest, $urlResource); $doc = new DOMDocument(); $domObj = $doc->loadXML($httpsPostBodyPreProcessed); $xpath = new DOMXpath($doc); // Replace generically-named IntuitObject nodes with tags that describe contained objects $objectIndex = 0; while (1) { $matchingElementArray = $xpath->query("//IntuitObject"); if (is_null($matchingElementArray)) { break; } if ($objectIndex >= count($intuitBatchRequest->BatchItemRequest)) { break; } foreach ($matchingElementArray as $oneNode) { // Found a DOMNode currently named "IntuitObject". Need to rename to // entity that describes it's contents, like "ns0:Customer" (determine correct // name by inspecting IntuitObject's class). if ($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject) { // Determine entity name to use $entityClassName = get_class($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject); $entityTransferName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName($entityClassName); $entityTransferName = 'ns0:' . $entityTransferName; // Replace old-named DOMNode with new-named DOMNode $newNode = $oneNode->ownerDocument->createElement($entityTransferName); if ($oneNode->attributes->length) { foreach ($oneNode->attributes as $attribute) { $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue); } } while ($oneNode->firstChild) { $newNode->appendChild($oneNode->firstChild); } $oneNode->parentNode->replaceChild($newNode, $oneNode); } break; } $objectIndex++; } $httpsPostBody = $doc->saveXML(); list($responseCode, $responseBody, $responseError) = $restRequestHandler->GetResponse($requestParameters, $httpsPostBody, NULL); } catch (Exception $e) { IdsExceptionManager::HandleException($e); } CoreHelper::CheckResponseErrorAndThrowException($this->serviceContext, $responseError); CoreHelper::CheckNullResponseAndThrowException($responseBody); try { $this->batchResponses = array(); $this->intuitBatchItemResponses = array(); // No JSON support here yet // de serialize object $responseXmlObj = simplexml_load_string($responseBody); foreach ($responseXmlObj as $oneXmlObj) { // process batch item $intuitBatchResponse = $this->ProcessBatchItemResponse($oneXmlObj); $this->intuitBatchItemResponses[] = $intuitBatchResponse; if ($intuitBatchResponse && $intuitBatchResponse->entities && count($intuitBatchResponse->entities)) { $this->batchResponses[] = $intuitBatchResponse->entities; } } } catch (Exception $e) { return NULL; } $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Execute method for batch."); }
public function __construct() { CoreHelper::logMessage('info', 'Model Class Initialized'); }
private static function createProcessSender(array $routes) { $workerNum = count($routes); $serv = self::$_serv; for ($i = 0; $i < $workerNum; $i++) { $class = $routes[$i]; $process = new swoole_process(function () use($class, $serv) { require_once BASEPATH . 'CoreEnvSetting.php'; $instance = CoreHelper::loadClass($class, "controllers/processes"); $instance->process($serv); }); $serv->addProcess($process); } }
/** * Alias to set_template from . * * @access public * @static * @param string $value (default: '') * @return void */ public static function set_formats($value = '') { return parent::set_template('format', $value); }