public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '') { $zip = new self(); $zip->open($zipFilename, $flags); $zip->addTree($dirname, $localname); $zip->close(); }
public static function createFromFile($file) { if (!file_exists($file)) { throw new \Exception('File not found.'); } $stream = new self(); $stream->open($file); $stream->alpha(); return $stream; }
public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '') { $zip = new self(); if (file_exists($zipFilename)) { unlink($zipFilename); } $zip->open($zipFilename, ZipArchive::CREATE); $zip->addTree($dirname, $localname); $zip->close(); }
/** * Creates a Database object, opens the connection and returns the instance. * * @param context TestSwarmContext * @param $connType int: [optional] */ public static function newFromContext(TestSwarmContext $context, $connType = SWARM_DBCON_DEFAULT) { $dbConf = $context->getConf()->database; $db = new self(); $db->context = $context; $db->host = $dbConf->host; $db->username = $dbConf->username; $db->password = $dbConf->password; $db->dbname = $dbConf->database; $db->open($connType); return $db; }
/** * Establish LDAP connection * * @static * @access public * @param string $username * @param string $password * @return Client */ public static function connect($username = null, $password = null) { $client = new self(); $client->open($client->getLdapServer()); $username = $username ?: $client->getLdapUsername(); $password = $password ?: $client->getLdapPassword(); if (empty($username) && empty($password)) { $client->useAnonymousAuthentication(); } else { $client->authenticate($username, $password); } return $client; }
/** * Adds sitemaps $aSitemaps to index $sFilename. If index doesn't exists it will be created. * * @param string $aSitemaps * @param string $sFilename * @param bool $bSaveCompressed */ public static function updateSitemapIndex($aSitemaps, $sFilename, $bSaveCompressed = true) { if (file_exists($sFilename)) { $oSitemapIndex = new self(); $oSitemapIndex->open($sFilename); } else { $oSitemapIndex = new self(); } $oSitemapIndex->addSitemaps($aSitemaps); if ($bSaveCompressed == true) { $oSitemapIndex->saveCompressed($sFilename); } else { $oSitemapIndex->saveUncompressed($sFilename); } }
/** * Creates a new empty zip file. * @param string $destination Path for the new zip * @param mixed $source * @return self */ public static function make($destination, $source) { $zip = new self(); $zip->open($destination, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE); if (is_string($source)) { $zip->add($source); } elseif (is_callable($source)) { $source($zip); } elseif (is_array($source)) { foreach ($source as $_source) { $zip->add($_source); } } $zip->close(); return $zip; }
public function send($data = null) { if ($this->ready_state !== 1) { self::throw_error('Invalid state; Cannot send unopened request', E_RECOVERABLE_ERROR); } // Build the data string if (!is_string($data) && $data !== null) { if (is_array($data)) { $data_arr = ''; foreach ($data as $name => $value) { $data_arr[] = urlencode($name) . ' = ' . urlencode($value); } $data = implode('&', $data_arr); } else { self::throw_error('Invalid data parameter given; Expects string, array, or NULL', E_RECOVERABLE_ERROR); } } // Build the request $request = $this->method . ' ' . $this->url_info['path'] . ' HTTP/1.1' . CRLF; $request .= 'Host: ' . $this->url_info['host'] . CRLF; foreach ($this->headers as $name => $value) { $request .= $name . ': ' . $value . CRLF; } $request .= CRLF . $data; // Send the request $response = ''; fputs($this->fh, $request); while (!feof($this->fh)) { $response .= fgets($this->fh, 128); } fclose($this->fh); // Seperate the response $response = explode(CRLF . CRLF, $response, 2); $headers = explode(CRLF, $response[0]); $this->response_body = $response[1]; // Parse the response status $http = array_shift($headers); preg_match('/^HTTP\\/[0-9.]+ ([0-9]{3}) (.*)$/', $http, $match); $this->status = (int) $match[1]; $this->status_text = $match[2]; // Parse the headers $parsed_headers = array(); foreach ($headers as $header) { $header = explode(': ', $header, 2); $parsed_headers[$header[0]] = $header[1]; } $this->response_headers = $parsed_headers; // Check for a location header if (isset($this->response_headers['Location'])) { $location = $this->response_headers; $sub_request = new self(); $sub_request->__is_redirect($this->redirect_stack); $sub_request->open($this->method, $location); if ($sub_request->error_code) { $this->error_code = $sub_request->error_code; return false; } foreach ($this->headers as $name => $value) { $sub_request->set_request_header($name, $value); } $sub_request->send($data); $this->response_text = $sub_request->response_text; $this->response_headers = $sub_request->get_all_response_headers(); $this->status_code = $sub_request->status_code; $this->status_text = $sub_request->status_text; } // All done $this->ready_state = 4; return $this; }
/** * * @param string $tmp_name path to file * @param string $type mime type * @return self * @throws Exception */ public static function createFromFile($tmp_name, $type) { $mime_type = ElggFile::detectMimeType($tmp_name, $type); if (false == in_array($mime_type, array("image/jpeg", "image/jpg"))) { register_error(elgg_echo("gallery_field:only_jpg")); return null; } $ext = "jpg"; $file = new self(); $thumb_file = new ElggFile(); $random_guid = self::genGUID(); $file->setFilename($random_guid . "." . $ext); $thumb_file->setFilename($random_guid . "_thumb." . $ext); $file->setMimeType($mime_type); $thumb_file->setMimeType($mime_type); $imgsizearray = getimagesize($tmp_name); if ($imgsizearray == false) { register_error("bad file"); return null; } $width = $imgsizearray[0]; $height = $imgsizearray[1]; $file->open("write"); $file->write(self::cropImage($tmp_name, $width, $height, 760, 580)); $file->close(); $file->access_id = 2; $thumb_file->open("write"); $thumb_file->write(self::cropImage($tmp_name, $width, $height, 200, 140)); $thumb_file->close(); $thumb_file->access_id = 2; $thumb_file->save(); $file->thumb_file_guid = $thumb_file->guid; $file->save(); return $file; }
/** * @param $name * @param Closure $builder * @return $this */ public function group($name, Closure $builder) { $instance = new self($this->presenter, $this->dataStore, $this->config); $instance->open($this->open->name)->bare(); $builder($instance); $instance->close(); $this->elements[$name ?: 'element-' . count($this->elements)] = $instance; return $this; }
/** * Creates new Image object from image file * * @param string $pathToFile Path to image file * @return self */ public static function fromFile($pathToFile) { $newImage = new self(); $newImage->open($pathToFile); return $newImage; }
/** * Returns an ArchiveInfo object for an embedded archive file with the contents * analyzed (initially without recursion). Calls to this method can also be * chained together to navigate the tree, e.g.: * * $rar->getArchive('parent.rar')->getArchive('child.zip')->getFileList(); * * @param string $filename the embedded archive filename * @return ArchiveInfo|boolean false if an object can't be returned */ public function getArchive($filename) { if (!$this->reader || !$this->allowsRecursion()) { return false; } // Check the cache first if (isset($this->archives[$filename])) { return $this->archives[$filename]; } foreach ($this->reader->getFileList(true) as $file) { if ($file['name'] == $filename && isset($file['range'])) { // Create the new archive object $archive = new self(); $archive->externalClients = $this->externalClients; $archive->extensions = $this->extensions; if ($this->inheritReaders) { $archive->setReaders($this->readers, true); } // Extract any compressed data to a temporary file if supported if ($this->canExtract() && !empty($file['compressed']) && empty($file['pass'])) { list($hash, $temp) = $this->getTempFileName("{$file['name']}:{$file['range']}"); if (!isset($this->tempFiles[$hash])) { $this->reader->extractFile($file['name'], $temp); @chmod($temp, 0777); $this->tempFiles[$hash] = $temp; } if ($this->reader->error) { $archive->error = $this->reader->error; $archive->readers = array(); } else { $archive->open($temp, $this->isFragment); $archive->isTemporary = true; } return $archive; } // Otherwise we shouldn't process any files that are unreadable if (!empty($file['compressed']) || !empty($file['pass'])) { $archive->readers = array(); } // Try to parse the raw source file/data $range = explode('-', $file['range']); if ($this->file) { $archive->open($this->file, $this->isFragment, $range); } else { $archive->setData($this->data, $this->isFragment, $range); } // Make error messages more specific if (!empty($file['compressed'])) { $archive->error = 'The archive is compressed and cannot be read'; } if (!empty($file['pass']) || !empty($archive->isEncrypted)) { $archive->error = 'The archive is encrypted and cannot be read'; } return $archive; } } // Something went wrong return false; }
/** * Insertion rapide dans un fichier de log */ public static function log($file, $line) { $csv = new self(); $csv->open($file); $csv->addLine($line); }