예제 #1
0
 /**
  * @param Account $creditor
  * @param $amount
  * @param Entity $owner
  * @param $due
  * @param $increasePerHour
  * @param bool $name
  * @param bool $creation
  * @param bool $originalAmount
  * @param bool $lastInterestUpdate
  */
 public function __construct(Account $creditor, $amount, $owner, $due, $increasePerHour, $name = false, $creation = false, $originalAmount = false, $lastInterestUpdate = false)
 {
     // setting defaults
     if (!$creditor->getName() instanceof Service and !$creditor->getEntity() instanceof PlayerEnt) {
         throw new \InvalidArgumentException("Loan must be provided by a player or a service");
     }
     if ($creation === false) {
         $creation = time();
     }
     if (!is_string($name)) {
         $name = sprintf("Loan from {$creditor->getUniqueName()}");
     }
     $oname = $name;
     for ($i = 2; $owner->getAccount($name) instanceof Account; $i++) {
         $name = "{$oname} ({$i})";
     }
     if (!is_numeric($originalAmount)) {
         $originalAmount = $amount;
     }
     if (!is_int($lastInterestUpdate)) {
         $lastInterestUpdate = time();
     }
     // saving fields
     $this->name = strtolower($name);
     $this->creditor = $creditor;
     $this->amount = $amount;
     $this->owner = $owner;
     $this->due = $due;
     $this->increasePerHour = $increasePerHour;
     $this->creation = $creation;
     $this->originalAmount = $originalAmount;
     $this->lastInterestUpdate = $lastInterestUpdate;
 }
 /**
  * @param \xecon\entity\Entity $entity
  * @return string
  */
 public function getPath($entity)
 {
     $path = str_replace(["<type>", "<name>"], [$entity->getAbsolutePrefix(), $entity->getName()], $this->path);
     @mkdir(dirname($path), 0777, true);
     return $path;
 }
예제 #3
0
 /**
  * @param Entity $entity
  */
 public function addEntity($entity)
 {
     $this->ents[strtolower($entity->getUniqueName())] = new \WeakRef($entity);
 }
예제 #4
0
 public function getUniqueName()
 {
     return implode("/", [$this->entity->getAbsolutePrefix(), $this->entity->getName(), $this->getName()]);
 }