m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

cakephp3でalpha1を超簡単に入れて動作確認

まあ、ほとんど何もしていない
vagrantの環境で前の環境を壊したくないから新しく別のディレクトリに配置

まずは実行ログ

ログ
[vagrant@localhost ~]$ mkdir sample1
[vagrant@localhost ~]$ cd sample1/
[vagrant@localhost sample1]$ curl -s https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /home/vagrant/sample1/composer.phar
Use it: php composer.phar
[vagrant@localhost sample1]$ php composer.phar create-project -s dev cakephp/app
Installing cakephp/app (dev-master 3a74fb5363be64d238a25696b79bd3a748cfe605)
  - Installing cakephp/app (dev-master master)
    Cloning master

Created project in /home/vagrant/sample1/app
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing ircmaxell/password-compat (1.0.3)
    Loading from cache

  - Installing nesbot/carbon (1.8.0)
    Loading from cache

  - Installing cakephp/cakephp (3.0.x-dev 3fd98f4)
    Cloning 3fd98f4e88cad4f00a1bf91550e4d6aee04d0fcc
Failed to download cakephp/cakephp from source: The process "git clone --no-checkout 'git://github.com/cakephp/cakephp.git' '/home/vagrant/sample1/app/vendor/cakephp/cakephp' && cd '/home/vagrant/sample1/app/vendor/cakephp/cakephp' && git remote add composer 'git://github.com/cakephp/cakephp.git' && git fetch composer" exceeded the timeout of 300 seconds.
Now trying to download from dist
  - Installing cakephp/cakephp (3.0.x-dev 3fd98f4)
    Downloading: 100%

  - Installing mobiledetect/mobiledetectlib (2.8.2)
    Downloading: 100%

  - Installing d11wtq/boris (v1.0.8)
    Loading from cache

Writing lock file
Generating autoload files
Created `Config/app.php` file
Permissions set on /home/vagrant/sample1/app/tmp/cache
Permissions set on /home/vagrant/sample1/app/tmp/cache/models
Permissions set on /home/vagrant/sample1/app/tmp/cache/persistent
Permissions set on /home/vagrant/sample1/app/tmp/cache/views
Permissions set on /home/vagrant/sample1/app/tmp/logs
Permissions set on /home/vagrant/sample1/app/tmp/sessions
Permissions set on /home/vagrant/sample1/app/tmp/tests
Permissions set on /home/vagrant/sample1/app/tmp
Updated Security.salt value in src/Config/app.php
Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]?
[vagrant@localhost sample1]$

なんか変なメッセージ出ている

Failed to download cakephp/cakephp from source: The process "git clone --no-checkout 'git://github.com/cakephp/cakephp.git' '/home/vagrant/sample1/app/vendor/cakephp/cakephp' && cd '/home/vagrant/sample1/app/vendor/cakephp/cakephp' && git remote add composer 'git://github.com/cakephp/cakephp.git' && git fetch composer" exceeded the timeout of 300 seconds.
Now trying to download from dist

うーん

composer.jsonを確認
{
        "name": "cakephp/app",
        "description": "CakePHP skeleton app",
        "homepage": "http://cakephp.org",
        "type": "project",
        "license": "MIT",
        "require": {
                "php": ">=5.4.19",
                "cakephp/cakephp": "3.0.*-dev",
                "mobiledetect/mobiledetectlib": "2.*"
        },
        "require-dev": {
                "d11wtq/boris": "1.0.*"
        },
        "suggest": {
                "phpunit/phpunit": "Allows automated tests to be run without system-wide install."
        },
        "autoload": {
                "psr-4": {
                        "App\\": "src",
                        "App\\Test\\": "tests",
                        "": "./plugins"
                }
        },
        "scripts": {
                "post-install-cmd": "App\\Console\\Installer::postInstall"
        }
}

cakephp/cakephpをalpha1へ変更
        "require": {
                "php": ">=5.4.19",
                "cakephp/cakephp": "3.0.0-alpha1",
                "mobiledetect/mobiledetectlib": "2.*"
        },
再度、update
[vagrant@localhost sample1]$ cd app
[vagrant@localhost app]$ php ../composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing cakephp/cakephp (3.0.0-alpha1)
    Downloading: 100%

Writing lock file
Generating autoload files
[vagrant@localhost app]$

なんかうまくいったっぽい

cake serverで稼働確認
[vagrant@localhost sample1]$ sh app/src/Console/cake server -H 192.168.33.10 -p 1234

Welcome to CakePHP v3.0.0-alpha1 Console
---------------------------------------------------------------
App : src
Path: /home/vagrant/sample1/app/src/
DocumentRoot: /home/vagrant/sample1/app/webroot
---------------------------------------------------------------
built-in server is running in http://192.168.33.10:1234/
You can exit with CTRL-C
[Thu Jun 26 13:14:10 2014] 192.168.33.1:63351 [200]: /css/cake.generic.css
[Thu Jun 26 13:14:10 2014] 192.168.33.1:63350 [200]: /img/cake.power.gif
[Thu Jun 26 13:14:10 2014] 192.168.33.1:63355 [200]: /img/cake.icon.png
^C
[vagrant@localhost sample1]$

※また、ディレクトリの構成が変わっている…

画面

f:id:m_shige1979:20140626221723p:plain

ディレクトリ

cake3-dev3
drwxrwxrwx 1 vagrant vagrant    306  6月 14 23:50 2014 App
drwxrwxrwx 1 vagrant vagrant    102  6月  7 22:16 2014 Plugin
-rw-rw-rw- 1 vagrant vagrant    708  6月  7 22:16 2014 README.md
drwxrwxrwx 1 vagrant vagrant    170  6月  7 22:16 2014 Test
-rw-rw-rw- 1 vagrant vagrant    583  6月  7 22:16 2014 composer.json
-rw-rw-rw- 1 vagrant vagrant   8395  6月 26 12:32 2014 composer.lock
-rw-rw-rw- 1 vagrant vagrant 963760  6月 26 12:24 2014 composer.phar
-rw-rw-rw- 1 vagrant vagrant    648  6月  7 22:16 2014 index.php
-rw-rw-rw- 1 vagrant vagrant    817  6月  7 22:16 2014 phpunit.xml.dist
drwxrwxrwx 1 vagrant vagrant    204  6月  7 22:16 2014 tmp
drwxrwxrwx 1 vagrant vagrant    374  6月 26 12:32 2014 vendor
drwxrwxrwx 1 vagrant vagrant    306  6月  7 22:16 2014 webroot
cake3-alpha1
-rw-rw-r-- 1 vagrant vagrant  708  6月 26 12:51 2014 README.md
-rw-rw-r-- 1 vagrant vagrant  588  6月 26 13:02 2014 composer.json
-rw-rw-r-- 1 vagrant vagrant 8398  6月 26 13:03 2014 composer.lock
-rw-rw-r-- 1 vagrant vagrant  648  6月 26 12:51 2014 index.php
-rw-rw-r-- 1 vagrant vagrant  819  6月 26 12:51 2014 phpunit.xml.dist
drwxrwxr-x 2 vagrant vagrant 4096  6月 26 12:51 2014 plugins
drwxrwxr-x 8 vagrant vagrant 4096  6月 26 12:51 2014 src
drwxrwxr-x 4 vagrant vagrant 4096  6月 26 12:51 2014 tests
drwxrwxrwx 6 vagrant vagrant 4096  6月 26 12:51 2014 tmp
drwxrwxr-x 9 vagrant vagrant 4096  6月 26 13:11 2014 vendor
drwxrwxr-x 6 vagrant vagrant 4096  6月 26 12:51 2014 webroot

※App→srcであとは小文字になったくらい?

ちょっと試しに

bakeでpostsを作成してみる
[vagrant@localhost sample1]$ sh app/src/Console/cake bake model posts

Welcome to CakePHP v3.0.0-alpha1 Console
---------------------------------------------------------------
App : src
Path: /home/vagrant/sample1/app/src/
---------------------------------------------------------------
One moment while associations are detected.

Baking table class for Posts...

Creating file /home/vagrant/sample1/app/src/Model/Table/PostsTable.php
Wrote `/home/vagrant/sample1/app/src/Model/Table/PostsTable.php`

Baking entity class for Post...

Creating file /home/vagrant/sample1/app/src/Model/Entity/Post.php
Wrote `/home/vagrant/sample1/app/src/Model/Entity/Post.php`

Baking test fixture for Posts...

Creating file /home/vagrant/sample1/app/Test/Fixture/PostFixture.php
Wrote `/home/vagrant/sample1/app/Test/Fixture/PostFixture.php`

Baking test case for App\Model\Table\PostsTable ...

Creating file /home/vagrant/sample1/app/Test/TestCase/Model/Table/PostsTableTest.php
Wrote `/home/vagrant/sample1/app/Test/TestCase/Model/Table/PostsTableTest.php`
[vagrant@localhost sample1]$ sh app/src/Console/cake bake controller posts

Welcome to CakePHP v3.0.0-alpha1 Console
---------------------------------------------------------------
App : src
Path: /home/vagrant/sample1/app/src/
---------------------------------------------------------------

Baking controller class for Posts...

Creating file /home/vagrant/sample1/app/src/Controller/PostsController.php
Wrote `/home/vagrant/sample1/app/src/Controller/PostsController.php`
Bake is detecting possible fixtures...

Baking test case for App\Controller\PostsController ...

Creating file /home/vagrant/sample1/app/Test/TestCase/Controller/PostsControllerTest.php
Wrote `/home/vagrant/sample1/app/Test/TestCase/Controller/PostsControllerTest.php`
[vagrant@localhost sample1]$ sh app/src/Console/cake bake view posts

Welcome to CakePHP v3.0.0-alpha1 Console
---------------------------------------------------------------
App : src
Path: /home/vagrant/sample1/app/src/
---------------------------------------------------------------

Baking `index` view file...

Creating file /home/vagrant/sample1/app/src/Template/Posts/index.ctp
Wrote `/home/vagrant/sample1/app/src/Template/Posts/index.ctp`

Baking `view` view file...

Creating file /home/vagrant/sample1/app/src/Template/Posts/view.ctp
Wrote `/home/vagrant/sample1/app/src/Template/Posts/view.ctp`

Baking `add` view file...

Creating file /home/vagrant/sample1/app/src/Template/Posts/add.ctp
Wrote `/home/vagrant/sample1/app/src/Template/Posts/add.ctp`

Baking `edit` view file...

Creating file /home/vagrant/sample1/app/src/Template/Posts/edit.ctp
Wrote `/home/vagrant/sample1/app/src/Template/Posts/edit.ctp`
[vagrant@localhost sample1]$
ディレクトリ名が変わっただけかな???

f:id:m_shige1979:20140626222421p:plain

まとめ

curl -s https://getcomposer.org/installer | php

このコマンドだと一部失敗するので気をつける必要が有るけど適当な感じで動作はしているよう
そんなに機能を多用しないと思うけどMVCとして必要な機能は覚えておく必要があるので検証は続けていく

もうこれ以上大きな変更はありませんようにm(__)m