You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.6KB

  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Fxp\Composer\AssetPlugin;
  11. use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
  12. /**
  13. * Assets definition.
  14. *
  15. * @author François Pluchino <francois.pluchino@gmail.com>
  16. */
  17. class Assets
  18. {
  19. /**
  20. * @var array
  21. */
  22. protected static $typeClasses = array(
  23. 'npm' => 'Fxp\Composer\AssetPlugin\Type\NpmAssetType',
  24. 'bower' => 'Fxp\Composer\AssetPlugin\Type\BowerAssetType',
  25. );
  26. /**
  27. * @var array
  28. */
  29. protected static $registryClasses = array(
  30. 'npm' => 'Fxp\Composer\AssetPlugin\Repository\NpmRepository',
  31. 'bower' => 'Fxp\Composer\AssetPlugin\Repository\BowerRepository',
  32. );
  33. /**
  34. * @var array
  35. */
  36. protected static $vcsRepositoryDrivers = array(
  37. 'vcs' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  38. 'github' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  39. 'git-bitbucket' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  40. 'git' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  41. 'hg-bitbucket' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  42. 'hg' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  43. 'perforce' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  44. 'svn' => 'Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository',
  45. );
  46. /**
  47. * @var array
  48. */
  49. protected static $vcsDrivers = array(
  50. 'github' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\GitHubDriver',
  51. 'git-bitbucket' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\GitBitbucketDriver',
  52. 'git' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\GitDriver',
  53. 'hg-bitbucket' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\HgBitbucketDriver',
  54. 'hg' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\HgDriver',
  55. 'perforce' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\PerforceDriver',
  56. // svn must be last because identifying a subversion server for sure is practically impossible
  57. 'svn' => 'Fxp\Composer\AssetPlugin\Repository\Vcs\SvnDriver',
  58. );
  59. /**
  60. * Creates asset type.
  61. *
  62. * @param string $type
  63. *
  64. * @return AssetTypeInterface
  65. *
  66. * @throws \InvalidArgumentException When the asset type does not exist
  67. */
  68. public static function createType($type)
  69. {
  70. if (!isset(static::$typeClasses[$type])) {
  71. throw new \InvalidArgumentException('The asset type "'.$type.'" does not exist, only "'.implode('", "', static::getTypes()).'" are accepted');
  72. }
  73. $class = static::$typeClasses[$type];
  74. return new $class();
  75. }
  76. /**
  77. * Gets the asset types.
  78. *
  79. * @return array
  80. */
  81. public static function getTypes()
  82. {
  83. return array_keys(static::$typeClasses);
  84. }
  85. /**
  86. * Gets the asset registry repositories.
  87. *
  88. * @return array
  89. */
  90. public static function getRegistries()
  91. {
  92. return static::$registryClasses;
  93. }
  94. /**
  95. * Gets the asset vcs repository drivers.
  96. *
  97. * @return array
  98. */
  99. public static function getVcsRepositoryDrivers()
  100. {
  101. return static::$vcsRepositoryDrivers;
  102. }
  103. /**
  104. * Gets the asset vcs drivers.
  105. *
  106. * @return array
  107. */
  108. public static function getVcsDrivers()
  109. {
  110. return static::$vcsDrivers;
  111. }
  112. }