php-extended/php-vote-citizen

此包已被放弃,不再维护。作者建议使用php-extended/php-vote-object包代替。

所有php提供的基本变量类型的标准市民

3.1.16 2021-06-25 10:08 UTC

README

所有php提供的基本变量类型的标准市民

coverage build status

安装

此库的安装通过composer进行。从他们的网站下载composer.phar。然后将其添加到您的composer.json文件中

	"require": {
		...
		"php-extended/php-vote-citizen": "^3",
		...
	}

然后运行php composer.phar update来安装此库。此库中所有类的自动加载都通过composer的自动加载器完成。

基本用法

此库提供了一组标准市民列表,它们将以预定的行为进行投票。它们在选举中使用很有用


use PhpExtended\Vote\ElectionRunner;
use PhpExtended\Vote\InvalidCandidateException;
use PhpExtended\Vote\InvalidVoteException;
use PhpExtended\Vote\UnsolvableSituationException;
use PhpExtended\Vote\UniqueStringEqualsCitizen;

$runner = new ElectionRunner();
$citizens = array();
foreach($yourObjectsThatProvideStrings as $yourObject)
{
	$id = $yourObject->__toString();	// or anything else that may be useful for an id
	$citizens[] = new UniqueStringEqualsCitizen($id, $yourObject->yourMethodThatReturnsString());
}

try
{
	$runner->runElection($method, new ArrayIterator(array()), new ArrayIterator($citizens)); 
}
catch(InvalidCandidateException $ice)
{
	// TODO handle the fact that one candidate is refused
}
catch(InvalidVoteException $ive)
{
	// TODO handle the fact that one vote is refused
}
catch(UnsolvableSituationException $use)
{
	// TODO handle the fact that an ordering between the 
	// candidates could not be decided by the current voting
	// method and the votes that were given.
}

UniqueBooleanEqualsCitizen

此市民提出一个只带一个参数的候选人,该参数是布尔值。如果候选人只有一个布尔值参数,则此市民将所有候选人的排名定为100%,否则为0%。

UniqueFloatEqualsCitizen

此市民提出一个只带一个参数的候选人,该参数是浮点值。如果候选人只有一个浮点值参数,则此市民将所有候选人的排名定为100%,否则为0%。

UniqueIntegerEqualsCitizen

此市民提出一个只带一个参数的候选人,该参数是整数值。如果候选人只有一个整数值参数,则此市民将所有候选人的排名定为100%,否则为0%。

UniqueStringEqualsCitizen

此市民提出一个只带一个参数的候选人,该参数是字符串值。如果候选人只有一个字符串值参数,则此市民将所有候选人的排名定为100%,否则为0%。

许可证

MIT(见许可证文件)。