Permalink
Browse files

Initial release

  • Loading branch information...
shama committed Jun 18, 2012
0 parents commit 6dac4765dab9786d4ee04fb452ca250e1f891829
@@ -0,0 +1,12 @@
+language: php
+
+php:
+ - 5.3.3
+ - 5.3
+ - 5.4
+
+before_script:
+ - curl -s http://getcomposer.org/installer | php
+ - php composer.phar install
+
+script: phpunit -c tests/
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Kyle Robinson Young
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,81 @@
+# Baton: A Multi-Framework [Composer](http://getcomposer.org) Library Installer
+
+This is for PHP package authors to require in their `composer.json`. It will
+magically install their package to the correct location based on the specified
+package type.
+
+**Current Supported Package Types**:
+
+* CakePHP 2+ `cakephp-`
+* CodeIgniter `codeigniter-`
+* FuelPHP `fuelphp-`
+* Laravel `laravel-`
+* Lithium `lithium-`
+
+Symfony and ZendFramework don't need this as they already work naturally with
+Composer.
+
+## Example `composer.json` File
+
+This is an example for a CakePHP plugin. The only important parts are
+`"type": "cakephp-plugin"` which tells Baton what your package is and
+`"require": { "shama/baton": "*" }` which tells composer to use the Baton
+installer.
+
+``` json
+{
+ "name": "shama/ftp",
+ "type": "cakephp-plugin",
+ "description": "Just an example",
+ "keywords": ["cakephp", "ftp"],
+ "homepage": "https://github.com/shama/cakeftp",
+ "license": "MIT",
+
+ "require": {
+ "php": ">=5.3",
+ "shama/baton": "*"
+ }
+}
+```
+
+This would install your package to the `app/Plugin/Ftp/` folder of a CakePHP app
+when a user runs `php composer.phar install`.
+
+So submit your packages to [packagist.org](http://packagist.org)!
+
+## Current Supported Types (Default Types in Bold)
+
+* CakePHP
+ * cakephp-app
+ * cakephp-plugin
+ * cakephp-lib
+ * **cakephp-vendor**
+ * cakephp-model
+ * cakephp-behavior
+ * cakephp-controller
+ * cakephp-component
+ * cakephp-helper
+ * cakephp-theme
+* CodeIgniter
+ * codeigniter-app
+ * **codeigniter-library**
+ * codeigniter-controller
+ * codeigniter-third-party
+ * codeigniter-model
+ * codeigniter-helper
+* FuelPHP
+ * fuelphp-app
+ * **fuelphp-module**
+* Laravel
+ * laravel-app
+ * **laravel-library**
+* Lithium
+ * lithium-app
+ * **lithium-library**
+ * lithium-controller
+ * lithium-extension
+ * lithium-model
+
+## Contribute!
+
+Please fork and send a pull request against the `master` branch. Thanks!
@@ -0,0 +1,24 @@
+{
+ "name": "shama/baton",
+ "type": "composer-installer",
+ "license": "MIT",
+ "description": "A multi-framework composer library installer",
+ "keywords": ["installer", "cakephp", "laravel", "li3", "lithium", "fuelphp", "codeigniter"],
+ "authors": [
+ {
+ "name": "Kyle Robinson Young",
+ "email": "kyle@dontkry.com",
+ "homepage": "https://github.com/shama"
+ }
+ ],
+ "autoload": {
+ "psr-0": { "Baton": "src/" }
+ },
+ "extra": {
+ "class": "src\\Baton\\Installer"
+ },
+ "require": {
+ "php": ">=5.3",
+ "composer/composer": ">=1.0.0"
+ }
+}
@@ -0,0 +1,77 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;

This comment has been minimized.

Show comment Hide comment
@GromNaN

GromNaN Jun 18, 2012

Contributor

This is not used.

@GromNaN

GromNaN Jun 18, 2012

Contributor

This is not used.

This comment has been minimized.

Show comment Hide comment
@shama

shama Jun 18, 2012

Contributor

It's used for the type hint on getInstallPath(). Or are you saying it's a deprecated class on Composer and we should use another for $package?

@shama

shama Jun 18, 2012

Contributor

It's used for the type hint on getInstallPath(). Or are you saying it's a deprecated class on Composer and we should use another for $package?

This comment has been minimized.

Show comment Hide comment
@GromNaN

GromNaN Jun 18, 2012

Contributor

Oups, you're right.

@GromNaN

GromNaN Jun 18, 2012

Contributor

Oups, you're right.

+
+abstract class BaseInstaller
+{
+
+ /**
+ * Package locations
+ *
+ * @var array
+ */
+ protected $locations = array(
+ 'app' => '/',
+ );
+
+ /**
+ * Default key if none found
+ *
+ * @var string
+ */
+ protected $default = null;
+
+ /**
+ * Return the install path based on package type.
+ *
+ * @return string
+ */
+ public function getInstallPath(BasePackage $package)
+ {
+ $type = $package->getType();
+ $packageLocation = strtolower(substr($type, strpos($type, '-') + 1));
+
+ $name = $package->getPrettyName();
+ list($packageVendor, $name) = explode('/', $name);
+ $name = $this->inflectPackageName($name);
+
+ $base = false;
+ if (isset($this->locations[$packageLocation])) {
+ $base = $this->locations[$packageLocation];
+ } else if (isset($this->locations[$this->default])) {
+ $base = $this->locations[$this->default];
+ } else if (!empty($this->locations)) {
+ $base = current($this->locations);
+ }
+
+ if ($base === false) {
+ throw new \InvalidArgumentException(
+ 'Package install location could not be found.'
+ );
+ }
+
+ if (strpos($base, '{') !== false) {
+ preg_match_all('@\{([A-Za-z0-9_]*)\}@i', $base, $matches);
+ if (!empty($matches[1])) {
+ foreach ($matches[1] as $var) {
+ $base = str_replace('{' . $var . '}', $$var, $base);
+ }
+ }
+ }
+
+ return $base;
+ }
+
+ /**
+ * Modify how the package name is translated.
+ *
+ * @param string $name
+ * @return string
+ */
+ public function inflectPackageName($name)
+ {
+ return $name;
+ }
+
+}
@@ -0,0 +1,32 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;
+
+class CakePHPInstaller extends BaseInstaller
+{
+
+ protected $locations = array(
+ 'app' => '/',
+ 'plugin' => '/Plugin/{name}/',
+ 'lib' => '/Lib/',
+ 'vendor' => '/Vendor/{name}/',
+ 'model' => '/Model/',
+ 'behavior' => '/Model/Behavior/',
+ 'controller' => '/Controller/',
+ 'component' => '/Controller/Component/',
+ 'helper' => '/View/Helper/',
+ 'theme' => '/View/Themed/{name}/',
+ );
+ protected $default = 'vendor';
+
+ /**
+ * Format package name to CamelCase
+ */
+ public function inflectPackageName($name)
+ {
+ $name = strtolower(str_replace(array('-', '_'), ' ', $name));
+ return str_replace(' ', '', ucwords($name));
+ }
+
+}
@@ -0,0 +1,19 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;
+
+class CodeIgniterInstaller extends BaseInstaller
+{
+
+ protected $locations = array(
+ 'app' => '/',
+ 'library' => '/libraries/',
+ 'controller' => '/controllers/',
+ 'third-party' => '/third-party/',
+ 'model' => '/models/',
+ 'helper' => '/helpers/',
+ );
+ protected $default = 'library';
+
+}
@@ -0,0 +1,15 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;
+
+class FuelPHPInstaller extends BaseInstaller
+{
+
+ protected $locations = array(
+ 'app' => '/',
+ 'module' => '/modules/',
+ );
+ protected $default = 'module';
+
+}
@@ -0,0 +1,55 @@
+<?php
+namespace Baton;
+
+use Composer\Package\PackageInterface;
+use Composer\Installer\LibraryInstaller;
+
+class Installer extends LibraryInstaller
+{
+
+ /**
+ * Package types to installer class map
+ *
+ * @var array
+ */
+ private $supportedTypes = array(
+ 'cakephp' => 'CakePHPInstaller',
+ 'codeigniter' => 'CodeIgniterInstaller',
+ 'fuelphp' => 'FuelPHPInstaller',
+ 'laravel' => 'LaravelInstaller',
+ 'lithium' => 'LithiumInstaller',
+ );
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getInstallPath(PackageInterface $package)
+ {
+ $type = $package->getType();
+ $packageType = substr($type, 0, strpos($type, '-'));
+
+ if (!isset($this->supportedTypes[$packageType])) {
+ throw new \InvalidArgumentException(
+ 'Sorry the package type of this package is not yet supported.'
+ );
+ } else {
+ $class = "\\Baton\\" . $this->supportedTypes[$packageType];
+ $Installer = new $class;
+ return $Installer->getInstallPath($package);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function supports($packageType)
+ {
+ foreach ($this->supportedTypes as $type => $sub) {
+ if (substr($packageType, 0, strlen($type)) === $type) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
@@ -0,0 +1,15 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;
+
+class LaravelInstaller extends BaseInstaller
+{
+
+ protected $locations = array(
+ 'app' => '/',
+ 'library' => '/libraries/{name}/',
+ );
+ protected $default = 'library';
+
+}
@@ -0,0 +1,26 @@
+<?php
+namespace Baton;
+
+use Composer\Package\BasePackage;
+
+class LithiumInstaller extends BaseInstaller
+{
+
+ protected $locations = array(
+ 'app' => '/',
+ 'library' => '/libraries/{name}/',
+ 'controller' => '/controllers/',
+ 'extension' => '/extensions/{name}/',
+ 'model' => '/models/',
+ );
+ protected $default = 'library';
+
+ /**
+ * Format package name to lowercase
+ */
+ public function inflectPackageName($name)
+ {
+ return strtolower(str_replace(array('-', '_'), '', $name));
+ }
+
+}
Oops, something went wrong.

0 comments on commit 6dac476

Please sign in to comment.