FuelPHPともっと仲良くする(Git&Composer)


# Gitと仲良くする

FuelPHP 1.7.2以前はすこしばかりGitと仲良くするのに手間が掛かった。

これからは違うようだ。

composerのcreate-projectで一発導入。<a href="https://packagist.org/">Packagist</a>からfuel/fuelを見ると

|バージョン指定子|
|---|
|dev-1.8/develop|
|dev-1.7/master|
|dev-1.6/master|

上記が利用可能な模様

```これから
$ curl -sS https://getcomposer.org/installer | php

$ php composer.phar create-project fuel/fuel:dev-1.7/master fuel-composer-base
Installing fuel/fuel (dev-1.7/master 51ae000a6eb4967a6531dea72c320d5ec287d78d)
  - Installing fuel/fuel (dev-1.7/master 1.7/master)
    Cloning 1.7/master

Created project in fuel-composer-base
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing composer/installers (dev-master d64e23f)
    Cloning d64e23fce42a4063d63262b19b8e7c0f3b5e4c45

  - Installing fuel/docs (1.7.2)
    Loading from cache

  - Installing fuel/core (1.7.2)
    Loading from cache
...
...
...
...
Writing lock file
Generating autoload files
	Made writable: /Users/hac/fuel-project/fuel-composer-base/fuel/app/cache
	Made writable: /Users/hac/fuel-project/fuel-composer-base/fuel/app/logs
	Made writable: /Users/hac/fuel-project/fuel-composer-base/fuel/app/tmp
	Made writable: /Users/hac/fuel-project/fuel-composer-base/fuel/app/config
Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]? y

```

Coreなんかも全部Composerで管理されていて、最後には「.git消すかい？」と親切な言葉まで投げかけてくるようになったらしい。

git init&addでは以下のようになる。

```
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   .gitignore
	new file:   .travis.yml
	new file:   CHANGELOG.md
	new file:   CONTRIBUTING.md
	new file:   LICENSE.md
	new file:   README.md
	new file:   TESTING.md
	new file:   composer.json
	new file:   composer.phar
	new file:   fuel/.htaccess
	new file:   fuel/app/bootstrap.php
	new file:   fuel/app/cache/.gitkeep
	new file:   fuel/app/classes/controller/.gitkeep
	new file:   fuel/app/classes/controller/welcome.php
	new file:   fuel/app/classes/model/.gitkeep
	new file:   fuel/app/classes/presenter/welcome/404.php
	new file:   fuel/app/classes/presenter/welcome/hello.php
	new file:   fuel/app/config/config.php
	new file:   fuel/app/config/db.php
	new file:   fuel/app/config/development/db.php
	new file:   fuel/app/config/production/db.php
	new file:   fuel/app/config/routes.php
	new file:   fuel/app/config/staging/db.php
	new file:   fuel/app/config/test/db.php
	new file:   fuel/app/lang/en/.gitkeep
	new file:   fuel/app/logs/.gitkeep
	new file:   fuel/app/migrations/.gitkeep
	new file:   fuel/app/modules/.gitkeep
	new file:   fuel/app/tasks/robots.php
	new file:   fuel/app/tests/controller/.gitkeep
	new file:   fuel/app/tests/model/.gitkeep
	new file:   fuel/app/tests/view/.gitkeep
	new file:   fuel/app/themes/.gitkeep
	new file:   fuel/app/tmp/.gitkeep
	new file:   fuel/app/vendor/.gitkeep
	new file:   fuel/app/views/.gitkeep
	new file:   fuel/app/views/welcome/404.php
	new file:   fuel/app/views/welcome/hello.php
	new file:   fuel/app/views/welcome/index.php
	new file:   fuel/packages/.gitkeep
	new file:   oil
	new file:   public/.htaccess
	new file:   public/assets/css/bootstrap-LICENSE
	new file:   public/assets/css/bootstrap-theme.css
	new file:   public/assets/css/bootstrap-theme.min.css
	new file:   public/assets/css/bootstrap.css
	new file:   public/assets/css/bootstrap.min.css
	new file:   public/assets/css/index.html
	new file:   public/assets/fonts/glyphicons-halflings-regular.eot
	new file:   public/assets/fonts/glyphicons-halflings-regular.svg
	new file:   public/assets/fonts/glyphicons-halflings-regular.ttf
	new file:   public/assets/fonts/glyphicons-halflings-regular.woff
	new file:   public/assets/fonts/index.html
	new file:   public/assets/img/index.html
	new file:   public/assets/js/bootstrap.js
	new file:   public/assets/js/bootstrap.min.js
	new file:   public/assets/js/index.html
	new file:   public/favicon.ico
	new file:   public/index.php
	new file:   public/web.config
```

自分はappとpackageは別リポジトリにしているほうなので、.gitignoreにpackageディレクトリごと除外指定、そのままgit initして利用開始できる状態になった。
見ての通りスッキリである。

# Composerをもう少し知る

```
$ php composer.phar help create-project
Usage:
 create-project [-s|--stability="..."] [--prefer-source] [--prefer-dist] [--repository-url="..."] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [package] [directory] [version]

Arguments:
 package                 Package name to be installed
 directory               Directory where the files should be created
 version                 Version, will default to latest

Options:
 --stability (-s)        Minimum-stability allowed (unless a version is specified).
 --prefer-source         Forces installation from package sources when possible, including VCS information.
 --prefer-dist           Forces installation from package dist even for dev versions.
 --repository-url        Pick a different repository url to look for the package.
 --dev                   Enables installation of require-dev packages (enabled by default, only present for BC).
 --no-dev                Disables installation of require-dev packages.
 --no-plugins            Whether to disable plugins.
 --no-custom-installers  DEPRECATED: Use no-plugins instead.
 --no-scripts            Whether to prevent execution of all defined scripts in the root package.
 --no-progress           Do not output download progress.
 --keep-vcs              Whether to prevent deletion vcs folder.
 --no-install            Whether to skip installation of the package dependencies.
 --ignore-platform-reqs  Ignore platform requirements (php & ext- packages).
 --help (-h)             Display this help message.
 --quiet (-q)            Do not output any message.
 --verbose (-v|vv|vvv)   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
 --version (-V)          Display this application version.
 --ansi                  Force ANSI output.
 --no-ansi               Disable ANSI output.
 --no-interaction (-n)   Do not ask any interactive question.
 --profile               Display timing and memory usage information
 --working-dir (-d)      If specified, use the given directory as working directory.

Help:
 The create-project command creates a new project from a given
 package into a new directory. If executed without params and in a directory
 with a composer.json file it installs the packages for the current project.

 You can use this command to bootstrap new projects or setup a clean
 version-controlled installation for developers of your project.

 php composer.phar create-project vendor/project target-directory [version]

 You can also specify the version with the package name using = or : as separator.

 To install unstable packages, either specify the version you want, or use the
 --stability=dev (where dev can be one of RC, beta, alpha or dev).

 To setup a developer workable version you should create the project using the source
 controlled code by appending the '--prefer-source' flag.

 To install a package from another repository than the default one you
 can pass the '--repository-url=http://myrepository.org' flag.

```
今回初めて create-projectコマンドを使ったわけだけど、よくわからないオプションが一つ.

```
--stability (-s)        Minimum-stability allowed (unless a version is specified).
```

安定度を指定出来るのか・・・な？バージョンを指定しない限りとなっているところを見るとFuel本体には影響しないようだがcomposer.jsonには確かに

```
"minimum-stability": "dev"
```

こんな一行がある。
パッケージによるのだろうけど、安定版などの供給があればそちらを利用するってことなんだろうね。

この辺りをググっているうちに

```
"prefer-stable": true
```

こんなのも見つける。
Composerが安定してるんじゃないかなーってのを割り当ててくれるってことか。
なかなか興味深いねぇ