.

Binaries Class Reference
[Binaries]

Facade class for binaries. More...

List of all members.

Static Public Member Functions

static  create ($data, $name, $mime_type, &$created)
  Create a new binary instance.
static  create_from_file ($file, $name, $mime_type, &$created)
  Create a binary from a file.
static  create_from_post ($post_item, &$created)
  Create a binary from POST data.
static  get ($id)
  Returns binary with given ID.
static  is_upload ($data)
  Returns true if the data passed represents an upload.
static  read_content ($id)
  Returns content of binary with given ID.

Detailed Description

Facade class for binaries.

Author:
Gerd Riesselmann

Definition at line 8 of file binaries.facade.php.


Member Function Documentation

static Binaries::create ( data,
name,
mime_type,
&$  created  
) [static]

Create a new binary instance.

Parameters:
string  $data
string  $name
string  $mime_type
DAOBinaries  $created
Returns:
Status

Definition at line 59 of file binaries.facade.php.

00059                                                                            {
00060                 $ret = new Status();
00061                 $params = array(
00062                         'name' => $name,
00063                         'mimetype' => $mime_type,
00064                         'data' => $data
00065                 );
00066                 $cmd = CommandsFactory::create_command('binaries', 'create', $params);
00067                 $ret->merge($cmd->execute());
00068                 $created = $cmd->get_result();
00069                 return $ret; 
00070         }
static Binaries::create_from_file ( file,
name,
mime_type,
&$  created  
) [static]

Create a binary from a file.

Parameters:
string  $file File name to load from
string  $name Name for new binary
string  $mime_type Mime type. Leave empty for auto detection
DAOBinaries  $created The created instances
Returns:
Status

Definition at line 81 of file binaries.facade.php.

00081                                                                                      {
00082                 $ret = new Status();
00083                 if (file_exists($file)) {
00084                         if (empty($mime_type)) {
00085                                 $mime_type = 'application/octect-stream';
00086                                 if (function_exists('finfo_open')) {
00087                                         $handle = finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
00088                                         $mime_type = finfo_file($handle, $file);
00089                                         finfo_close($handle);
00090                                 }
00091                                 else if (function_exists('mime_content_type')) {
00092                                         $mime_type = mime_content_type($file);
00093                                 }
00094                         }
00095                         $ret->merge(self::create(file_get_contents($file), $name, $mime_type, $created));
00096                 }
00097                 else {
00098                         $ret->append(tr('File %f not found', 'binaries', array('%f' => $file)));
00099                 }
00100                 return $ret;
00101         }
static Binaries::create_from_post ( post_item,
&$  created  
) [static]

Create a binary from POST data.

POST date MUST! be retrieved from $page_data->get_post()

If no file was uploaded, an error gets returned

Parameters:
array  $post_item
DAOBinaries  $created
Returns:
Status

Definition at line 114 of file binaries.facade.php.

00114                                                                        {
00115                 $ret = new Status();
00116                 $i_err = Arr::get_item($post_item, 'error', UPLOAD_ERR_NO_FILE);
00117                 switch ($i_err) {
00118                         case UPLOAD_ERR_OK:
00119                                 $tmp_file = Arr::get_item($post_item, 'tmp_name', '');
00120                                 $org_file = Arr::get_item($post_item, 'name', '');
00121                                 $mime = Arr::get_item($post_item, 'type', '');
00122                                 $ret->merge(Binaries::create_from_file($tmp_file, $org_file, $mime, $created));
00123                                 break;          
00124                         case UPLOAD_ERR_NO_FILE:
00125                                 $ret->append(tr('No file was uploaded', 'binaries'));
00126                                 break;                          
00127                         case UPLOAD_ERR_INI_SIZE:
00128                         case UPLOAD_ERR_FORM_SIZE:
00129                                 $ret->append(tr('The uploaded file is too big', 'binaries'));
00130                                 break;
00131                         default:
00132                                 $ret->append(tr('An unknown error code was retrieved while uploading the file.', 'binaries'));
00133                                 break;
00134                 }
00135                 return $ret;
00136         }
static Binaries::get ( id  )  [static]

Returns binary with given ID.

Parameters:
int  $id
Returns:
DAOBinaries

Definition at line 15 of file binaries.facade.php.

00015                                         {
00016                 return DB::get_item('binaries', 'id', $id);     
00017         }
static Binaries::is_upload ( data  )  [static]

Returns true if the data passed represents an upload.

This is: The data is an array, and the error is not UPLOAD_ERR_NO_FILE

Parameters:
array  $data

Definition at line 42 of file binaries.facade.php.

00042                                                 {
00043                 $ret = false;
00044                 if (is_array($data)) {
00045                         $ret = (Arr::get_item($data, 'error', UPLOAD_ERR_NO_FILE) != UPLOAD_ERR_NO_FILE);
00046                 }
00047                 return $ret;
00048         }
static Binaries::read_content ( id  )  [static]

Returns content of binary with given ID.

Parameters:
int  $id
Returns:
string

Definition at line 25 of file binaries.facade.php.

00025                                                  {
00026                 $ret = '';
00027                 /* @var $b DAOBinaries */
00028                 $b = self::get($id);
00029                 if ($b) {
00030                         $ret = $b->data;
00031                 }
00032                 return $ret;
00033         }

The documentation for this class was generated from the following file: