carpehora / classifiablebehavior
ClassifiableBehavior 是一个 Propel 行为,允许在用户定义的范围内对资源进行标签化,类似于资源访问控制。
dev-master
2012-06-21 14:37 UTC
Requires
- php: >=5.2.4
- propel/propel1: >=1.6.4
This package is not auto-updated.
Last update: 2020-01-01 18:03:27 UTC
README
快速开始
只需声明可分类对象的行为了解过滤分类
<database name="propel"> <table name="repository"> <column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" /> <column name="name" type="VARCHAR" size="255" /> <behavior name="classifiable" /> </table> </database>
然后只需向您的对象添加分类即可
<?php // create your objects... $MyPhpRepo = new Repository(); $MyPhpRepo->setName('my php repository'); $MyPhpRepo->classify('visibility', 'public'); $MyPhpRepo->classify('language', 'php'); $MyPhpRepo->classify('language', 'js'); $MyPhpRepo->classify('license', 'MIT'); $MyJsRepo = new Repository(); $MyJsRepo->setName('my php repository'); $MyJsRepo->classify('language', 'js'); $MyJsRepo->classify('language', 'php'); // is now classified in js AND php $MyJsRepo->classify('license', 'GPL'); $MyJsRepo->disclose('language', 'js'); // now only classified in php // ...and then retrieve it RepositoryQuery::create() // filter for 'php' AND 'js' language, paranoid ->filterByClassified('language', array('php', 'js'), 'and', $paranoid = true) // filter for 'MIT'OR 'GPL' license, paranoid ->filterByClassified('license', array('MIT', 'BSD'), 'or', $paranoid = true) // filter for public visibility, // default is public, so request match if no visibility defined ->filterByClassified('visibility', 'public', null, $paranoid = false);
前面的示例将返回一个包含 $MyPhpRepo 的 PropelCollection
通过提供一个数组和子查询要使用的运算符,可以轻松地执行 OR 搜索
<?php RepositoryQuery::create() // filter by OR queries ->filterByClassified(array( 'license' => array('MIT', 'BSD'), // licensed under MIT AND BSD as defined $operator argument 'visibility' => 'public', // or with public visibility ), $operator = 'AND', $paranoid = true)
要检索与对象关联的分类,只需调用 getClassification 方法
<?php $myRepo->classify(array( 'license' => array('MIT', 'BSD'), 'visibility' => 'public' ), 'AND', $excludeUnclassified = true); // return $myRepo $myRepo->getClassification(); // array( // 'license' => array('MIT', 'BSD'), // 'visibility' => 'public' // ) $myRepo->isClassified(array( 'license' => array('MIT', 'BSD'), 'visibility' => 'public' ), 'AND', $excludeUnclassified = true); // return true $myRepo->disclose();
为了方便分类管理,行为使用一个唯一的分类表,该表共享所有分类内容。如果要使用单独的表,只需覆盖 classification_table 参数。
用法
您可以使用 ClassifiableBehavior
- 限制对分类内容的访问
- 组织集合并简化过滤
- 标记对象
- 在此处放置您的想法
安装
内部结构
行为创建一个交叉引用表,使用 EXISTS 语句来访问分类字典和过滤器。
高级配置
以下参数可用:
classification_table:用于处理分类的表。classification_column:要使用的分类列。scope_column:要使用的范围列。auto_create_classification:如果没有找到参数的分类,是否应该创建它?scope_default:逗号分隔的默认范围列表。scope_matching:如何匹配范围?- strict:命名空间必须严格相等
- nested:命名空间必须以相同的方式开始。分隔符由
nesting_separator定义 - none:不检查命名空间
nesting_separator:嵌套范围上要使用的分隔符
范围
范围可用于组织分类。您可以通过提供 nesting_separator 使用命名空间范围。在这种情况下,您可以将分类组织为文件和文件夹,并可以在所有范围后代上进行搜索。
范围可以是对象的外键。
待办事项
- AR 揭示方法
- 嵌套命名空间
- 索引分类表字段