Skip to content

Commit

Permalink
Merge pull request #4 from plcf5/main
Browse files Browse the repository at this point in the history
upd
  • Loading branch information
li-hoy committed Mar 23, 2022
2 parents abbe28e + 7cd8985 commit 3f953bc
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions assistent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ class Assistent
private
$amo_client,
$storage,
$storage_path,
$storage_default_key;

public function __construct(
object $amoClient,
string $storagePath = ""
string $storagePath
) {
if (empty($storagePath)) {
throw new \Exception("Storage path is empty.");
}
$this->storage_path = $storagePath;
$this->setStorage($this->storage_path);
// set amo client
if ($amoClient instanceof AmoClient) {
$this->amo_client = $amoClient;
} else {
$this->setAmoClient($amoClient);
}

// set storage
if (false === empty($storagePath)) {
$this->setStorage($storagePath);
}
$this->storage_default_key = 'cache';
}

Expand Down Expand Up @@ -65,9 +66,9 @@ public function getFromStorage(
/**
* puts data into storage in json format
*
* @param data
* @param path
* @return void
* @param mixed data
* @param string path
* @return bool
*/
public function saveToStorage(
$data,
Expand All @@ -94,6 +95,7 @@ protected function setStorage(string $path)
{
$subfolderList = [];
$subfolderLine = "";

if (false === empty($path)) {
throw new \Exception("Path is empty.");
}
Expand All @@ -116,7 +118,7 @@ protected function setStorage(string $path)
}
$dir = $dir . "/";
}
$this->sorage = $fm;
$this->storage = $fm;
}

public function getCusomFieldValues($cf)
Expand Down Expand Up @@ -177,16 +179,15 @@ public function getEntityCategoryByType($entityType)
public function setAmoClient(
object $config
) {
if (empty($name)) {
throw new \Exception("Argument 'name' is empty");
}
$client = AmoClient::setInstance($config->oauth);
$client->queries->logs($config->log_queries ?? false);
$client->queries->setDelay($config->queries_delay ?? 0.15);
$client->setOauthPath($config->oauth_storage ?? (self::$storage_path . '/Oauth'));
$client->queries->setDelay($config->query_delay ?? 0.15);
$client->setOauthPath(
$config->oauth_storage ?? (self::$storage_path . '/Oauth')
);
AmoAccount::setCacheTime($config->account_cache_time ?? 1800);
self::$amo_clients[$name] = $client;
return self::$amo_clients[$name];
self::$amo_client = $client;
return self::$amo_client;
}

/**
Expand Down

0 comments on commit 3f953bc

Please sign in to comment.