两种类型的资源探测器

xml文件资源探测器

目录资源探测器

系统内置的资源探测器(核心)

数据库定义目录资源探测器  -base_application_datable  关注dbschema  

service资源探测器  -base_application_service  关注services.xml  

语言包资源探测器  -base_application_lang

缓存更新探测器  -base_application_cache_expires

位置解释

base-》app名称

application-》lib/application

datable-》datable.php文件

其余的资源探测器,都通过service的形式注册,注册点为app_content_detector (detector探测器的意思)

这里怎么实现的过会再说???

查看系统里目前已注册的资源探测器

dev:show services | grep -i app_content_detector (dev:show services 所有注册的service,grep -i app_content_detector从这些注册的service中找资源探测器)//这个命令只适合与linux

windows命令未找到,等找到会补上---------------------------------------------------???

资源探测器开放!!!

级联结构

Iterator(迭代器)接口

base_application_prototype_content 使用 Iterator 接口(implements)  

位置app/base/lib/application/prototype/content.php 

base_application_prototype_filepath 继承 base_application_prototype_content

base_application_prototype_xml 继承 base_application_prototype_content

filepath.php提供可以遍历目录里所有文件或目录的接口

xml.php提供可以遍历xml文件下某个节点下所有子节点的接口

例子

开发xml文件资源探测器

desktop作为例子

菜单探测器针对desktop.xml内寻找permissions下所有permission子节点

<desktop>
<permissions>
<permission id="shopsetting" display='true'>商店设置 </permission>
<permission id="setting" display='true'>数据管理</permission>
<permission id="performance" display='true'>缓存,队列,计划任务管理</permission>
<permission id="users" display='true'>权限管理</permission>
<permission id="other" display='true'>其他</permission>
</permissions> </desktop>

建立探测器类文件(那个app下探测什么,该探测器继承与那类探测器)

<?php
class desktop_application_permission extends base_application_prototype_xml{
}

位置app/desktop/lib/application/permission.php

注册成service

在service中进行注册

app/desktop/desktop.xml(配置文件)(app_conetent_detector  service box id意思)

<services>
...
<service id="app_content_detector">
<class>desktop_application_permission</class>
</service>
...
</services>

补充desktop_application_permission类

<?php
class desktop_application_permission extend base_application_prototype_xml{
var $xml='desktop.xml';//指定要探测的xml资源文件,本例中会调用app/desktop/desktop.xml
var $xsd='desktop_content';//指定xml对应的xsd位置,本例是app/desktop/xmlschema/content.xsd(为何不是desktop_xmlschema_content)
var $path='permissions/permission';//指定xml节点
}

desktop.xml下permissions节点下所有permission子节点

current

设置当前遍历子节点的内容$current和当前元素的键$key

通过$this->iterator()->current()可以获取当前xml子节点的array数据

本例中是当前permissions/permission节点数据

<?php
class desktop_application_permission extends base_application_prototype_xml{
function current(){
$this->current = $this->iterator->current();
$this->key = $this->current['id'] ;
return $this;
}
}

install

install app_name时调用

需要重载,安装当前遍历节点的数据

<?php
class desktop_application_permission extend base_application_prototype_xml{
function row(){
$row = array(
'menu_type'=>$this->content_typename();
'app_id'=>$this->target_app->app_id
);
$row['menu_title']=$this->current['value'];
$row['display'] = $this->current['display'];
$access_opct=array(
'show'=>$this->current['show'],
'save'=>$this->current['save']
);
$row['addon']=serialize($access_opct);
$row['permission']=$this->current['id']//$this->key;
return $row;
}
   function install(){
     kernel:log('Installing'.$this->content_typename().' '.$this->key());
     return app:get('desktop')->model('menus')->insert($this->row());
   }  
}

到这里就解释了资源探测器的作用了,探测资源,获取资源,操作资源

clear_by_app

资源卸载,在uninstall app_name时调用

<?php
class desktop_application_permission extends base_application_prototype_xml {
function clear_by_app($app_id){
if(!$app_id){
return false;
}
app::get('desktop')->model('menus')->delete(array(
'app_id'=>$app_id,'menu_type' => $this->content_typename()));
}

update

资源更新 update app_name时调用 不需要重载(基类有这个函数)

active_by_app

active app_name时调用 不需要重载(基类有这个函数)

pause_by_app

pause app_name时调用 不需要重载(基类有这个函数)

如何开发目录型资源探测器

类似

去掉$xml和$xsd属性

去掉current()函数,基类提供的函数默认设置$key为文件名/目录名

增加filter()函数,可以只遍历$path目录下关注的文件和目录

增加getPathname(),可以取得当前节点的目录名

增加getFilename(),可以取得当前节点的文件名

ecos资源探测器的更多相关文章

  1. eCos中的线程与同步

    http://blog.csdn.net/ooaven/article/details/6280018 先看一下eCos线程的创建.控制以及优先级的操作这三个方面的知识,主要是对它的实现方式及API做 ...

  2. ecstore实现图片分离(静态资源分离)配置文件

    转载http://bbs.ec-os.net/read.php?tid=854 图片分离涉及到三个config设置#define('APP_STATICS_HOST', 'http://192.168 ...

  3. C 语言资源大全中文版

    C 语言资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-c 是 koz.ross 发起维护的 C 语言资源列表,内容包括了: ...

  4. Github资源汇集

    Github资源汇集 突然发现申请博客园已经两年有余,没有发表过一篇文章,十分惭愧.言归正传,先分享一下两年来收集的部分编程资源,大部分为Github上的项目.虽然网上这样的分享已不在少数,但不如我理 ...

  5. OpenRisc-34-ORPSoC跑eCos实验

    引言 ORPSoC目前支持好几种OS,除了前面一直介绍的linux,还支持eCos,eCos是RTOS,如果你的系统对时间的要求比较高,那eCos会是一个不错的选择. 本小节就简单介绍一下,在ORPS ...

  6. Python 库,资源

    库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...

  7. MIT挑战(如何在12个月内自学完成MIT计算机科学的33门课程|内附MIT公开课程资源和学习顺序

    译者注:本文译自Scott H. Young的博客,Scott拥有超强的学习能力,曾在12个月内自学完成麻省理工学院计算机科学的33门课程.本文就是他个人对于这次MIT挑战的介绍和总结. 版权声明:本 ...

  8. Docker背后的内核知识——cgroups资源限制(转)

    时间 2015-04-20 21:10:00 InfoQ 原文  http://www.infoq.com/cn/articles/docker-kernel-knowledge-cgroups-re ...

  9. PHP 优秀资源汇集(照搬)

    文章目录 原文地址: https://shockerli.net/post/php-awesome/ GitHub: https://github.com/shockerli/php-awesome ...

随机推荐

  1. 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E

    http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...

  2. jquery 高亮

    <ul> <li id="0">冬瓜很好吃</li> <li id="1">西瓜不好吃</li> & ...

  3. Array.length vs Array.prototype.length

    I found that both the Array Object and Array.prototype have the length property. I am confused on us ...

  4. OpenGL中shader读取实现

    1.需要shader在OpenGL中工作,必须经过如下过程 2.代码实现 /********** * loadshader.h **********/ #pragma once #define _CR ...

  5. LightOJ 1370 Bi-shoe and Phi-shoe 数论

    题目大意:f(x)=n 代表1-x中与x互质的数字的个数.给出n个数字a[i],要求f(x)=a[i],求x的和. 思路:每个素数x 有x-1个不大于x的互质数.则f(x)=a[i],若a[i]+1为 ...

  6. UVA 10759 Dice Throwing

    题意为抛n个骰子凑成的点数和大于或等于x的概率,刚开始用暴力枚举,虽然AC了,但时间为2.227s,然后百度了下别人的做法,交了一遍,靠,0.000s,然后看了下思路,原来是dp,在暴力的基础上记忆化 ...

  7. 在Javascript中使用protobuf与c++进行通信

    环境:Win7_64旗舰版,VS2013 最近在研究Webkit,已经编译成功,接下来就是Javascript与c++如何传输数据,立刻就想到了protobuf,但是谷歌不支持Javascript,百 ...

  8. HDU 2489 Minimal Ratio Tree (DFS枚举+最小生成树Prim)

    Minimal Ratio Tree Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. Android真机连接手机Target显示unknown cmd命令下adb devices 显示offline

    主要原因是adb版本的问题: 1.找到adb.exe路径  比如:G:\BaiduYunDownload\Android\android-sdk\platform-tools,将该路径放到环境便利-- ...

  10. Contest - 多校训练(985专场) Problem C: 985的方格难题

    题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1157&pid=2 Description 985走入了一个n * n的方格地图, ...