江湖夜雨十年

Symfony workflow demo.

March 13, 2017 fatrbaby

<?php

require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\Workflow\DefinitionBuilder;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
use Symfony\Component\Workflow\Registry;

$builder = new DefinitionBuilder();
$builder->addPlaces(['draft', 'review', 'rejected', 'published']);

$builder->addTransition(new Transition('to_review', 'draft', 'review'));
$builder->addTransition(new Transition('reject', 'review', 'rejected'));
$builder->addTransition(new Transition('publish', 'rejected', 'published'));

$definition = $builder->build();

$marking = new SingleStateMarkingStore('status');
$workflow = new Workflow($definition, $marking);

$entity = new class {
    public $status = 'review';
};

$can = $workflow->can($entity, 'reject');

var_dump($can);

Dockerfile指令详解

March 6, 2017 fatrbaby

FROM ubuntu  #指定基础镜像
RUN echo "hello world" #执行命令
RUN ['command', 'argment-1', 'argment-2']
COPY source-path target-path #copy文件,可以像run一样写成多个源和目标
ADD source-path target-path #copy文件,源可以是url,并且ADD会自动解压缩,拷贝压缩文件则不用此命令
CMD echo "hello world" #执行命令
CMD ['command', 'argment-1', 'argment-2']
ENTRYPOINT command #指定
ENV <key> <value> #设置环境变量
ENV <key1>=<value1> <key2>=<value2>... #设置环境变量
ARG <argment-name>[=<default-value>] #构建参数。该默认值可以在构建命令 docker build 中用 --build-arg <参数名>=<值> 来覆盖
VOLUME ["path-1", "path-2", "path-3"] #定义匿名卷,容器不挂载目录时,默认的写入数据的目录
VOLUME path
EXPOSE port-1[port-2...] #指令是声明运行时容器提供服务端口
WORKDIR path #指定工作目录(或者称为当前目录)
USER username #指定当前用户名,只是帮助你切换到指定用户而已,这个用户必须是事先建立好的,否则无法切换
HEALTHCHECK [options] command #设置检查容器健康状况的命令
ONBUILD others-command #在当前镜像构建时并不会被执行。只有当以当前镜像为基础镜像,去构建下一级镜像的时候才会被执行。
  • docker中有一个特殊的镜像:scratch - 虚拟镜像
  • docker中每个指令都是都会建立一层,所以尽量将RUN写在一个指令里
  • container是进程,所以启动容器的时候,需要指定所运行的程序及参数
  • ADDCOPYENVEXPOSELABELUSERWORKDIRVOLUMESTOPSIGNALONBUILD支持对环境变量的展开

使用gulp构建前端资源

August 2, 2016 fatrbaby

var gulp = require('gulp');
var concat = require('gulp-concat');
var concat_by_dir = require('gulp-concat-dir');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var minify = require('gulp-clean-css');
var copy = require('gulp-copy-ext');


gulp.task('boot', function() {
    gulp.src([
            './src/boot.js',
            './src/directives/*.js',
            './src/components/*.js',
            './src/filters/*.js'
        ])
        .pipe(concat('boot.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./build/'));
});

gulp.task('apps', function () {
    gulp.src([
            './src/apps/*/app.js',
            './src/apps/*/routes.js'
        ])
        .pipe(concat_by_dir({ext: '.js'}))
        .pipe(uglify())
        .pipe(gulp.dest('./build/apps/'));
});

gulp.task('sass', function () {
    gulp.src('./src/sass/app.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(minify({debug: true}))
        .pipe(gulp.dest('./build/css/'));
});

gulp.task('copy', function () {
    gulp.src('./statics/fonts/*')
        .pipe(copy())
        .pipe(gulp.dest('./build/css/fonts'));
});

gulp.task('default', ['boot', 'apps', 'sass']);

gulp.task('watch', function () {
    gulp.watch('src/**/*.js', ['default']);
});