ekuiter/feature-php

使用 PHP 和 FeatureIDE 进行面向特征的编程

v1.1 2018-03-22 17:40 UTC

This package is not auto-updated.

Last update: 2024-09-29 12:46:18 UTC


README

feature-php 是一个用于分析和实现面向特征的软件产品线的 Composer 扩展包。

它可以用于

  • 分析和验证 FeatureIDE 特征模型和配置(域分析
  • 使用以下可变性机制实现和跟踪特征(域实现
    • PHP 代码的运行时可变性
    • 类似构建系统的文件和目录复制
    • 类似预处理器模板和块系统
    • 面向特征的编程(基于 mixin 的)
    • 面向方面的编程(使用 Go! AOP
  • 生成产品并将其导出(例如,作为 ZIP 文件)(产品派生

(如果您需要用于特征模型和配置的视觉工具,请查看 ekuiter/feature-configuratorekuiter/feature-model-viz。)

要求

要使用 feature-php,需要以下条件

  • PHP >= 5.3
  • libxml 和 SimpleXML 扩展(大多数服务器都有这些)

还推荐以下扩展

  • DOM 扩展(用于验证 XML 数据)
  • ZIP 扩展(用于将产品导出为 ZIP 文件)

feature-php 还依赖于一些 Composer 扩展包

要安装依赖项,创建以下 composer.json 文件

{
    "minimum-stability": "dev",
    "require": {
        "ekuiter/feature-php": "dev-master"
    }
}

然后运行 composer install有关 Composer 的更多信息)。有关更多信息,请参阅 指南

使用方法

请参阅 用户指南 了解安装和使用方法。

为了快速入门,您还可以

API 参考文档

feature-php 的 API 参考文档可以在 这里 找到。

一个好的起点是 ProductLine 类。如果您想了解配置文件,请查看 ProductLine\Settings 类。

示例

命令行界面

安装后,在项目根目录中运行

vendor/bin/feature-php --settings <productLine.json> --configuration <configuration.xml>

以分析给定的配置。有关命令行界面的更多信息,请运行 vendor/bin/feature-php 或参阅 指南。要查看示例输入文件,请参阅 uvr2web.jsonUVR1611.xml

脚本使用

<?php

/*
 * This is a simple example for the usage of the feature-php library.
 * Here we are going to analyze a given feature model regarding a given configuration.
 * Then, for a valid configuration, we analyze the generated product.
 * Finally, the user may export a ZIP file and download it.
 * 
 * Feature models and configurations are expected to be supplied as
 * FeatureIDE XML files, see https://featureide.github.io/.
 * The product line settings can be supplied in various formats, see
 * the feature-php API reference.
 */

use \FeaturePhp as fphp; // this is just for convenience so we can abbreviate the prefix "FeaturePhp\" below

require "vendor/autoload.php"; // include classes from Composer

// feature-php may throw exceptions, in particular on parsing errors.
// We just output an exception if we get one.
try {

    // read a product line settings file, containing the model and the default configuration
    $productLine = new fphp\ProductLine\ProductLine(fphp\ProductLine\Settings::fromFile("config.json"));

    // alternatively you can supply the settings directly as an array
    $productLine = new fphp\ProductLine\ProductLine(fphp\ProductLine\Settings::fromArray(array(
        "model" => "model.xml",
        "defaultConfiguration" => array(
            "data" => "<configuration></configuration>"
        )
    )));

    // the configuration is user-supplied with the GET or POST parameter "configuration"
    // we could also use XmlConfiguration::fromString(...) or XmlConfiguration::fromFile(...)
    if (isset($_REQUEST["configuration"]))
        $configuration = new fphp\Model\Configuration(
            $productLine->getModel(),
            fphp\Model\XmlConfiguration::fromRequest("configuration")
        );
    else // if not supplied, use the default configuration
        $configuration = $productLine->getDefaultConfiguration();
    // used for replacements by the templating system
    fphp\Specification\ReplacementRule::setConfiguration($configuration);

    if (!isset($_REQUEST["generate"])) {
        // output some information on the model and configuration
        echo '<h2><a href="?generate">Generate</a></h2>';
        echo $configuration->renderAnalysis();
        
    } else {
        // we want to generate or export a product
        $product = $productLine->getProduct($configuration);
        
        if (!isset($_REQUEST["export"])) {
            // output some information on the product
            echo '<h2><a href="?generate&export">Download ZIP</a></h2>';
            echo $product->renderAnalysis();
            
        } else
            // export product as ZIP file (using "tmp" as a temporary directory)
            $product->export(new fphp\Exporter\DownloadZipExporter("tmp"));
    }
    
} catch (Exception $e) {
    echo $e->getMessage();
}

?>

许可证

本项目遵循LGPL v3许可协议发布。