Example #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 />');
 }
Example #2
0
 /**
  * @param $source
  * @return string
  */
 public function addClass($source)
 {
     if (Collection::isNotEmpty($this->getClass())) {
         $source .= ' class="' . Collection::implode($this->getClass(), ' ') . '"';
         return $source;
     }
     return $source;
 }
Example #3
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), '');
     }
 }
 /**
  *
  */
 public function testImplodeWithWrongDatatype()
 {
     $this->assertFalse(Collection::implode('abc', 'b'));
 }
Example #5
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);
     }
 }