本文整理汇总了PHP中Events::add_once方法的典型用法代码示例。如果您正苦于以下问题:PHP Events::add_once方法的具体用法?PHP Events::add_once怎么用?PHP Events::add_once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Events
的用法示例。
在下文中一共展示了Events::add_once方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_helperes_from_cache
protected function load_helperes_from_cache($helpers)
{
if (!CMS::is_lazy_components()) {
return;
}
if ($this->is_cache_loaded) {
return;
}
$this->is_cache_loaded = true;
if ($classes = WS::env()->cache->get('cms:viwes:helpers_classes')) {
foreach ($classes as $name => $class) {
$helpers->append($class, $name);
}
} else {
Events::add_once('cms.load_components', function () use($helpers) {
WS::env()->cache->set('cms:viwes:helpers_classes', $helpers->classes, 0);
});
CMS::load_components();
}
}
示例2: load_cache
protected function load_cache()
{
if (!CMS::is_lazy_components()) {
return;
}
if ($this->is_cache_loaded) {
return;
}
$this->is_cache_loaded = true;
if ($classes = $this->cache->get('cms:orm:classes')) {
$this->mappers = array_replace_recursive($classes, $this->mappers, self::$classes);
} else {
$self = $this;
$cache = $this->cache;
Events::add_once('cms.load_components', function () use($self, $cache) {
$mappers = array_replace_recursive(CMS_ORM_Root::$classes, $self->get_mappers());
$cache->set('cms:orm:classes', $mappers, 0);
});
CMS::load_components();
}
}
示例3: process_schema
public function process_schema()
{
// process schema modules
$modules = $this->schema_modules();
if (!empty($modules)) {
foreach ($modules as $name => $module) {
CMS::cached_run($module);
}
}
// get data from config
$schema = $this->config('schema');
$fields = $this->config('fields');
$tmp1 = (array) $schema;
$tmp2 = (array) $fields;
if (empty($tmp1) && empty($tmp2)) {
return;
}
if (empty($fields)) {
$fields = Core::hash();
}
$schema = clone $schema;
// some time we have fields without info in schema
// fix it
$schema_keys = array_keys((array) $schema);
$fields_keys = array_keys((array) $fields);
$diff = array_diff($fields_keys, $schema_keys);
foreach ($diff as $name) {
$schema->{$name} = array();
}
//fields to schema
Core::load('DB.Schema');
Core::load('CMS.Fields');
foreach ($schema as $name => &$table) {
if (!empty($fields->{$name})) {
$table_fields = $fields->{$name};
$table_name = $name;
CMS_Fields::fields_to_schema($fields->{$name}, $name, $table);
Events::add_once('db.schema.after_execute.' . $name, function ($tf_schema) use($table_fields, $table_name) {
foreach ($table_fields as $tf_name => $tf_data) {
$tf_type = CMS_Fields::type($tf_data);
$tf_type->process_schema($tf_name, $tf_data, $table_name, $table_fields);
}
});
}
}
// remove empty values
foreach ($schema as $name => $ttable) {
if (empty($ttable)) {
unset($schema->{$name});
}
}
// cache
$cname = strtolower($this->get_name());
if (!empty($cname)) {
$cache_key = 'cms:component:' . $cname . ':schema:' . md5(serialize($schema));
if ($this->cache->has($cache_key)) {
return $this;
}
$this->cache->set($cache_key, 1, 0);
}
// run
DB_Schema::process_cache($schema);
}
示例4: load_mappers_from_cache
protected static function load_mappers_from_cache()
{
if (!self::is_lazy_components()) {
return;
}
// include files where reouters defined
if ($files = WS::env()->cache->get('cms:url_mappers:files')) {
foreach ($files as $f) {
include_once $f;
}
}
// get & load routers classes
if ($classes = WS::env()->cache->get('cms:url_mappers:classes')) {
foreach ($classes as $name => $class) {
if (!isset(self::$mappers[$name])) {
$reflection = new ReflectionClass($class);
self::$mappers[$name] = $reflection->newInstance();
}
}
} else {
// load components & save routers
Events::add_once('cms.load_components', function () {
$mappers = CMS::$mappers;
$classes = array();
foreach ($mappers as $name => $mapper) {
$classes[$name] = get_class($mapper);
}
WS::env()->cache->set('cms:url_mappers:classes', $classes, 0);
$files = array();
foreach ($mappers as $mapper) {
$reflection = new ReflectionClass($mapper);
$files[] = $reflection->getFileName();
}
WS::env()->cache->set('cms:url_mappers:files', $files, 0);
});
self::load_components();
}
}