/**
  * 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;
 }
Beispiel #2
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;
 }
 /**
  * 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::isNumeric($offset, Number::NOT_NEGATIVE | Number::NOT_FLOAT)) {
         throw new DatabaseException('Provided offset is negative');
     }
     $this->offset = $offset;
 }
Beispiel #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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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::isNumeric($age, Number::NOT_NEGATIVE | Number::NOT_FLOAT)) {
         throw new ZiboException('Provided clean up age is negative');
     }
     $this->cleanUpAge = $age;
 }
 /**
  * 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;
 }
Beispiel #9
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::isNumeric($size, Number::NOT_NEGATIVE | Number::NOT_FLOAT)) {
         throw new FileSystemException('Invalid 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];
 }
Beispiel #10
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);
 }
 /**
  * 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]);
 }
 /**
  * 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);
 }
Beispiel #14
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;
 }
Beispiel #15
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;
 }
 /**
  * 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;
 }
Beispiel #17
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');
     }
 }
Beispiel #18
0
 /**
  * Sets the date the content was last modified
  * @param integer $timestamp Timestamp of the date
  * @return null
  */
 public function setLastModified($timestamp = null)
 {
     if ($timestamp === null) {
         $this->dateLastModified = null;
         $this->headers->removeHeader(Header::HEADER_LAST_MODIFIED);
         return;
     }
     if (!Number::isNumeric($timestamp, Number::NOT_NEGATIVE | Number::NOT_ZERO | Number::NOT_FLOAT)) {
         throw new ZiboException('Invalid date provided');
     }
     $this->dateLastModified = $timestamp;
     $this->headers->setHeader(Header::HEADER_LAST_MODIFIED, Header::parseTime($timestamp));
 }
 /**
  * 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;
 }
Beispiel #20
0
 /**
  * @dataProvider providerIsOctalThrowsExceptionWhenNoNumericValueIsPassed
  * @expectedException zibo\ZiboException
  */
 public function testIsOctalThrowsExceptionWhenNoNumericValueIsPassed($value)
 {
     Number::isOctal($value);
 }
Beispiel #21
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;
 }
Beispiel #22
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;
 }
 /**
  * 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);
         }
     }
 }
Beispiel #24
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;
 }
Beispiel #25
0
 /**
  * @dataProvider providerIsNumericOctal
  */
 public function testIsNumericOctal($expected, $value)
 {
     $result = Number::isNumeric($value, Number::OCTAL);
     $this->assertEquals($expected, $result);
 }
 /**
  * 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);
     // validate the weight value
     if ($weight === null) {
         $weight = $this->getNewWeight($event);
     } elseif (!Number::isNumeric($weight, Number::NOT_NEGATIVE) || $weight >= $this->maxEventListeners) {
         throw new ZiboException('Provided weight is invalid. Try a value between 0 and ' . $this->maxEventListeners);
     }
     // check the occupation
     if (isset($this->events[$event][$weight])) {
         throw new ZiboException('Weight ' . $weight . ' for event ' . $event . ' is already set with callback ' . $this->events[$event][$weight]);
     }
     // add it
     if (!isset($this->events[$event])) {
         $this->events[$event] = array();
     }
     $this->events[$event][$weight] = new Callback($callback);
     // resort the event listeners by weight
     ksort($this->events[$event]);
 }
Beispiel #27
0
 /**
  * Generates a random string
  * @param integer $length Number of characters to generate
  * @param string $haystack String with the haystack to pick characters from
  * @return string A random string
  * @throws zibo\ZiboException when an invalid length is provided
  * @throws zibo\ZiboException when an empty haystack is provided
  * @throws zibo\ZiboException when the requested length is greater then
  * the length of the haystack
  */
 public static function generate($length = 8, $haystack = null)
 {
     $string = '';
     if ($haystack == null) {
         $haystack = self::GENERATE_HAYSTACK;
     }
     if (!Number::isNumeric($length, Number::NOT_NEGATIVE | Number::NOT_ZERO | Number::NOT_FLOAT)) {
         throw new ZiboException('Could not generate a random string: invalid length provided');
     }
     if (!self::isString($haystack, self::NOT_EMPTY)) {
         throw new ZiboException('Could not generate a random string: empty or invalid haystack provided');
     }
     $haystackLength = strlen($haystack);
     if ($length > $haystackLength) {
         throw new ZiboException('Length cannot be greater than the length of the haystack. Length is ' . $length . ' and the length of the haystack is ' . $haystackLength);
     }
     $i = 0;
     while ($i < $length) {
         $char = substr($haystack, mt_rand(0, $haystackLength - 1), 1);
         if (!strstr($string, $char)) {
             $string .= $char;
             $i++;
         }
     }
     return $string;
 }
 /**
  * Checks if the provided octal permissions is a valid value
  * @param int $octalPermissions Octal permissions
  * @return null
  * @throws zibo\ZiboException when the provided permissions is not a valid octal permissions value
  */
 private function checkOctalPermissions($octalPermissions)
 {
     $lengthPermissions = strlen($octalPermissions);
     if ($lengthPermissions > 5) {
         throw new ZiboException('Provided permissions is not a valid octal permissions value: too much digits');
     }
     if (!Number::isOctal($octalPermissions)) {
         throw new ZiboException('Provided permissions is not a valid octal permissions value: not an octal value');
     }
 }