Example #1
0
 /**
  * Returns a list of files given the path and optionally the pattern
  *
  * @param string|null regular expression
  * @param             bool
  *
  * @return array
  */
 public function getFiles($regex = null, $recursive = false)
 {
     //argument test
     Argument::i()->test(1, 'string', 'null')->test(2, 'bool');
     $this->absolute();
     $files = array();
     if ($handle = opendir($this->data)) {
         //for each file
         while (false !== ($file = readdir($handle))) {
             // If this is infact a file
             if (filetype($this->data . '/' . $file) == 'file' && (!$regex || preg_match($regex, $file))) {
                 //add it
                 $files[] = File::i($this->data . '/' . $file);
                 // recursive and this is infact a directory
             } else {
                 if ($recursive && $file != '.' && $file != '..' && filetype($this->data . '/' . $file) == 'dir') {
                     $subfiles = self::i($this->data . '/' . $file);
                     $files = array_merge($files, $subfiles->getFiles($regex, $recursive));
                 }
             }
         }
         closedir($handle);
     }
     return $files;
 }
Example #2
0
 /**
  * Adds the attachment string body
  * for plain text emails
  *
  * @param *array $body The body types
  *
  * @return array
  */
 protected function addAttachmentBody(array $body)
 {
     foreach ($this->attachments as $attachment) {
         list($name, $data, $mime) = $attachment;
         $mime = $mime ? $mime : File::i($name)->getMime();
         $data = base64_encode($data);
         $count = ceil(strlen($data) / 998);
         $body[] = '--' . $this->boundary[1];
         $body[] = 'Content-type: ' . $mime . '; name="' . $name . '"';
         $body[] = 'Content-disposition: attachment; filename="' . $name . '"';
         $body[] = 'Content-transfer-encoding: base64';
         $body[] = null;
         for ($i = 0; $i < $count; $i++) {
             $body[] = substr($data, $i * 998, 998);
         }
         $body[] = null;
         $body[] = null;
     }
     $body[] = '--' . $this->boundary[1] . '--';
     return $body;
 }
Example #3
0
 /**
  * Returns the file class
  *
  * @param string
  *
  * @return Eden\System\File
  */
 public function file($path)
 {
     //argument 1 must be a string
     Argument::i()->test(1, 'string');
     return File::i($path);
 }