crecket/dependency-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crecket/dependency-manager

Composer 安装命令:

composer require crecket/dependency-manager

包简介

Resource dependency manager

README 文档

README

Build Status Latest Release

Introduction

A simple and small dependency manager for javascript and CSS files. All files will be combined, minified and cached. Less and Scss files are also supported and all css output is run through a auto-prefixer.

Requirements

- matthiasmullie/minify ^1.3
- doctrine/cache ^1.6
- leafo/scssphp ^0.6.3
- tedivm/jshrink ^1.1
- leafo/lessphp ^0.5.0
- twig/twig ^1.23
- css-crush/css-crush ^dev-master

Installation

  1. Install with composer

    composer require crecket/dependency-manager

  2. Add the twig extension to your twig view:

    $twig->addExtension(new Crecket\DependencyManager\Response());

Usage

Adding new files

addFiles($fileList, $groupName);
  • PARAM1: enter a single string to a file location or a array with multiple files.
  • PARAM2: the group name, this way you can store multiple file groups
use Crecket\DependencyManager\Loader;
Loader::addFiles('testFile.css', 'cssGroupName');

// different group and multiple files this time
Loader::addFiles(array('testFile.css', '/some/folder/file_name.css'), 'cssGroupName2');

Remove files

removeFiles($groupName);
  • PARAM1: contains the file group name.
Loader::removeFiles('cssGroupName2');

Create a url

Twig: getFilesLink(minify, groupName)
  • PARAM1: Minify the files or not
  • PARAM2: Group name
<script src="/minify.php{{ getFilesLink(true, 'jsGroupName') }}">
PHP: getFilesLink(
  • PARAM1: Minify the files or not
  • PARAM2: Group name
<link href="/minify.php<?php echo Crecket\DependencyManager\Loader::getFilesLink(true, 'cssGroupName'); ?>" rel="stylesheet">

Response

Standard php example
$options = array(
    // Location that the default Doctrine/FilesystemCache will use. Location is based on the root
    // Required if no custom cache object is given
    'CacheLocation' => '/cache',

    // Optional, namespace to use for the doctrine file system cache
    'CacheNamespace'  => 'DependencyManagerNamespace',
);

define('ROOT', __DIR__); // Don't forget this!

try{
    $Response = new Crecket\DependencyManager\Response($options);

    echo $Response->getResult();
}catch(Crecket\DependencyManager\Exception $ex){ // catch errors
    echo $ex->getTitle();
    echo '<br>';
    echo $ex->getMessage();
}
Silex route example

You can quite easily use the url generator in silex to create a url to this route using

<script src="{{ url('dependency_minify', {id: GetFilesHash(false, 'jsGroupExample')}) }}"></script>

or without twig

<script src="/minify/<?php echo Loader::getHash(true, 'jsGroupExample'); ?>"

Next create a route:

// ID contains the hash id
$app->get('/minify/{id}', function ($id) use ($app) {

    // Options
    $options = array(
        'CacheLocation' => '/cache',
        'CacheNamespace' => 'DependencyManagerNamespace'
    );

    try {
        // second parameter contains the hash id
        $Response = new Crecket\DependencyManager\Response($options, $id);

        // Get the response data
        $response_data = $Response->getResult();

        // Get the headers and status code for this request
        $header_data = Crecket\DependencyManager\Utilities::getHeaders();

    } catch (Crecket\DependencyManager\Exception $ex) { // catch errors
        // return a error
        return new Symfony\Component\HttpFoundation\Response(
            $ex->getTitle() . '<br>' . $ex->getMessage(),
            500,
            array()
        );
    }

    // Return content, headers and status code
    return new Symfony\Component\HttpFoundation\Response(
        $response_data,
        $header_data['status_code'],
        $header_data['headers']
    );
})->bind('dependency_minify');

Debugging

Response takes a optional second parameter which will make sure the session storage and secret key are ignored. This can be a hash id to retrieve the files stored in the session, or a direct array with files

$file_list = array('/some/js/file.js', '/another/js/files.js');
$Response = new Crecket\DependencyManager\Response($options, $file_list);

Or get the hash value directly to use in a route/url generator.

$file_hash = Loader::getHash($minify, $groupName);
$Response = new Crecket\DependencyManager\Response($options, $file_hash);

Security

To ensure only you can create a file list add a secret key. Make sure this key is secure/long enough!

Loader::Secret('some long secret passphrase');

Issues

Font files in Css

External font files, for example bootstrap's Glyphicons my return 404 errors because the path has changed. These can usually be fixed by copying the font files and moving them to a /fonts folder in your web root.

crecket/dependency-manager 适用场景与选型建议

crecket/dependency-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 crecket/dependency-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 crecket/dependency-manager 我们能提供哪些服务?
定制开发 / 二次开发

基于 crecket/dependency-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 98
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2016-01-24