Skip to content
Permalink
Browse files

Add an install script.

This install script takes care of copying the default config file into
its proper place, and changing permissions on the tmp dir if required.
This will help ease use of the app skeleton. It also gives a place for
application developers to provide their own install script if they want.
  • Loading branch information...
markstory committed Sep 4, 2013
1 parent cf11244 commit 2b2ee2fe2437162db34129c2511906700f76deb8
Showing with 89 additions and 1 deletion.
  1. +83 −0 App/App/Console/Installer.php
  2. +6 −1 App/composer.json
@@ -0,0 +1,83 @@
<?php
/**
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Console;
use Composer\Script\Event;
/**
* Provides installation hooks for when this application is installed via
* composer. Customize this class to suit your needs.
*/
class Installer {
/**
* Does some routine installation tasks so people don't have to.
*
* @param Composer\Script\Event $event
*/
public static function postInstall(Event $event) {
$io = $event->getIO();
$rootDir = dirname(dirname(__DIR__));
static::createAppConfig($rootDir, $io);
static::setTmpPermissions($rootDir, $io);
}
/**
* Create the Config/app.php file if it does not exist.
*
* @param string $dir The application's root directory.
* @param Composer\IO\IOInterface IO interface to write to console.
* @return void
*/
public static function createAppConfig($dir, $io) {
$appConfig = $dir . '/App/Config/app.php';
$defaultConfig = $dir . '/App/Config/app.php.default';
if (!file_exists($appConfig)) {
copy($defaultConfig, $appConfig);
$io->write('Created `Config/app.php` file');
}
}
/**
* Set globally writable permissions on the tmp directory.
*
* This is not the most secure default, but it gets people up and running quickly.
*
* @param string $dir The application's root directory.
* @param Composer\IO\IOInterface IO interface to write to console.
* @return void
*/
public static function setTmpPermissions($dir, $io) {
$worldWritable = bindec('0110000000');
// Get current permissions in decimal format so we can bitmask it.
$currentPerms = octdec(substr(sprintf('%o', fileperms($dir . '/tmp')), -4));
if (($currentPerms & $worldWritable) != $worldWritable) {
$io->write('Attempting to set permissions on tmp/');
$result = chmod('./tmp', $currentPerms | $worldWritable);
if ($result) {
$io->write('Permissions set on tmp/');
} else {
$io->write('Failed to set permissions on tmp/ you must do it yourself.');
}
}
}
}
@@ -1,7 +1,8 @@
{
"name": "cakephp/app",
"name": "cakephp/cakephp-app",
"description": "CakePHP skeleton app",
"homepage": "http://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"cakephp/cakephp": "dev-3.0",
@@ -12,7 +13,11 @@
},
"autoload": {
"psr-0": {
"": ".",
"App\\": "."
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall"
}
}

0 comments on commit 2b2ee2f

Please sign in to comment.
You can’t perform that action at this time.