Esempio n. 1
0
/**
 * 2016-08-22
 * @param DataObject|C|null $c [optional]
 * @param string $path [optional]
 * @param string|array(string => mixed)|null $default [optional]
 * @return string|array(string => mixed)|null
 */
function df_customer_info_get(DataObject $c = null, $path = null, $default = null)
{
    $c = $c ?: df_current_customer();
    /** @var string|array(string => mixed)|null $result */
    if (!$c) {
        $result = null;
    } else {
        /** @var string $json */
        $json = $c[Schema::F__DF];
        /** @var array(string => mixed) $array */
        $array = is_null($json) ? [] : df_json_decode($json);
        $result = is_null($path) ? $array : dfa_deep($array, $path, $default);
    }
    return $result;
}
Esempio n. 2
0
 /**
  * 2015-11-27
  * @return array(string => mixed)
  * @throws \Exception
  */
 private function responseA()
 {
     if (!isset($this->{__METHOD__})) {
         /** @var bool $debug */
         $debug = true;
         /** @var array(string => mixed) $result */
         $result = df_json_decode($debug || !S::s()->serverApiKey() ? df_http_get('https://mage2.pro/google-fonts.json') : df_http_get('https://www.googleapis.com/webfonts/v1/webfonts', ['key' => S::s()->serverApiKey(), 'sort' => 'alpha']));
         /**
         * 2015-11-17
         * В документации об этом ни слова не сказано,
         * однако в случае сбоя Google API возвращает JSON следующией структуры:
         				{
         					error: {
         						errors: [
         							{
         								domain: "usageLimits",
         								reason: "accessNotConfigured",
         								message: "Access Not Configured. The API (Google Fonts Developer API) is not enabled for your project. Please use the Google Developers Console to update your configuration.",
         								extendedHelp: "https://console.developers.google.com"
         							}
         						],
         						code: 403,
         						message: "Access Not Configured. The API (Google Fonts Developer API) is not enabled for your project. Please use the Google Developers Console to update your configuration."
         					}
         				}
         * https://developers.google.com/fonts/docs/developer_api
         */
         /** @var array(string => mixed)|null $result */
         $error = dfa($result, 'error');
         if ($error) {
             throw (new Exception($error))->standard();
         }
         /**
          * 2015-11-27
          * https://developers.google.com/fonts/docs/developer_api#Example
          */
         $result = dfa($result, 'items');
         df_result_array($result);
         $this->{__METHOD__} = $result;
     }
     return $this->{__METHOD__};
 }
Esempio n. 3
0
/**
 * 2016-11-21
 * @param string|object $moduleName
 * @param string $localPath [optional]
 * @return array(string => string|array)
 */
function df_test_file_lj($moduleName, $localPath = '')
{
    return df_json_decode(df_test_file_l($moduleName, "{$localPath}.json"));
}
Esempio n. 4
0
/**
 * @param string|null $v
 * @return mixed|bool
 */
function df_unserialize_simple($v)
{
    return df_json_decode($v);
}
Esempio n. 5
0
/**
 * @used-by Df_InTime_Api::call()
 * http://stackoverflow.com/a/18576902
 * @param mixed $value
 * @return array
 */
function df_stdclass_to_array($value)
{
    return df_json_decode(json_encode($value));
}
Esempio n. 6
0
 /**
  * 2015-12-07
  * @used-by \Df\Framework\Form\Element\ArrayT::onFormInitialized()
  * @param string|null $name [optional]
  * @return string|null
  */
 protected function v($name = null)
 {
     if (!isset($this->{__METHOD__})) {
         $this->{__METHOD__} = dfa($this->_data, 'value', []);
         /**
          * 2016-06-29
          * Что интересно, при смене области действия настроек с глобальной на другую (сайт или магазин)
          * поле «value» может почему-то содержпть не массив,
          * а строку JSON, соответствующую запакованному в JSON массиву:
          * https://code.dmitry-fedyuk.com/m2e/currency-format/issues/1
          * Заметил это только для модуля «Price Format».
          */
         if (is_string($this->{__METHOD__})) {
             $this->{__METHOD__} = df_json_decode($this->{__METHOD__});
         }
     }
     return is_null($name) ? $this->{__METHOD__} : dfa($this->{__METHOD__}, $name);
 }
Esempio n. 7
0
/**
 * 2016-04-13
 * @param string $urlBase
 * @param array(string => string) $params [optional]
 * @param int|null $timeout [optional]
 * @return array(string => mixed)
 */
function df_http_json($urlBase, array $params = [], $timeout = null)
{
    /** @var array|mixed $result */
    $result = [];
    /** @var string|bool $json */
    $json = df_http_get($urlBase, $params, $timeout);
    if (false !== $json) {
        /** @var bool|array|null $decoded */
        $decoded = df_json_decode($json);
        if (is_array($decoded)) {
            $result = $decoded;
        }
    }
    return $result;
}
Esempio n. 8
0
 /**
  * 2015-12-16
  * @param string|null $key [optional]
  * @param null|string|int|S|Store $s [optional]
  * @return mixed[]
  */
 private function json($key = null, $s = null)
 {
     return df_nta(@df_json_decode($this->v($key ?: df_caller_f(), $s)));
 }
Esempio n. 9
0
File: O.php Progetto: mage2pro/core
 /**
  * 2016-07-19
  * @param string $localName
  * @return array(mixed => mixed)
  */
 protected function moduleJson($localName)
 {
     if (!isset($this->{__METHOD__}[$localName])) {
         $this->{__METHOD__}[$localName] = df_json_decode(file_get_contents($this->modulePathEtc($localName . '.json')));
     }
     return $this->{__METHOD__}[$localName];
 }
Esempio n. 10
0
 /**
  * 2015-12-08
  * @return array(string => int[])
  */
 private function datumPoints()
 {
     if (!$this->_datumPoints) {
         if (file_exists($this->pathToDatumPoints())) {
             try {
                 $this->_datumPoints = df_json_decode(df_media_read($this->pathToDatumPoints()));
             } catch (\Exception $e) {
                 df_log($e->getMessage());
             }
         }
         if (!$this->_datumPoints) {
             $this->create();
             df_assert_array($this->_datumPoints);
         }
     }
     return $this->_datumPoints;
 }
Esempio n. 11
0
 /**
  * 2016-07-12
  * @used-by \Df\Payment\R\Response::ic()
  * @param string|null $case [optional]
  * @return array(string => string)
  */
 private function testData($case = null)
 {
     /** @var string $classSuffix */
     $classSuffix = df_class_last($this);
     /**
      * 2016-08-28
      * Если у класса Response нет подклассов,
      * то не используем суффикс Response в именах файлах тестовых данных,
      * а случай confirm делаем случаем по умолчанию.
      * /dfe-allpay/confirm/?class=BankCard => AllPay/BankCard.json
      * /dfe-allpay/confirm/?class=BankCard&case=failure => AllPay/BankCard-failure.json
      * /dfe-securepay/confirm/?dfTest=1 => SecurePay/confirm.json
      */
     if ($classSuffix === df_class_last(__CLASS__)) {
         $classSuffix = null;
         $case = $case ?: 'confirm';
     }
     /** @var string $basename */
     $basename = df_ccc('-', $classSuffix, $case);
     /** @var string $module */
     $module = df_module_name_short($this);
     return df_json_decode(file_get_contents(BP . "/_my/test/{$module}/{$basename}.json"));
 }
Esempio n. 12
0
 /**
 * 2015-12-07
 * Сначала пробовал здесь код:
 		$value = json_decode($this->getValue(), $assoc = true);
 			dfa_deep_set($this->_data, $this->valuePathA(), $value);
 			$this->setValue(null);
 * Однако этот код неверен,
 * потому что нам нужно установить данные именно в поле value:
 * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Block/System/Config/Form.php#L344
 * $data = $backendModel->getValue();
 * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Block/System/Config/Form.php#L362
 * 'value' => $data
 * @used-by \Df\Framework\Form\Element\FieldsetBackend::_afterLoad()
 * @used-by \Df\Framework\Form\Element\FieldsetBackend::dfSaveAfter()
 * @return void
 */
 protected function valueUnserialize()
 {
     /**
      * 2016-07-31
      * Добавил проверку !is_array($this->getValue()),
      * потому что родительский метод @see \Df\Config\Backend::save()
      * будет вызывать нас даже если при сериализации произошёл сбой
      * (и она не была завершена успешно):
      * https://github.com/mage2pro/core/blob/1.5.7/Config/Backend.php?ts=4#L29-L35
      */
     if (!is_array($this->getValue())) {
         $this->setValue($this->processA(df_nta(df_json_decode($this->getValue()))));
     }
 }