Exemplo n.º 1
0
 /**
  * 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 />');
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /**
  * @param $source
  * @return string
  */
 public function addClass($source)
 {
     if (Collection::isNotEmpty($this->getClass())) {
         $source .= ' class="' . Collection::implode($this->getClass(), ' ') . '"';
         return $source;
     }
     return $source;
 }
Exemplo n.º 4
0
 /**
  * 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), '');
     }
 }
Exemplo n.º 5
0
 /**
  *
  */
 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;
 }
Exemplo n.º 6
0
 /**
  *
  */
 public function testImplodeWithWrongDatatype()
 {
     $this->assertFalse(Collection::implode('abc', 'b'));
 }
Exemplo n.º 7
0
 /**
  * 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);
     }
 }
Exemplo n.º 8
0
 /**
  * @param $className
  */
 private static function createInstance($className)
 {
     if (!Collection::existsKey(self::$instances, $className)) {
         self::$instances[$className] = new $className();
     }
 }