facebook twitter hatena line email

「Php/composer」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
行35: 行35:
 
  }
 
  }
  
==phpunitのinstall&実行例==
+
==composer.json記述例==
 
  {
 
  {
 +
    "repositories": [
 +
        {
 +
            "type": "pear",
 +
            "url": "http://pear.php.net/"
 +
        }
 +
    ],
 
     "require": {
 
     "require": {
 +
        "pear-pear.php.net/PEAR": "1.9.*",
 +
        "pear-pear.php.net/Mail": "1.2.*",
 +
        "pear-pear.php.net/Mail_Mime": "1.8.*",
 +
        "pear-pear.php.net/Net_SMTP": "1.6.*",
 +
        "pear-pear.php.net/Net_UserAgent_Mobile": "*"
 +
    }
 +
    "require-dev": {
 +
        "phpunit/PHPUnit": "5.1.*"
 +
    },
 +
}
 +
 +
==phpunitのinstall&実行例==
 +
{
 +
    "require-dev": {
 
         "phpunit/phpunit": "5.1.*"
 
         "phpunit/phpunit": "5.1.*"
 
     }
 
     }

2016年2月5日 (金) 05:25時点における版

パッケージ管理ツール node.jsのnpmみたいなもの。

ローカルプロジェクトにcomposerインストール

$ curl -s http://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer.phar
$ composer -V
Composer version e77435cd0c984e2031d915a6b42648e7b284dd5c 2014-07-02 15:44:54

使い方(例:monolog/monolog)

composer.json

{
    "require": {
        "monolog/monolog": ">=1.0.0"
    }
}
$ php composer.phar install

autoload

vender/autoload.phpでパッケージを読み込んでくれる。

composer.json編集した後の更新

composer update

vendorのdirの名前を変更

composer.json

{
    "require": {
        "monolog/monolog": ">=1.0.0"
    },
    "config": {
        "vendor-dir": "lib/"
    }
}

composer.json記述例

{
   "repositories": [
       {
           "type": "pear",
           "url": "http://pear.php.net/"
       }
   ],
   "require": {
       "pear-pear.php.net/PEAR": "1.9.*",
       "pear-pear.php.net/Mail": "1.2.*",
       "pear-pear.php.net/Mail_Mime": "1.8.*",
       "pear-pear.php.net/Net_SMTP": "1.6.*",
       "pear-pear.php.net/Net_UserAgent_Mobile": "*"
   }
   "require-dev": {
       "phpunit/PHPUnit": "5.1.*"
   },
}

phpunitのinstall&実行例

{
   "require-dev": {
       "phpunit/phpunit": "5.1.*"
   }
}
$ vendor/bin/phpunit --bootstrap vendor/autoload.php tests/hoge.php

参考

http://www.ryuzee.com/contents/blog/5681