Skip to content

Instantly share code, notes, and snippets.

@alphp
Forked from ogrrd/Cake Composer.md
Last active June 5, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphp/1d45e67dc16611dd69b30c358c6c6dd0 to your computer and use it in GitHub Desktop.
Save alphp/1d45e67dc16611dd69b30c358c6c6dd0 to your computer and use it in GitHub Desktop.
Install Cake 2.x with Composer

Install CakePHP 2.x with Composer

Windows version

Create project folder

mkdir C:\path\to\your\project
cd C:\path\to\your\project

Create composer.json

echo {} > composer.json
composer config name me/project
composer config type project
composer config vendor-dir vendors
composer config extra.installer-types ["cakephp-plugin"]
composer config extra.installer-paths.app/Plugin/{$name} ["type:cakephp-plugin"]

The created composer.json look as this:

{
    "name": "presst/presst",
    "type": "project",
    "config": {
        "vendor-dir": "vendors"
    },
    "extra": {
        "installer-types": "[cakephp-plugin]",
        "installer-paths": {
            "app/Plugin/{$name}": "[type:cakephp-plugin]"
        }
    }
}

But extra.installer-types and extra.installer-paths are array istead of string type.

Fix extra options

php -a
$composer = json_decode(file_get_contents('composer.json'), true);
$composer['extra']['installer-types'] = ['cakephp-plugin'];
$composer['extra']['installer-paths']['app/Plugin/{$name}'] = ['type:cakephp-plugin'];
file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
exit

The fixed composer.json look as this:

{
    "name": "presst/presst",
    "type": "project",
    "config": {
        "vendor-dir": "vendors"
    },
    "extra": {
        "installer-types": [
            "cakephp-plugin"
        ],
        "installer-paths": {
            "app/Plugin/{$name}": [
                "type:cakephp-plugin"
            ]
        }
    }
}

Install CakePHP for the project

composer require oomphinc/composer-installers-extender:* cakephp/cakephp:2.* cakephp/debug_kit:2.*

Bake the project

php vendors\cakephp\cakephp\lib\Cake\Console\cake.php -working . bake project .\app

Tell CakePHP where to find the new library

Update app/webroot/index.php and app/webroot/test.php

Replace this...

define('CAKE_CORE_INCLUDE_PATH',  ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib');

...with this

define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'vendors' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib');

Update app/Console/cake.php

Replace this...

$install = $root . PATH_SEPARATOR . 'C:' . DS . 'path' . DS . 'to' . DS . 'your' . DS . 'project' . DS . 'vendors' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';

...with this

$install = $root . DS . 'vendors' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';

Enable DebugKit

  • You need to enable the plugin in your app/Config/bootstrap.php file. If you are already using CakePlugin::loadAll();, then the following is not necessary.:

    CakePlugin::load('DebugKit');
  • Include the toolbar component in your app/Controller/AppController.php:

    class AppController extends Controller {
         public $components = array('DebugKit.Toolbar');
    }
  • Set Configure::write('debug', 1); in app/Config/core.php.

  • In app/View/Layouts/default.ctp replace this...

    <?php echo $this->element('sql_dump'); ?>

    ...with this

    <?php
    if (Configure::read('debug') and !class_exists('DebugPanel')) {
        echo $this->Html->css('cake.debug', ['inline' => true]);
        echo $this->Html->div('container-sql', $this->element('sql_dump'));
    }
    ?>

Use composer autoloader

Add this to the top of app/Config/bootstrap.php

App::import('Vendor', ['file' => 'autoload']);
@charset "utf-8";
th a {
display: block;
padding: 2px 4px;
text-decoration: none;
}
th a.asc:after {
content: ' ⇣';
}
th a.desc:after {
content: ' ⇡';
}
/* SQL log */
.cake-sql-log {
background: #fff;
clear: both;
margin: 0px 1em 1em 1em;
width: calc(100% - 2em);
}
.cake-sql-log th {
padding: 4px 8px;
background: #cacaca;
font-weight: bold;
}
.cake-sql-log td {
padding: 4px 8px;
text-align: left;
font-family: Monaco, Consolas, "Courier New", monospaced;
}
.cake-sql-log tr:nth-child(2n) {
background: #f0f0f0;
}
.cake-sql-log tr:hover {
background: #fff6c7;
}
.cake-sql-log caption {
padding: 4px 8px;
color:#fff;
background: #ff552a;
}
/** Debugging **/
pre {
color: #000;
background: #f0f0f0;
padding: 15px;
-moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.cake-debug-output {
padding: 0;
position: relative;
top: -30px;
}
.cake-debug-output > span {
position: relative;
top: 30px;
right: 1px;
background: rgba(255, 255, 255, 0.3);
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
padding: 5px 6px;
color: #000;
display: block;
float: right;
-moz-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.5);
-webkit-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.5);
box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.5);
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
}
.cake-debug,
.cake-error {
font-size: 16px;
line-height: 20px;
/*clear: both;*/
float: left;
width: 100%;
}
.cake-error > a {
text-shadow: none;
}
.cake-error {
white-space: normal;
}
.cake-stack-trace {
background: rgba(255, 255, 255, 0.7);
color: #333;
margin: 10px 0 5px 0;
padding: 10px 10px 0 10px;
font-size: 120%;
line-height: 140%;
overflow: auto;
position: relative;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
.cake-stack-trace a {
text-shadow: none;
background: rgba(255, 255, 255, 0.7);
padding: 5px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
margin: 0px 4px 10px 2px;
font-family: sans-serif;
font-size: 14px;
line-height: 14px;
display: inline-block;
text-decoration: none;
-moz-box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
-webkit-box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
}
.cake-code-dump pre {
position: relative;
overflow: auto;
}
.cake-context {
margin-bottom: 10px;
}
.cake-stack-trace pre {
color: #000;
background-color: #F0F0F0;
margin: 0px 0 10px 0;
padding: 1em;
overflow: auto;
text-shadow: none;
}
.cake-stack-trace li {
padding: 10px 5px 0px;
margin: 0 0 4px 0;
font-family: monospace;
border: 1px solid #bbb;
-moz-border-radius: 4px;
-wekbkit-border-radius: 4px;
border-radius: 4px;
background: #dcdcdc;
background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#dcdcdc));
background-image: -webkit-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -moz-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -ms-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -o-linear-gradient(top, #fefefe, #dcdcdc);
background-image: linear-gradient(top, #fefefe, #dcdcdc);
}
/* excerpt */
.cake-code-dump pre,
.cake-code-dump pre code {
clear: both;
font-size: 12px;
line-height: 15px;
margin: 4px 2px;
padding: 4px;
overflow: auto;
}
.cake-code-dump .code-highlight {
display: block;
background-color: rgba(255, 255, 0, 0.5);
}
.code-coverage-results div.code-line {
padding-left:5px;
display:block;
margin-left:10px;
}
.code-coverage-results div.uncovered span.content {
background:#ecc;
}
.code-coverage-results div.covered span.content {
background:#cec;
}
.code-coverage-results div.ignored span.content {
color:#aaa;
}
.code-coverage-results span.line-num {
color:#666;
display:block;
float:left;
width:20px;
text-align:right;
margin-right:5px;
}
.code-coverage-results span.line-num strong {
color:#666;
}
.code-coverage-results div.start {
border:1px solid #aaa;
border-width:1px 1px 0px 1px;
margin-top:30px;
padding-top:5px;
}
.code-coverage-results div.end {
border:1px solid #aaa;
border-width:0px 1px 1px 1px;
margin-bottom:30px;
padding-bottom:5px;
}
.code-coverage-results div.realstart {
margin-top:0px;
}
.code-coverage-results p.note {
color:#bbb;
padding:5px;
margin:5px 0 10px;
font-size:10px;
}
.code-coverage-results span.result-bad {
color: #a00;
}
.code-coverage-results span.result-ok {
color: #fa0;
}
.code-coverage-results span.result-good {
color: #0a0;
}
/** Elements **/
#url-rewriting-warning {
display:none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment