예제 #1
0
/**
 * 2016-08-03
 * @param string $name
 * @param string|\Exception $message [optional]
 * @return void
 * @throws DFE
 */
function df_assert_class_exists($name, $message = null)
{
    df_param_string_not_empty($name, 0);
    if (df_enable_assertions()) {
        if (!df_class_exists($name)) {
            df_error($message ?: "The required class «{$name}» does not exist.");
        }
    }
}
예제 #2
0
파일: Validator.php 프로젝트: mage2pro/core
 /**
  * 2015-04-05
  * @used-by resolve()
  * @param string $name
  * @param bool $skipOnNull [optional]
  * @return \Zend_Validate_Interface|\Zend_Filter_Interface
  */
 private static function byName($name, $skipOnNull = false)
 {
     /** @var array(bool => array(string => \Zend_Validate_Interface)) */
     static $cache;
     if (!isset($cache[$skipOnNull][$name])) {
         /** @var array(string => string) $map */
         static $map;
         if (!$map) {
             /** @var string[] $entries */
             $entries = [DF_F_TRIM, DF_V_ARRAY, DF_V_BOOL, DF_V_FLOAT, DF_V_INT, DF_V_ISO2, DF_V_NAT, DF_V_NAT0, DF_V_STRING, DF_V_STRING_NE];
             $map = array_combine($entries, $entries);
         }
         /** @var \Zend_Validate_Interface|\Zend_Filter_Interface $result */
         if (isset($map[$name])) {
             $result = new $map[$name]();
         } else {
             if (df_class_exists($name) || @interface_exists($name)) {
                 $result = \Df\Zf\Validate\ClassT::i($name);
             } else {
                 df_error("Система не смогла распознать валидатор «{$name}».");
             }
         }
         $result->{self::$SKIP_ON_NULL} = $skipOnNull;
         $cache[$skipOnNull][$name] = $result;
     }
     return $cache[$skipOnNull][$name];
 }
예제 #3
0
/**
 * Инструмент парадигмы «convention over configuration».
 * 2016-10-26
 * @param \Closure $f
 * @param object|string $c
 * @param string|string[] $suffix
 * @param string|null $def [optional]
 * @param bool $throw [optional]
 * @return string|null
 */
function df_con_generic(\Closure $f, $c, $suffix, $def = null, $throw = true)
{
    return dfcf(function ($f, $c, $suffix, $def = null, $throw = true) {
        /** @var string $result */
        $result = $f($c, $suffix);
        return df_class_exists($result) ? $result : ($def ?: (!$throw ? null : df_error("The «{$result}» class is required.")));
    }, [$f, df_cts($c), $suffix, $def, $throw]);
}