Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Added a cleanup routing to the installer #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- We've added a post-install-cmd that recursively removes the `src/Composer/`
directory of the skeleton, ensuring you have a clean start when creating a
project.

### Deprecated

Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Expressive Skeleton and Installer

[![Build Status](https://secure.travis-ci.org/zendframework/zend-expressive-skeleton.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-expressive-skeleton)

*Begin developing PSR-7 middleware applications in seconds!*

[zend-expressive](https://github.com/zendframework/zend-expressive) builds on
[zend-stratigility](https://github.com/zendframework/zend-stratigility) to
provide a minimalist PSR-7 middleware framework for PHP with routing, DI
container, optional templating, and optional error handling capabilities.

This installer will setup a skeleton application based on zend-expressive by
choosing optional packages based on user input as demonstrated in the following
screenshot:

![screenshot-installer](https://cloud.githubusercontent.com/assets/459648/10410494/16bdc674-6f6d-11e5-8190-3c1466e93361.png)

The user selected packages are saved into `composer.json` so that everyone else
working on the project have the same packages installed. Configuration files and
templates are prepared for first use. The installer command is removed from
`composer.json` after setup succeeded, and all installer related files are
removed.

## Getting Started

Start your new Expressive project with composer:

```bash
$ composer create-project zendframework/zend-expressive-skeleton <project-path>
```

After choosing and installing the packages you want, go to the
`<project-path>` and start PHP's built-in web server to verify installation:

```bash
$ php -S 0.0.0.0:8000 -t public/ public/index.php
```
26 changes: 0 additions & 26 deletions readme.md

This file was deleted.

67 changes: 61 additions & 6 deletions src/Composer/OptionalPackages.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License
*/

namespace App\Composer;

Expand All @@ -11,6 +18,9 @@
use Composer\Package\Version\VersionParser;
use Composer\Script\Event;
use Composer\Package\BasePackage;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
* Composer installer script
Expand All @@ -21,26 +31,48 @@
* "pre-update-cmd": "Zend\\Expressive\\Composer\\OptionalPackages::install",
* "pre-install-cmd": "Zend\\Expressive\\Composer\\OptionalPackages::install"
* },
*
* @package Zend\Expressive\Composer
*
* @author Geert Eltink <https://xtreamwayz.github.io/>
*/
class OptionalPackages
{
/**
* @const string Regular expression for matching package name and version
*/
const PACKAGE_REGEX = '/^(?P<name>[^:]+\/[^:]+)([:]*)(?P<version>.*)$/';

/**
* @var array
*/
private static $config;

/**
* @var array
*/
private static $composerDefinition;

/**
* @var string[]
*/
private static $composerRequires;

/**
* @var string[]
*/
private static $composerDevRequires;

/**
* @var string[]
*/
private static $stabilityFlags;

/**
* Install command: choose packages and provide configuration.
*
* Prompts users for package selections, and copies in package-specific
* configuration when known.
*
* Updates the composer.json with the package selections, and removes the
* install and update commands on completion.
*
* @param Event $event
*/
public static function install(Event $event)
Expand Down Expand Up @@ -138,8 +170,31 @@ public static function install(Event $event)
// Update composer definition
$json->write(self::$composerDefinition);

// @TODO: Remove installer - Not working, getting unlink(D:\projects\test/src/Zend): Permission denied
//array_map('unlink', glob($projectRoot . '/src/Zend'));
self::cleanUp($io);
}

/**
* Clean up/remove installer classes and assets.
*
* On completion of install/update, removes the installer classes (including
* this one) and assets (including configuration and templates).
*
* @param IOInterface $io
*/
private static function cleanUp(IOInterface $io)
{
$io->write("<info>Removing Expressive installer classes and configuration</info>");

$rdi = new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
$rii = new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($rii as $filename => $fileInfo) {
if ($fileInfo->isDir()) {
rmdir($filename);
continue;
}
unlink($filename);
}
rmdir(__DIR__);
}

/**
Expand Down