定制 fsi/metadata 二次开发

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

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

fsi/metadata

最新稳定版本:0.9.3

Composer 安装命令:

composer require fsi/metadata

包简介

FSi Metadata Component is a library that provide some commonly used mechanisms to read configurations for classes from different sources like annotations, yaml or xml.

README 文档

README

Do not use this package, as it will not receive any updates and may be deleted in the future.

FSi Metadata Component Documentation

FSi Metadata Component is a library that provide some commonly used mechanisms to read configurations for classes from different sources like annotations, yaml or xml. At the moment only php files annotations are supported.

Setup and autoloading

We highly recommend to use autoloader generated by composer.phar

Adding reflection into composer.json

{
    ... 
    "require": {
        ... 
        "fsi/metadata": "0.9.*" 
        ...
    },
    ...
}

Usage

FSi Metadata Component provides ClassMetadata object that can be easly overwritten. Default ClassMetadata object allows you to strore inside of it configuration for class, properties and methods. This can be done by using methods "addClassMetadata", "addPropertyMetadata", "addMethodMetadata".

What you need to do is to create class that extends from one of abstract drivers like AbstractAnnotationDriver.

Example of reading annotations from php class files.

Annotation driver

namespace FSi\Bundle\SiteBundle\Metadata\Driver;

use FSi\Component\Metadata\ClassMetadataInterface;
use FSi\Component\Metadata\Driver\AbstractAnnotationDriver;

class AnnotationDriver extends AbstractAnnotationDriver
{
    public function loadClassMetadata(ClassMetadataInterface $metadata)
    {
        $classReflection  = $metadata->getClassReflection();
        $className        = $classReflection->getName();

        $classReflectionProperties = $classReflection->getProperties();
        foreach ($classReflectionProperties as $property) {
            if ($property->getDeclaringClass()->getName() == $className) {
                foreach ($this->getAnnotationReader()->getPropertyAnnotations($property) as $element) {
                    $metadata->addPropertyMetadata($property->name, $element->name, $element->value);
                }
            }
        }
    }
}

Annotation declaration

namespace FSi\Bundle\SiteBundle\Metadata\Mapping\Annotation;

use Doctrine\Common\Annotations\Annotation;

/** @Annotation */
final class Field extends Annotation {
    public $name;
    public $value;
}

Example action in symfony 2 controller

    public function metadataAction()
    {
        $driver = new \FSi\Bundle\SiteBundle\Metadata\Driver\AnnotationDriver($this->get('annotation_reader'));
        
        $factory = new MetadataFactory($driver);
        
        $metdata = $factory->getClassMetadata('FSi\Bundle\SiteBundle\Entity\MetaTest');
    }

Example action in symfony 2 controller (with cache)

All you need to do to implement caching metadata is create the cache object from Doctrine\Common\Cache and pass it into MetadataFactory constructor. For development purposes we suggest to use ArrayCache instead of not using any cache.

public function metadataAction()
{
    $cache = new Doctrine\Common\Cache\ApcCache(); 
    
    $driver = new \FSi\Bundle\SiteBundle\Metadata\Driver\AnnotationDriver($this->get('annotation_reader'));
    
    // the third parameter should be used when one cache instance will be used in many metadata factories. 
    $factory = new MetadataFactory($driver, $cache, 'cache-prefix');
    
    $metdata = $factory->getClassMetadata('FSi\Bundle\SiteBundle\Entity\MetaTest');
}

Sometimes default ClassMetadata is not enough. You can create own class that implements ClassMetadataInterface and pass class name into MetadataFactory constructor as third parameter.

Factory constructor example with custom metadata class

$factory = new MetadataFactory($driver, $cache, 'cache-namespace', 'FSi\SiteBundle\Metadata\MyClassMetadata');

If you want to use Metadata Component in two separate mechanisms, inside of the same application you should create new MetatadaFactory and appropriate driver in each mechanism but cache driver may be the same object each time. It is possible when cache mechanism is used with different prefix and/or metadata class for each factory object.

fsi/metadata 适用场景与选型建议

fsi/metadata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.91k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2012 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「metadata」 「annotation」 「component」 「fsi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fsi/metadata 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fsi/metadata 我们能提供哪些服务?
定制开发 / 二次开发

基于 fsi/metadata 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 7
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-10-03