コード例 #1
0
ファイル: validators.php プロジェクト: bruensicke/radium
    }
    $fields = $options['field'];
    $result = $options['model']::find('first', compact('fields', 'conditions'));
    return (bool) empty($result);
}, 'status' => function ($value, $format, $options) {
    return (bool) $options['model']::status($value);
}, 'type' => function ($value, $format, $options) {
    return (bool) $options['model']::types($value);
}, 'md5' => function ($value, $format, $options) {
    return (bool) (strlen($value) === 32 && ctype_xdigit($value));
}, 'attachmentType' => function ($value, $type, $data) {
    if (!isset($data['attachment'])) {
        return true;
    }
    $mime = $data['attachment']['type'];
    $mimeTypes = Mime::types();
    foreach ($data['types'] as $each) {
        if (isset($mimeTypes[$each]) && in_array($mime, $mimeTypes[$each])) {
            return true;
        }
    }
    return false;
}, 'attachmentSize' => function ($value, $type, $data) {
    if (!isset($data['attachment'])) {
        return true;
    }
    $size = $data['attachment']['size'];
    if (is_string($data['size'])) {
        if (preg_match('/([0-9\\.]+) ?([a-z]*)/i', $data['size'], $matches)) {
            $number = $matches[1];
            $suffix = $matches[2];
コード例 #2
0
ファイル: Assets.php プロジェクト: bruensicke/radium
 /**
  * renders given asset
  *
  * @see radium\media\Mime
  * @param object $asset instance of current record
  * @param array $data additional data to be passed into render context
  * @param array $options additional options
  *        - `response`: returns prepared response, defaults to false
  *                      WARNING: will load whole file into RAM at once.
  *        - `download`: specify a filename and file will be offered as download
  *        - `stream`: directly stream contents out, defaults to true
  *        - `exit`: will exit process after streaming, defaults to true
  * @return object|void returns response or directly renders the asset
  */
 public function render($asset, $data = array(), array $options = array())
 {
     $defaults = array('download' => false, 'response' => false, 'stream' => true, 'exit' => true, 'size' => 51200);
     $options += $defaults;
     if ($options['response'] || !$options['stream']) {
         return new Response(array('headers' => array('Content-type' => $asset->mimetype), 'body' => $asset->file->getBytes()));
     }
     Mime::header($asset->extension, $options);
     $stream = $asset->file->getResource();
     while (!feof($stream)) {
         echo fread($stream, $options['size']);
     }
     if ($options['exit']) {
         exit;
     }
 }