From 19862493cca42f532c1e437cfc140c17f6ec76cf Mon Sep 17 00:00:00 2001 From: mdmunir Date: Fri, 11 Mar 2016 12:09:46 +0700 Subject: [PATCH] prepare for new release --- Classes/Import.php | 54 +++++++++++++++++++++++++++++++--------------- README.md | 7 ++++++ composer.json | 2 +- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Classes/Import.php b/Classes/Import.php index d88e307..d7fc4d3 100644 --- a/Classes/Import.php +++ b/Classes/Import.php @@ -17,28 +17,45 @@ class Import * ``` * Import::using('yii\bootstrap\*'); * Import::using('yii\widgets\ActiveForm'); + * + * Import::using([ + * 'yii\helpers\Html', + * 'yii\bootstrap\Html' => 'BHtml' + * ]); * ``` * @param string $namespace * @throws BadMethodCallException */ - public static function using($namespace) + public static function using($namespace, $as = null) { if (!static::$_registered) { spl_autoload_register(['Import', 'load']); static::$_registered = true; } + if (is_array($namespace)) { + foreach ($namespace as $class => $alias) { + if (is_int($class)) { + static::using($alias); + } else { + static::using($class, $alias); + } + } + return; + } + $namespace = trim($namespace, '\\'); if (($pos = strrpos($namespace, '\\')) !== false) { $ns = trim(substr($namespace, 0, $pos), '\\'); $alias = substr($namespace, $pos + 1); - if ($alias === '*') { - static::$_paths[] = $ns; - static::$_paths = array_unique(static::$_paths); - } else { - static::$_classMap[$alias] = $namespace; - } } else { - throw new BadMethodCallException("Invalid import alias: $namespace"); + $ns = ''; + $alias = $namespace; + } + + if ($alias === '*') { + static::$_paths[$ns] = true; + } else { + static::$_classMap[$as ? : $alias] = $namespace; } } @@ -52,16 +69,19 @@ public static function load($class) if (empty(static::$_paths) && empty(static::$_classMap)) { return; } - if (strpos($class, '\\') === false) { - if (isset(static::$_classMap[$class])) { - return class_alias(static::$_classMap[$class], $class); - } else { - foreach (static::$_paths as $path) { - if (class_exists($path . '\\' . $class)) { - return class_alias($path . '\\' . $class, $class); - } + if (($pos = strrpos($class, '\\')) !== false) { + $alias = substr($class, $pos + 1); + } else { + $alias = $class; + } + if (isset(static::$_classMap[$alias])) { + return class_alias(static::$_classMap[$alias], $class); + } else { + foreach (array_keys(static::$_paths) as $path) { + if (class_exists(rtrim($path . '\\' . $alias, '\\'))) { + return class_alias(rtrim($path . '\\' . $alias, '\\'), $class); } } } } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 85ca3dc..7f90e4e 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,19 @@ Once the extension is installed, use in your code: 'Html', + 'yii\helpers\ArrayHelper', +]); ?> 'Action Test', 'options' => ['class' => 'btn-lg'], ]); + +echo BootstrapHtml::icon('star'); ?> diff --git a/composer.json b/composer.json index 76cc333..cacef3a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } } }