定制 openbuildings/jam-freezable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

openbuildings/jam-freezable

Composer 安装命令:

composer require openbuildings/jam-freezable

包简介

Freeze dynamically computed values in the database using Jam

README 文档

README

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version

Freezable is a Jam ORM behavior for freezing dynamically computed values in the database.

Often one would have a method in the model which computes and returns a value. It could be a price, time or anything else. The computation could be a heavy one or time sensitive (based on time, currency exchange rates and other). Then you would need to save the value in a database column (a.k.a freezing) and in the future read the value from the field rather than the method.

The Freezable behavior allows you to do exactly that in an easy way. The freeze(), unfreeze() and is_frozen() methos give you the convenience to easily get either the dynamically computed or the frozen value when needed.

Usage

It has 3 parameters associations, parent and fields

class Some_Model extends Jam_Model {

	public static function initialize(Jam_Meta $meta)
	{
		$meta
			->behaviors(array(
				'freezable' => Jam::behavior('freezable', array(
					'fields' => 'price',
					'parent' => 'some_parent_model',
					'associations' => array('some_child', 'some_children'),
				)),
			));
	}
	//...
}

That means that whenever the model is frozen then the field named price will be assigned the value of the method price(). And all the associations will be also frozen. The associations themselves have to be freezable (have the Freezable behavior attached) in order for this to work. And the price() method, as well as any other fields, have to take into account the value of the field. E.g.

public function price()
{
	return $this->price ? $this->price : $this->compute_price();
}

The parent association is used in order to find the value of is_frozen, so that only one model holds the value of the flag. So that if you call is_frozen() on a freezable that has a parent, then it will get that value from the parent.

Details

TODO: add note about validation TODO: add more examples

License

Copyright (c) 2013 OpenBuildings, Inc. Developed by Ivan Kerin as part of clippings.com.

Under BSD-3-Clause license, read LICENSE file.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固