Skip to content

Commit

Permalink
Add get array value with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Jun 13, 2016
1 parent 9a72f9c commit de3fc28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Repository/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ public static function convertAliasName($name)
return $name;
}

/**
* Get the array value.
*
* @param array $array The array
* @param string $name The key name
* @param mixed $default The default value
*
* @return mixed
*/
public static function getArrayValue(array $array, $name, $default = null)
{
return array_key_exists($name, $array)
? $array[$name]
: $default;
}

/**
* Write the vcs repository name in output console.
*
Expand Down
5 changes: 2 additions & 3 deletions Util/AssetPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Fxp\Composer\AssetPlugin\Assets;
use Fxp\Composer\AssetPlugin\Installer\AssetInstaller;
use Fxp\Composer\AssetPlugin\Installer\BowerInstaller;
use Fxp\Composer\AssetPlugin\Repository\Util;
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;

/**
Expand Down Expand Up @@ -76,9 +77,7 @@ public static function createAssetOptions(array $extra, $assetType)
*/
public static function createRepositoryConfig(RepositoryManager $rm, VcsPackageFilter $filter, array $extra, $assetType)
{
$opts = array_key_exists('asset-registry-options', $extra)
? $extra['asset-registry-options']
: array();
$opts = Util::getArrayValue($extra, 'asset-registry-options', array());

return array(
'repository-manager' => $rm,
Expand Down

0 comments on commit de3fc28

Please sign in to comment.