germania-kg/websites

4.2.2 2022-03-30 09:47 UTC

README

*此包是从旧代码中提取出来的,已弃用。
最好不要在生产中使用此包。

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

升级说明

从v2升级

数据库:有一个新的字段 route_name。请参阅 sql/install.sql.txt 了解如何创建或添加字段。

PdoAllWebsitesPdoRouteWebsiteFactory:现在必须将页面表名传递给构造函数。

从v1升级

有两个新的数据库字段 javascriptsstylesheets。请参阅 sql/install.sql.txt 了解如何创建或添加字段。

根据这一点,接口 WebsiteInterface 规定了两个方法 getJavascriptsgetStylesheets,其实现类 Website 还引入了 setJavascriptssetStylesheets

使用Composer安装

$ composer require germania-kg/websites

MySQL:在数据库操作中,使用 sql/install.sql.txt 中的 CREATE TABLE 语句创建您的表。

所有网站

接口 WebsitesInterface 扩展了 IteratorAggregate, Countable 和 PSR-11 的 ContainerInterface。

Websites 实现了 WebsitesInterface,因此可以迭代并“计数”。PdoAllWebsites 类是一个扩展,它从 MySQL 表中读取。

<?php
use Germania\Websites\PdoAllWebsites;
use Germania\Websites\Website;

// Instantiation
// - optional: Custom Website object template (extension of WebsiteAbstract)
$all_websites = new PdoAllWebsites( $pdo, "my_pages" );
$all_websites = new PdoAllWebsites( $pdo, "my_pages", new Website );


// Countable:
echo count($all_websites);

// Iterator:
foreach( $all_websites as $website):
	echo $website->getTitle(), PHP_EOL;
endforeach;

// ContainerInterface:
// Getting may throw WebsiteNotFoundException
// which implements Psr\Container\NotFoundExceptionInterface
$website_exists = $all_websites->has( 42 );
$website        = $all_websites->get( 42 );
?>

通过路由获取网站

<?php
use Germania\Websites\PdoRouteWebsiteFactory;
use Germania\Websites\WebsiteNotFoundException;
use Germania\Websites\Website;


// Instantiation
// - optional: Custom Website object template (extension of WebsiteAbstract)
$factory = new PdoRouteWebsiteFactory( $pdo, "my_pages" );
$factory = new PdoRouteWebsiteFactory( $pdo, "my_pages", new Website );
$factory = new PdoRouteWebsiteFactory( $pdo, "my_pages", null );

$route = "/index.html";

// interop ContainerInterface
$exists  = $factory->has( $route );

try// Callable or ContainerInterface's Getter
	$website = $factory( $route );
	$website = $factory->get( $route );
}
// Interop\Container\Exception\NotFoundException
catch (WebsiteNotFoundException $e) {
	// 404
}

问题

问题1:MySQL 5.7.5 在类 PdoWebsiteRoutesAcl 中使用的 SQL 查询存在 ONLY_FULL_GROUP_BY 问题。

请参阅 问题列表。

开发

$ git clone https://github.com/GermaniaKG/Websites.git
$ cd Websites
$ composer install

单元测试

您可以复制 phpunit.xml.distphpunit.xml 并根据需要进行调整,或者保持原样。运行 PhpUnit 测试或 composer 脚本,如下所示

$ composer test
# or
$ vendor/bin/phpunit