itinance/tiny-state-machine

1.0.3 2016-02-08 16:24 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:26:14 UTC


README

安装

composer require itinance/tiny-state-machine

用法

这个状态机允许在应用程序中设置一些状态,并在其他地方(甚至在 Twig 中)请求这个状态。

设置状态

StateMachine::instance()->setState('Foobar');

使用值设置状态

StateMachine::instance()->setState('Foobar', 'barfoo');

请求状态

StateMachine::instance()->getState('Foobar' /* , $default */);

StateMachine::instance()->hasState('Foobar');
StateMachine::instance()->hasStateWithValue('Foobar', 'barfoo');

Twig

{% if hasState('Foobar') %}