fkr / simplepie-bundle
将SimplePie集成到Symfony中
v1.1.0
2022-10-09 05:36 UTC
Requires
- php: >=5.3.2
- simplepie/simplepie: ~1.3
- symfony/framework-bundle: ~2.6|~3.0|~4.0|~5.0|~6.0
README
将SimplePie RSS解析器集成到Symfony中,并设置缓存到symfony缓存文件夹。
安装
引入供应商库
这可以通过两种不同的方式完成
方法#1) 使用composer
"require": {
"fkr/simplepie-bundle": "1.0.*@dev"
}
方法#2) 使用deps文件
[SimplePie]
git=git://github.com/simplepie/simplepie.git
target=simplepie
[FkrSimplePieBundle]
git=git://github.com/fkrauthan/FkrSimplePieBundle.git
target=bundles/Fkr/SimplePieBundle
方法#3) 使用git子模块
git submodule add git://github.com/simplepie/simplepie.git vendor/simplepie
git submodule add git://github.com/fkrauthan/FkrSimplePieBundle.git vendor/bundles/Fkr/SimplePieBundle
注册SimplePie和Fkr命名空间
如果您使用composer安装,则此步骤不是必需的。
// app/autoload.php
$loader->registerNamespaces(array(
'Fkr' => __DIR__.'/../vendor/bundles',
// your other namespaces
));
$loader->registerPrefixes(array(
'SimplePie' => __DIR__.'/../vendor/simplepie/library',
// your other namespaces
));
将SimplePieBundle添加到您的应用程序内核中
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Fkr\SimplePieBundle\FkrSimplePieBundle(),
// ...
);
}
配置
# app/config.yml
fkr_simple_pie:
cache_enabled: false
cache_dir: %kernel.cache_dir%/rss
cache_duration: 3600
idna_converter: ~ #default is false
- cache_enabled: [true or false] 启用SimplePie类的缓存
- cache_dir: [任意目录] 设置SimplePie应使用的缓存目录
- cache_duration: [秒] 设置缓存时间为多少秒。
- idna_converter: [true or false] 启用idna转换器,这是一个国际化域名名称的编码/解码器
有关SimplePie缓存的更多信息,请访问SimplePie维基百科。
使用
要获取配置好的SimplePie类实例,请使用以下代码
$this->get('fkr_simple_pie.rss');
该服务只保留一个SimplePie实例。如果您想在应用程序中使用多个源,您必须使用clone
来复制实例以避免它们相互干扰
$one = clone $this->get('fkr_simple_pie.rss');
$two = clone $this->get('fkr_simple_pie.rss');
就这些。有关完整的API,请访问SimplePie API文档。