本文整理汇总了PHP中Employee::recruit方法的典型用法代码示例。如果您正苦于以下问题:PHP Employee::recruit方法的具体用法?PHP Employee::recruit怎么用?PHP Employee::recruit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Employee
的用法示例。
在下文中一共展示了Employee::recruit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
abstract class Employee
{
protected $name;
private static $types = array('minion', 'cluedup', 'wellconnected');
static function recruit($name)
{
$num = rand(1, count(self::$types)) - 1;
$class = self::$types[$num];
return new $class($name);
}
function __construct($name)
{
$this->name = $name;
}
abstract function fire();
}
// new Employee class...
class WellConnected extends Employee
{
function fire()
{
print "{$this->name}: I'll call my dad\n";
}
}
$boss = new NastyBoss();
$boss->addEmployee(Employee::recruit("harry"));
$boss->addEmployee(Employee::recruit("bob"));
$boss->addEmployee(Employee::recruit("mary"));
$boss->projectFails();
$boss->projectFails();
$boss->projectFails();
示例2: fire
}
}
class WellConnected extends Employee
{
function fire()
{
print "{$this->name}: blablabla\n";
}
}
class NastyBoss
{
private $employees = array();
function addEmployee(Employee $employee)
{
$this->employees[] = $employee;
}
function projectFails()
{
if (count($this->employees) > 0) {
$emp = array_pop($this->employees);
$emp->fire();
}
}
}
$employee = new NastyBoss();
$employee->addEmployee(Employee::recruit('Slava'));
$employee->addEmployee(Employee::recruit('Lidia'));
$employee->addEmployee(Employee::recruit('Nestor'));
$employee->projectFails();
$employee->projectFails();
$employee->projectFails();
示例3: addEmployee
{
print "{$this->name}: убери со стола\n";
}
}
class NastyBoss
{
private $employees = [];
function addEmployee(Employee $employee)
{
$this->employees[] = $employee;
}
function projectFails()
{
if (count($this->employees) > 0) {
$emp = array_pop($this->employees);
$emp->fire();
}
}
}
class ClueUp extends Employee
{
function fire()
{
print "{$this->name}: вызови адвоката\n";
}
}
$boss = new NastyBoss();
$boss->addEmployee(Employee::recruit("Игорь"));
$boss->addEmployee(Employee::recruit("Владимир"));
$boss->addEmployee(Employee::recruit("Мария"));
示例4: NastyBoss
<?php
$boss = new NastyBoss();
$boss->addEmployee(Employee::recruit("Bob"));
$boss->addEmployee(Employee::recruit("Steve"));
$boss->addEmployee(Employee::recruit("Lisa"));
$boss->projectFails();
$boss->projectFails();
$boss->projectFails();
示例5: fire
}
}
class CluedUp extends Employee
{
function fire()
{
echo $this->name . ': вызови адвоката';
}
}
class NastyBoss
{
private $employees = [];
function addEmployee(Employee $employee)
{
$this->employees[] = $employee;
}
function projectFails()
{
if (count($this->employees) > 0) {
$emp = array_pop($this->employees);
$emp->fire();
}
}
}
$boss = new NastyBoss();
$boss->addEmployee(Employee::recruit('Игорь'));
$boss->addEmployee(Employee::recruit('Владимир'));
$boss->addEmployee(Employee::recruit('Мария'));
var_dump($boss);
$boss->projectFails();
var_dump($boss);