Exemple #1
0
 /**
  *
  * @throws \InvalidArgumentException
  * @throws \ErrorException
  * @return bool
  */
 private function uploadFile()
 {
     // If upload path not specified InvalidArgumentException will throw.
     if (!(isset($this->_fileRequirements['params']['upload_path']) && !empty($this->_fileRequirements['params']['upload_path']))) {
         throw new \InvalidArgumentException('Upload path required');
     }
     $pathArray = array();
     show($this->_fileRequirements);
     if (isset($this->_fileRequirements['file']['name'])) {
         $pathArray = pathinfo($this->_fileRequirements['file']['name']);
     }
     if (isset($pathArray['extension'])) {
         // If invalid file uploaded InvalidArgumentException will throw.
         /** @var $this TYPE_NAME */
         if (in_array(strtolower($pathArray['extension']), $this->_fileRequirements['ext']) === false) {
             throw new \InvalidArgumentException("<span style='color: #D8000C;' >\n                Invalid file upload: Following formats only allowed\n                " . implode(',', $this->_fileRequirements['ext']) . "</span>");
         }
     }
     exit;
     if (isset($this->_fileRequirements['file']['size']) && $this->_fileRequirements['file']['size'] <= $this->getNumericfileSize($this->_fileRequirements['size'])) {
         $path = getcwd() . $this->_fileRequirements['params']['upload_path'] . '/' . $this->_fileRequirements['file']['name'];
         if (move_uploaded_file($this->_fileRequirements['file']['tmp_name'], $path) === true) {
             return true;
         } else {
             // If file was not uploaded successfully  ErrorException will throw.
             throw new \ErrorException('<span style="color: #00B050;">
                 ' . $this->_fileRequirements["file"]["name"] . '
                 was not uploaded successfully</span>');
         }
     } else {
         // If file size was too large  OutofRange exception will throw.
         throw \OutOfRangeException('<span style="color: #D8000C;" >
             ' . $this->_fileRequirements['file']['name'] . '
             was too large exceeds upload limit
             ' . $this->_fileRequirements['size'] . '
             </span>');
     }
     //end if
 }
 /**
  * ArrayAccess: unset the item at the specified offset
  *
  * @param  mixed $index
  * @return void
  * @throws OutOfRangeException
  */
 public function offsetUnset($index)
 {
     if (!$this->offsetExists($index)) {
         throw OutOfRangeException(sprintf('Invalid index ("%s") specified', $index));
     }
     unset($this->data[$index]);
     $this->stack = false;
     $this->count--;
 }
Exemple #3
0
 public function setPage($int)
 {
     $int = (int) $int;
     if ($int < 1) {
         throw \OutOfRangeException('Argument must be a positive integer');
     }
     $this->page = $int;
     return $this;
 }