/** * @covers mychaelstyle\utils\File::base64encode * @covers mychaelstyle\utils\File::base64decode * @covers mychaelstyle\utils\File::base64 */ public function testEncode() { $expected = $this->example_text; $path = $this->org_example; $to = tempnam(DIR_TEST . '/tmp', 'encoded_'); $recover = tempnam(DIR_TEST . '/tmp', 'encoded_'); \mychaelstyle\utils\File::base64encode($path, $to); \mychaelstyle\utils\File::base64decode($to, $recover); $this->assertEquals($expected, file_get_contents($recover)); unlink($to); unlink($recover); }
/** * get contents from uri */ public function get($uri, $path = null) { $uri = $this->__formatUri($uri); $pdo = $this->connections[array_rand($this->connections)]; $sql = sprintf('SELECT %s FROM %s WHERE %s=:uri', $this->field_contents, $this->table, $this->field_uri); $statement = $pdo->prepare($sql); $statement->bindValue(':uri', $uri, \PDO::PARAM_STR); $statement->execute(); $result = $statement->fetch(\PDO::FETCH_ASSOC); $tmp = tempnam(sys_get_temp_dir(), 'tmp_mychaelstyle_storage_mysql_'); if (file_put_contents($tmp, $result['contents'])) { if (is_null($path)) { $decodedPath = tempnam(sys_get_temp_dir(), 'tmp_mychaelstyle_storage_mysql_'); \mychaelstyle\utils\File::base64decode($tmp, $decodedPath); $ret = file_get_contents($decodedPath); @unlink($tmp); @unlink($decodedPath); return $ret; } else { \mychaelstyle\utils\File::base64decode($tmp, $path); @unlink($tmp); return true; } } throw new \mychaelstyle\Exception('File storage provider mysql: fail to open temporary file!' . $tmp, 0); }