本文整理汇总了PHP中Helper::checkType方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::checkType方法的具体用法?PHP Helper::checkType怎么用?PHP Helper::checkType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper
的用法示例。
在下文中一共展示了Helper::checkType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Colony
public function Colony($value = "")
{
if (empty($value)) {
return $this->_colony;
} else {
Helper::checkType($this, $value, "Colony");
$this->_colony =& $value;
}
}
示例2: Target
public function Target($value = "")
{
if (empty($value)) {
return $this->_target;
} else {
Helper::checkType($this, $value, "Coordinates");
$this->_target =& $value;
}
}
示例3: Defender
public function Defender($value = "")
{
if (empty($value)) {
return $this->_defender;
} else {
Helper::checkType($this, $value, "Fleet");
$this->_defender =& $value;
}
}
示例4: Owner
public function Owner($value = "")
{
if (empty($value)) {
return $this->_owner;
} else {
Helper::checkType($this, $value, "User");
$this->_owner =& $value;
}
}
示例5: AddToDatabase
public static function AddToDatabase($u, $plainPassword)
{
Helper::checkType(get_called_class(), $u, "User");
// Generate a 50-character random salt and salt the plain password with it
$random_salt_value = substr(md5(uniqid(mt_rand(), true)), 0, 50);
$hashedPassword = sha1($random_salt_value . $plainPassword);
$query = "INSERT INTO user ";
$query .= "(username, password, randomsalt, authorisationID, primary_email, secondary_email, ";
$query .= "registration_time, last_online, is_banned, banned_until) ";
$query .= "VALUES('" . $u->Username() . "', '" . $hashedPassword . "', '" . $random_salt_value . "', " . $u->AuthorisationLevel();
$query .= ", '" . $u->PrimaryEmail() . "', '" . $u->SecondaryEmail() . "', " . $u->RegistrationTime() . ", " . $u->LastOnline();
$query .= ", " . $u->IsBanned() . ", " . $u->BannedUntil() . ");";
return Database::Instance()->ExecuteQuery($query, "INSERT");
}
示例6: UpdateDatabase
public function UpdateDatabase()
{
$colonyID = $this->Colony()->ID();
$query = "";
// Iterate over the build list
foreach ($this->Members() as $item) {
// Check if we're getting a correct object
Helper::checkType($this, $item, "BuildItem");
if ($item->Amount() < 1) {
$this->DeleteItemFromDatabase($item);
continue;
}
$newPositionInList = $item->PositionInList();
$oldPositionInList = $item->OldPositionInList();
$itemID = $item->ID();
$level = $item->Level();
$query .= "UPDATE production_building SET build_list_position = {$newPositionInList}, level = {$level} ";
$query .= "WHERE colonyID = {$colonyID} AND resource_type_being_built = {$itemID} AND build_list_position = {$oldPositionInList};";
}
if ($query != "") {
// Lop off the last semicolon because otherwise you get an SQL error
$fixedQuery = substr($query, 0, strlen($query) - 1);
Database::Instance()->ExecuteQuery($fixedQuery, "MULTI");
}
}
示例7: UpdateDatabase
public function UpdateDatabase()
{
$colonyID = $this->BuildList()->Colony()->ID();
$query = "";
// We'll want to keep track of how many fields we'll use up
$usedFields = 0;
// Get current time
$currentTime = time();
// Iterate over the build list and only update the items that were changed
foreach ($this->BuildList()->Members() as $item) {
// Check if we're getting a correct object
Helper::checkType($this, $item, "BuildItem");
$itemName = $item->Name();
$amountRequested = $item->Amount();
// TODO: uncommented for testing purposes
if ($amountRequested === 0) {
$this->BuildList()->DeleteItemFromDatabase($item);
continue;
}
$usedFields += $amountRequested;
$newPositionInList = $item->PositionInList();
$oldPositionInList = $item->OldPositionInList();
$itemID = $item->ID();
$scheduledTime = $item->FirstBuildTime() + $currentTime;
$query .= "UPDATE production SET amount_requested = {$amountRequested}, build_list_position = {$newPositionInList}, scheduled_time = {$scheduledTime} ";
$query .= "WHERE colonyID = {$colonyID} AND resource_type_being_built = {$itemID} AND build_list_position = {$oldPositionInList};";
}
if ($query != "") {
// Lop off the last semicolon because otherwise you get an SQL error
$fixedQuery = substr($query, 0, strlen($query) - 1);
Database::Instance()->ExecuteQuery($fixedQuery, "MULTI");
// Update UsedFields
$colonyUsedFields = $this->BuildList()->Colony()->UsedFields();
$this->BuildList()->Colony()->UsedFields($colonyUsedFields + $usedFields);
$itemsToBeUpdated = array("used_build_fields");
$this->BuildList()->Colony()->UpdateDatabaseProperties($itemsToBeUpdated);
}
}
示例8: DeductFromFleet
public function DeductFromFleet(ShipFleet $otherFleet)
{
Helper::checkType($this, $otherFleet, "ShipFleet");
$this->VerifySameColonyAndMission($otherFleet, true);
$newFleet = Helper::deductUnits($this->Members(), $otherFleet->Members());
$this->Members($newFleet);
if (Helper::containsNegative($newFleet)) {
// Should never ever happen
throw new Exception("Fleet contains negative units! (in ShipFleet::DeductFromFleet)");
}
}
示例9: AddToDatabase
public static function AddToDatabase(Colony $c)
{
// TODO: (not a real todo) VERY IMPORTANT: get_called_class ONLY WORKS ABOVE 5.3.0!!
Helper::checkType(get_called_class(), $c, "Colony");
// If this is a home colony, check if one already exists.
if ($c->HomeColony()) {
$ownerID = $c->Owner()->ID();
$query = "SELECT ID FROM colony WHERE userID = {$ownerID} AND is_home_colony = 1;";
$result = Database::Instance()->ExecuteQuery($query, "SELECT");
if ($result != NULL) {
throw new Exception("The user {$ownerID} already has a home colony!");
}
}
// Insert a row in the colony table
$query = "INSERT INTO colony ";
$query .= "(name, userID, is_home_colony, is_moon, galaxy_position, system_position, planet_position, last_updated) ";
$query .= "VALUES ('" . $c->Name() . "', " . $c->Owner()->ID() . ", " . $c->HomeColony() . ", " . $c->IsMoon() . ", " . $c->Coordinates()->Galaxy() . ", " . $c->Coordinates()->System() . ", " . $c->Coordinates()->Planet() . ", " . $c->LastUpdated() . ");";
$colonyID = Database::Instance()->ExecuteQuery($query, "INSERT");
$c->ID($colonyID);
// Prepare rows in the other colony tables
// colony_defences
$query = "INSERT INTO colony_defences VALUES( {$colonyID}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );";
Database::Instance()->ExecuteQuery($query, "INSERT");
// colony_properties
$query = "INSERT INTO colony_properties VALUES( {$colonyID}, 0, " . $c->MaxFields() . ", " . $c->UsedFields() . ", " . $c->PlanetData()->MinTemperature() . ", ";
$query .= $c->PlanetData()->GenerateMaxTemperature() . ", '" . $c->PlanetData()->GroundType() . "', '" . $c->PlanetData()->Image() . "', ";
$query .= $c->Diameter() . ", 0, " . $c->PlanetType()->ID() . ")";
Database::Instance()->ExecuteQuery($query, "INSERT");
// colony_resources
$query = "INSERT INTO colony_resources VALUES( {$colonyID}, " . $c->CurrentResources()->Metal() . ", 0, " . $c->MetalStorage();
$query .= ", " . $c->CurrentResources()->Crystal() . ", 0, " . $c->CrystalStorage();
$query .= ", " . $c->CurrentResources()->Deuterium() . ", 0, " . $c->DeuteriumStorage();
$query .= ", " . $c->CurrentResources()->Energy() . ", " . $c->CurrentResources()->Energy();
$query .= ", 0, 0, 0, 0, 0, 0 );";
Database::Instance()->ExecuteQuery($query, "INSERT");
// fleet table
$c->Fleet()->AddToDatabase();
// colony_structures
$query = "INSERT INTO colony_structures VALUES( {$colonyID}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );";
Database::Instance()->ExecuteQuery($query, "INSERT");
// Update Colony object
$c->ID($colonyID);
return $colonyID;
}