承接 johnkrovitch/sam 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

johnkrovitch/sam

最新稳定版本:v0.1.7

Composer 安装命令:

composer require johnkrovitch/sam

包简介

Simple Assets Manager

README 文档

README

Simple Assets Manager

Version : 0.1.7

Build Status Scrutinizer Code Quality Code Coverage Build Status GuardRails badge

Sam is your friend. Sam is like you, he does not like handling complicated assets related stuff.

Sam is a Simple Assets Manager to help assets management in PHP Project. You will be able to easily describe where you want your assets to compiled.

Sam was first develop to be used with the SamBundle, but it can be used stand-alone. Using Sam stand-alone require coding your building tasks. With the SamBundle, you will be able to use a more convenient yml configuration syntax.

Installation

Using composer :

    composer require johnkrovitch/sam

Usage

Filters

A filter is a process which transform one or more source files into one or more destination files, using a binary or not. A filter can have options, like the binary path.

Sam a has the following built-in filters for now. More will be added. You can also add your own filter

  • Compass filter

The Compass filter will use the Compass binary to transform your ".scss" files into ".css" files.

    $configuration = [
        'compass' => [
            // put here the compas binary path. By default it will assume
            // that the binary is loaded in $PATH
            'bin' => 'compass'
        }
    ];
  • Minify filter

The Minify Filter use the matthiasmullie/minify library to minify your css and js files. No options are available for now.

  • Merge filter

The Merge filter will merge multiple files into one. It allow you to reduce the number of http requests. No options are available for now.

  • Copy filter

The Copy filter will copy one or more files into one or more directory.

Building your filters

In order to use compile your assets, you have to build the filters, using the FilterBuilder. It will check the given configuration and create filters instances according to this configuration.

    
    // enable the filters with default configuration
    $configuration = [
        'compass' => [],
        'merge' => [],
        'minify' => [],
    ];
    
    // an event dispatcher is required. Some events will be dispatched
    // before the application of each filter
    $eventDispatcher = new EventDispatcher();
    
    // build tasks using the builder
    $builder = new FilterBuilder($eventDispatcher);
    
    // filters are build, they can be passed to the runner
    $filters = $builder->build($configuration);

Tasks

A Task will apply one or more filters to a list of source files to a directory or a list of destination files. It describe your assets compilation process.

Building your tasks

    $taskConfigurations = [
        // main.css is just a name, you can put what ever you want
        'main.css' => [
            // this filters will be applied in this order to the destination files 
            'filters' => [
                'compass',
                'minify',
                'merge',
            ],
            // sources file to be compiled
            'sources' => [
                'src/MyBundle/Resources/public/css/mycss.css',
                'app/Resources/public/css/mycss.css',
                'css/mycss.css',
                'vendor/a-library/css/lib.css'
            ],
            // all assets will be minified and merged to this file
            'destinations' => [
                'web/css/main.min.css'
            ],
        ],
        
        'main.js' => [
            'filters' => [
                'compass',
                'minify',
                'merge',
            ],
            'sources' => [
                'css/myjs.js',
                'css/mycss.css',
                'css/mycss.scss',
            ],
            // all assets will be minified and merged to this directory
            'destinations' => [
                'web/css'
            ],
        ]
    ];
    
    // build tasks using the builder
    $builder = new TaskBuilder();
    $tasks = $builder->build($taskConfigurations);
    

Running the tasks

Once your filters are configured and build, once your tasks are create, you should run the task using the TaskRunner. A normalizer should be created to normalize file names for the filters.

    // used to normalize file names because multiple pattern could be passed
    $normalizer = new Normalizer('/path/to/project_root');
    
    // used to locate the file
    $locator = new Locator($normalizer);
    
    // create the runner
    $runner = new TaskRunner(
        $filters,
        $locator,
        // debug
        false
    );

    // run your task
    foreach ($tasks as $task) {
        $runner->run($task);
    }

SamBundle

Sam is designed to be used with Symfony and SamBundle integrate the Sam library with Symfony. It will allow your to put your assets configuration into yaml files. It will ease the integration of vendor js/css library (bootstrap, jquery...) using composer.

You no more have to use BootstrapBundle or jQueryBundle. You just have to require them using composer and easily copy, merge, minify those files with your custom assets.

Issues

Feel free to open an issue if you have a problem using this library.

License

The Sam library is release under the MIT License.

johnkrovitch/sam 适用场景与选型建议

johnkrovitch/sam 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.56k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 johnkrovitch/sam 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 6.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-09