Exemplo n.º 1
0
 /**
  * Set the offset of this limit clause
  * @param int $offset
  * @return null
  * @throws zibo\ZiboException when $offset is not numeric
  * @throws zibo\library\database\exception\DatabaseException when $offset is negative
  */
 private function setOffset($offset = null)
 {
     if ($offset !== null && Number::isNegative($offset)) {
         throw new DatabaseException('Provided offset is negative');
     }
     $this->offset = $offset;
 }
Exemplo n.º 2
0
 /**
  * Sets the time in seconds before fetching and invoking the job
  * @param integer $sleepTime Time in seconds
  * @return null
  */
 public function setSleepTime($sleepTime)
 {
     if (Number::isNegative($sleepTime)) {
         throw new ZiboException('Could not set the sleep time of the queue worker: invalid sleep time provided');
     }
     $this->sleepTime = $sleepTime;
 }
Exemplo n.º 3
0
 /**
  * Sets the port of this connection
  * @param integer $port The port of this connection
  * @return null
  * @throws zibo\library\network\exception\ConnectionException when the port is invalid
  */
 protected function setPort($port)
 {
     if (Number::isNegative($port)) {
         throw new ConnectionException('Could not set the port: invalid port provided');
     }
     $this->port = $port;
 }
Exemplo n.º 4
0
 /**
  * Sets the allowed maximum size
  * @param integer $maximum
  * @return null
  */
 public function setMaximum($maximum)
 {
     if (Number::isNegative($maximum)) {
         throw new ZiboException('Provided maximum cannot be negative');
     }
     $this->maximum = $maximum;
 }
Exemplo n.º 5
0
 /**
  * Constructs a new percent decorator
  * @param string $fieldName field name for objects or arrays passed to this decorator (optional)
  * @param integer $precision Number of decimal digits to round to
  * @return null
  * @throws zibo\ZiboException when the precision is not a number or smaller then 0
  */
 public function __construct($fieldName = null, $precision = 0)
 {
     parent::__construct($fieldName);
     if (Number::isNegative($precision)) {
         throw new ZiboException('Provided precision cannot be smaller then 0');
     }
     $this->precision = $precision;
 }
Exemplo n.º 6
0
 /**
  * Sets how old a cache object may become before it's cleared.
  * @param int $age Number of seconds a cache object can exist before it's cleared. Set to null or 0 to skip age checking
  * @return null
  * @throws zibo\ZiboException when the provided age is invalid
  */
 public function setCleanUpAge($age)
 {
     if ($age === null || $age === 0) {
         $this->cleanUpAge = null;
         return;
     }
     if (Number::isNegative($age)) {
         throw new ZiboException('Provided clean up age is negative');
     }
     $this->cleanUpAge = $age;
 }
Exemplo n.º 7
0
 /**
  * Format a size in bytes into a more human readable byte unit
  * @param int $size size in bytes
  * @return int a size in Kb, Mb, ... depending on the size
  * @throws zibo\library\filesystem\exception\FileSystemException when the size is not a zero or a positive number
  */
 public static function formatSize($size)
 {
     if (Number::isNegative($size)) {
         throw new FileSystemException($size . ' is not a valid file size');
     }
     if ($size == 0) {
         return '0 bytes';
     }
     $fileSizeUnits = array(' bytes', ' Kb', ' Mb', ' Gb', ' Tb', ' Pb', ' Eb', ' Zb', ' Yb');
     $i = floor(log($size, 1024));
     return round($size / pow(1024, $i), 2) . $fileSizeUnits[$i];
 }
 /**
  * Get a thumbnail from the given image
  * @param Image image source image for the thumbnail
  * @param int width width to calculate the thumbnail's width
  * @param int height height to calculate the thumbnail's height
  * @return Image Image instance of the thumbnail
  */
 public function getThumbnail(Image $image, $thumbnailWidth, $thumbnailHeight)
 {
     if (Number::isNegative($thumbnailWidth)) {
         throw new ThumbnailException($thumbnailWidth . ' is an invalid width');
     }
     if (Number::isNegative($thumbnailHeight)) {
         throw new ThumbnailException($thumbnailHeight . ' is an invalid height');
     }
     if ($image->getWidth() <= $thumbnailWidth && $image->getHeight() <= $thumbnailHeight) {
         return $image;
     }
     return $this->createThumbnail($image, $thumbnailWidth, $thumbnailHeight);
 }
Exemplo n.º 9
0
 /**
  * Registers a new event listener
  * @param string $event Name of the event
  * @param string|array|zibo\library\Callback $callback Callback for the event listener
  * @param int $weight Weight for the new listener in the event listener list.
  *                    This will influence the order of the event listener calls.
  *                    An event with weight 1 will be called before an event with weight 10.
  * @return null
  * @throws zibo\ZiboException when the name of the event is empty or invalid
  * @throws zibo\ZiboException when the weight of the event listener is invalid or already set
  */
 public function registerEventListener($event, $callback, $weight = null)
 {
     $this->checkEventName($event);
     if (!array_key_exists($event, $this->events)) {
         $this->events[$event] = array();
     }
     if ($weight === null) {
         $weight = $this->getNewWeight($event);
     } elseif (Number::isNegative($weight) || $weight >= $this->maxEventListeners) {
         throw new ZiboException('Provided weight ' . $weight . ' is invalid. Try a value between 0 and ' . $this->maxEventListeners);
     }
     if (array_key_exists($weight, $this->events[$event])) {
         throw new ZiboException('Weight ' . $weight . ' for event ' . $event . ' is already set with callback ' . $this->events[$event][$weight]);
     }
     $this->events[$event][$weight] = new Callback($callback);
     ksort($this->events[$event]);
 }
Exemplo n.º 10
0
 /**
  * Sets the port where the server is listening
  * @param integer|null $port The port or null for the default port
  * @return null
  * @throws zibo\library\mail\exception\MailException when the provided port is invalid
  */
 public function setPort($port)
 {
     if ($port === null) {
         $this->port = null;
         return;
     }
     if (Number::isNegative($port)) {
         throw new MailException('Could not set the port: provided port is negative');
     }
     $this->port = $port;
 }
Exemplo n.º 11
0
 /**
  * Performs a search in a specific content type
  * @param string $type Name of the content type
  * @param string $query Query string to search with
  * @param int $numItems Number of items to return
  * @param int $page Page number of the result
  * @return ContentResult
  */
 public function searchContent($type, $query, $numItems, $page = 1)
 {
     if (String::isEmpty($type)) {
         throw new ZiboException('Provided type is empty');
     }
     if (!array_key_exists($type, $this->mappers)) {
         throw new ZiboException('No searchable mapper found for ' . $type);
     }
     if (Number::isNegative($numItems)) {
         throw new ZiboException('Provided numItems cannot be negative');
     }
     if (Number::isNegative($page)) {
         throw new ZiboException('Provided page cannot be negative');
     }
     $queryTokens = $this->getQueryTokens($query);
     $results = $this->mappers[$type]->searchGetResults($query, $queryTokens, $page, $numItems);
     $numResults = $this->mappers[$type]->searchCountResults($query, $queryTokens);
     return new ContentResult($results, $numResults);
 }
Exemplo n.º 12
0
 /**
  * Sets the limitation of the query
  * @param integer $count Number of rows to retrieve
  * @param integer $offset Offset of the result
  * @return null
  * @throws zibo\library\orm\exception\OrmException when the provided count or offset is invalid
  */
 public function setLimit($count, $offset = 0)
 {
     if (Number::isNegative($offset)) {
         throw new OrmException('Provided offset ' . $offset . ' should be a positive number');
     }
     $this->limitCount = $count;
     $this->limitOffset = $offset;
 }
Exemplo n.º 13
0
 /**
  * Create a new internal image resource with the given width and height
  * @param int width width of the new image resource
  * @param int height height of the new image resource
  * @return null
  */
 protected function createResource($width, $height)
 {
     if (Number::isNegative($width)) {
         throw new ImageException('Invalid width provided ' . $width);
     }
     if (Number::isNegative($height)) {
         throw new ImageException('Invalid height provided ' . $height);
     }
     $this->resource = @imageCreateTrueColor($width, $height);
     if ($this->resource === false) {
         $error = error_get_last();
         throw new ImageException('Could not create the image resource: ' . $error['message']);
     }
     $this->width = $width;
     $this->height = $height;
 }
Exemplo n.º 14
0
 /**
  * Sets the current page number
  * @param integer $page New page number
  * @return null
  */
 public function setPage($page)
 {
     if ($this->pageRows == null) {
         throw new ZiboException('No pagination set, use setRowsPerPage first');
     }
     if (Number::isNegative($page)) {
         throw new ZiboException('Provided page number is not a positive number');
     }
     $this->page = $page;
 }
Exemplo n.º 15
0
 /**
  * Set the size of the text
  * @param int $size text size
  * @return null
  */
 public function setTextSize($size)
 {
     if (Number::isNegative($size)) {
         throw new ZiboException('Invalid text size provided, text size should be a positive numeric value');
     }
     $this->textSize = $size;
 }
Exemplo n.º 16
0
 /**
  * Set the limit in kb before the log file gets truncate
  * @param integer size limit in kilobytes
  */
 public function setFileTruncateSize($size)
 {
     if (Number::isNegative($size)) {
         throw new ZiboException($size . ' should be positive or zero');
     }
     $this->fileTruncateSize = $size;
 }
Exemplo n.º 17
0
 /**
  * Sets the height for this video
  * @param integer $height Height of the video in pixels
  * @return null
  */
 public function setHeight($height)
 {
     if (Number::isNegative($height)) {
         throw new ZiboException('Provided height is invalid');
     }
     $this->height = $height;
 }
Exemplo n.º 18
0
 /**
  * @dataProvider providerIsNegativeThrowsExceptionWhenNoNumericValueIsPassed
  * @expectedException zibo\ZiboException
  */
 public function testIsNegativeThrowsExceptionWhenNoNumericValueIsPassed($value)
 {
     Number::isNegative($value);
 }
Exemplo n.º 19
0
 /**
  * Construct a new image validator
  * @param array $options options for this validator
  * @return null
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     $this->isRequired = false;
     if (array_key_exists(self::OPTION_REQUIRED, $options)) {
         $this->isRequired = $options[self::OPTION_REQUIRED];
     }
     $this->minHeight = null;
     if (array_key_exists(self::OPTION_HEIGHT_MIN, $options)) {
         $this->minHeight = $options[self::OPTION_HEIGHT_MIN];
         if ($this->minHeight != '0' && Number::isNegative($this->minHeight)) {
             throw new ZiboException('Provided minimum height is invalid: ' . $this->minHeight);
         }
     }
     $this->minWidth = null;
     if (array_key_exists(self::OPTION_WIDTH_MIN, $options)) {
         $this->minWidth = $options[self::OPTION_WIDTH_MIN];
         if ($this->minWidth != '0' && Number::isNegative($this->minWidth)) {
             throw new ZiboException('Provided maximum width is invalid: ' . $this->minWidth);
         }
     }
     $this->maxHeight = null;
     if (array_key_exists(self::OPTION_HEIGHT_MAX, $options)) {
         $this->maxHeight = $options[self::OPTION_HEIGHT_MAX];
         if ($this->maxHeight != '0' && Number::isNegative($this->maxHeight)) {
             throw new ZiboException('Provided maximum height is invalid: ' . $this->maxHeight);
         }
     }
     $this->maxWidth = null;
     if (array_key_exists(self::OPTION_WIDTH_MAX, $options)) {
         $this->maxWidth = $options[self::OPTION_WIDTH_MAX];
         if ($this->maxWidth != '0' && Number::isNegative($this->maxWidth)) {
             throw new ZiboException('Provided maximum width is invalid: ' . $this->maxWidth);
         }
     }
 }
Exemplo n.º 20
0
 /**
  * Checks the dimensions
  * @param mixed $width The new width
  * @param mixed $height The new height
  * @return null
  * @throws zibo\ZiboException when the provided dimension is not valid
  */
 private function checkDimension($width, $height)
 {
     if (Number::isNegative($width)) {
         throw new ZiboException('Could not set the dimensions: provided width is negative');
     }
     if ($width > 1000) {
         throw new ZiboException('Could not set the dimensions: provided width exceeds 1000px');
     }
     if (Number::isNegative($height)) {
         throw new ZiboException('Could not set the dimensions: provided height is negative');
     }
     if ($height > 1000) {
         throw new ZiboException('Could not set the dimensions: provided height exceeds 1000px');
     }
     if ($width * $height > 300000) {
         throw new ZiboException('Could not set the dimensions: width multiplied with the height cannot exceed 300.000');
     }
 }