/** * Default constructor * * @throws ErrorNotFoundException * @return \Codersquad\Pennephp\Exception\Exception */ public function __construct() { if (!Collection::existsKey(self::$errorCodes, $this->errorCode)) { throw new ErrorNotFoundException(); } $errorMessage = []; $errorMessage[] = 'Error ' . $this->errorCode . ' occured: ' . self::$errorCodes[$this->errorCode]; $this->message = Collection::implode($errorMessage, '<br />'); }
/** * Replace marker * * @return void */ private function replace() { foreach ($this->replacementArray as $_key => $_value) { if (String::isValid($_value)) { $this->replaceString($_key, $_value); } elseif (Collection::isValid($_value)) { $this->replaceArray($_key, $_value); } elseif (Object::isValid($_value)) { $this->replaceObject($_key, $_value); } } $this->cleanup(); }
/** * @param $source * @return string */ public function addClass($source) { if (Collection::isNotEmpty($this->getClass())) { $source .= ' class="' . Collection::implode($this->getClass(), ' ') . '"'; return $source; } return $source; }
/** * Read content from file * * @param int $length Length of content to read * @param bool $asArray Get as array * * @return array|string|bool */ public function read($length = 0, $asArray = false) { if ($asArray && Number::isZero($length)) { return file($this->file); } elseif (Number::isPositive($length)) { $this->setHandle('r'); return fread($this->handle, $length); } else { return Collection::implode($this->read(0, true), ''); } }
/** * */ protected function generateRandomPassword() { $password = ''; for ($i = 0; $i < $this->numberOfPasswords; $i++) { for ($j = 0; $j < $this->passwordLength; $j++) { $password .= $this->charArray[rand(0, Collection::length($this->charArray) - 1)]; } } $this->passwords[] = $password; }
/** * */ public function testImplodeWithWrongDatatype() { $this->assertFalse(Collection::implode('abc', 'b')); }
/** * Load one or more data sets * * @param int|string $primaryValue The value for the primary key * * @return void */ public function load($primaryValue = null) { $model = $this->model; $query = []; /** @noinspection PhpUndefinedFieldInspection */ $query[] = 'SELECT * FROM ' . $model::TABLE; $query = $this->loadWithPrimaryKey($primaryValue, $model, $query); $dataCollection = $this->databaseObject->getInstance()->setQuery(Collection::implode($query, ''))->fetch(); if (Collection::length($dataCollection) === 1 || $primaryValue === null) { $this->loadSingleEntry($dataCollection, $model); } elseif (Collection::length($dataCollection) > 2) { $this->setProperties($dataCollection[0], $this); } }
/** * @param $className */ private static function createInstance($className) { if (!Collection::existsKey(self::$instances, $className)) { self::$instances[$className] = new $className(); } }