Beispiel #1
0
/**
 * 2016-08-02
 * *) По аналогии с @see \Magento\Config\Block\System\Config\Form::initForm()
 * *) Мы не можем кэшировать результат, потому что возвращаемые объекты - это приспособленцы (fleweights).
 * *) Метод не может вернуть обект класса @see \Magento\Config\Model\Config\Structure\Element\Tab
 * потому что идентификатор вкладки не входит в $path.
 * Для получения данных вкладки используйте метод @see \Df\Config\Model\Config\Structure::tab()
 * Для получения названия вкладки используйте функцию @see df_config_tab_label()
 *
 * @param string $path
 * @param bool $throw [optional]
 * @param string|null $expectedClass [optional]
 * @return IElement|Field|Group|Section|null
 */
function df_config_e($path, $throw = true, $expectedClass = null)
{
    /** @var IElement|Field|Group|Section|null $result */
    $result = df_config_structure()->getElement($path);
    if (!$result && $throw) {
        df_error_html(__("Unable to read the configuration node «<b>%1</b>»", $path));
    }
    return !$result || !$expectedClass || $result instanceof $expectedClass ? $result : df_error_html(__("The configuation node «<b>%1</b>» should be an instance of the <b>%2</b> class, " . "but actually it is an instance of the <b>%3</b> class.", $path, $expectedClass, df_cts($result)));
}
Beispiel #2
0
/**
 * 2016-11-10
 * @param string|object $v
 * @param string|object|null $class
 * @param string|\Exception|null  $message [optional]
 * @return string|object
 * @throws DFE
 */
function df_ar($v, $class, $message = null)
{
    if ($class && df_enable_assertions()) {
        $class = df_cts($class);
        !is_null($v) ?: df_error($message ?: "Expected class: «{$class}», given NULL.");
        is_object($v) || is_string($v) ?: df_error($message ?: "Expected class: «{$class}», given: a value «%s» of type «%s».", df_dump($v), gettype($v));
        /** @var string $cv */
        $cv = df_cts($v);
        df_assert_class_exists($cv);
        if (!is_a($cv, $class, true)) {
            df_error($message ?: "Expected class: «{$class}», given class: «{$cv}».");
        }
    }
    return $v;
}
Beispiel #3
0
 /**
  * 2016-08-04
  * 2016-11-25
  * Отныне метод возвращает класс не обязательно из базовой папки (например, \Df\Sso\Settings),
  * а из папки с тем же окончанием, что и у вызываемого класса.
  * Например, \Df\Sso\Settings\Button::convention() будет искать класс в папке Settings\Button
  * модуля, к которому относится класс $c.
  * @param object|string $c
  * @param string $key [optional]
  * @param null|string|int|S $scope [optional]
  * @param mixed|callable $d [optional]
  * @return self
  */
 public static function convention($c, $key = '', $scope = null, $d = null)
 {
     /** @var self $result */
     /**
      * 2016-11-25
      * Используем 2 уровня кэширования, и оба они важны:
      * 1) Кэширование self::s() приводит к тому, что вызов s() непосредственно для класса
      * возвращает тот же объект, что и вызов convention(). Это очень важно.
      * 2) Кэширование dfcf() позволяет нам не рассчитывать df_con_heir()
      * при каждом вызове convention().
      */
     $result = dfcf(function ($c, $def) {
         return self::s(df_con_heir($c, $def));
     }, [df_cts($c), static::class]);
     return df_null_or_empty_string($key) ? $result : $result->v($key, $scope, $d);
 }
Beispiel #4
0
 /**
  * 2016-07-12
  * http://php.net/manual/function.get-called-class.php#115790
  * @param string $c [optional]
  * @param array(string => mixed) $params [optional]
  * @return self
  */
 public static function s($c = null, array $params = [])
 {
     return df_sc($c ? df_cts($c) : static::class, static::class, $params);
 }
Beispiel #5
0
/**
 * 2016-08-25
 * @uses \Df\Payment\Method::codeS()
 * @param string|object $caller
 * @return string
 */
function dfp_method_code($caller)
{
    return dfcf(function ($class) {
        return dfp_method_call_s($class, 'codeS');
    }, [df_cts($caller)]);
}
Beispiel #6
0
/**
 * 2016-08-28
 * «Dfe\AllPay\Response» => «AllPay»
 * 2016-10-20
 * Нельзя делать параметр $c опциональным, потому что иначе получим сбой:
 * «get_class() called without object from outside a class»
 * https://3v4l.org/k6Hd5
 * @param string|object $c
 * @return string
 */
function df_module_name_short($c)
{
    return dfcf(function ($c) {
        return df_explode_class($c)[1];
    }, [df_cts($c)]);
}