1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
<?php
/**
* Copyright 2006-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd
* @package Db
*/
/**
* Encapsulation object for LOB values to be used in SQL statements to ensure
* proper quoting, escaping, retrieval, etc.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @category Horde
* @copyright 2006-2017 Horde LLC
* @license http://www.horde.org/licenses/bsd
* @package Db
* @property $value The binary value as a string. @since Horde_Db 2.1.0
* @property $stream The binary value as a stream. @since Horde_Db 2.4.0
*/
abstract class Horde_Db_Value_Lob implements Horde_Db_Value
{
/**
* Binary scalar value to be quoted
*
* @var string
*/
protected $_value;
/**
* Binary stream value to be quoted
*
* @var stream
*/
protected $_stream;
/**
* Constructor
*
* @param string|stream $binaryValue The binary value in a string or
* stream resource.
*/
public function __construct($binaryValue)
{
if (is_resource($binaryValue)) {
$this->stream = $binaryValue;
} else {
$this->value = $binaryValue;
}
}
/**
* Getter for $value and $stream properties.
*/
public function __get($name)
{
switch ($name) {
case 'value':
if (isset($this->_value)) {
return $this->_value;
}
if (isset($this->_stream)) {
rewind($this->_stream);
return stream_get_contents($this->_stream);
}
break;
case 'stream':
if (isset($this->_stream)) {
return $this->_stream;
}
if (isset($this->_value)) {
$stream = @fopen('php://temp', 'r+');
fwrite($stream, $this->_value);
rewind($stream);
return $stream;
}
break;
}
}
/**
* Setter for $value and $stream properties.
*/
public function __set($name, $value)
{
switch ($name) {
case 'value':
case 'stream':
$this->{'_' . $name} = $value;
break;
}
}
}
|