本文整理汇总了PHP中File::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getContent方法的具体用法?PHP File::getContent怎么用?PHP File::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toHtml
/**
* Converts the code to HTML
*
* @param File $file File to render
* @param Tool_Result $res Tool result to integrate
*
* @return string HTML
*/
public function toHtml(File $file, Tool_Result $res = null)
{
if (class_exists('\\Michelf\\Markdown', true)) {
//composer-installed version 1.4+
$markdown = \Michelf\Markdown::defaultTransform($file->getContent());
} else {
//PEAR-installed version 1.0.2 has a different API
require_once 'markdown.php';
$markdown = \markdown($file->getContent());
}
return '<div class="markdown">' . $markdown . '</div>';
}
示例2: executeResizeSvg
/**
* Resize an SVG image
*/
protected function executeResizeSvg()
{
$doc = new \DOMDocument();
if ($this->fileObj->extension == 'svgz') {
$doc->loadXML(gzdecode($this->fileObj->getContent()));
} else {
$doc->loadXML($this->fileObj->getContent());
}
$svgElement = $doc->documentElement;
// Set the viewBox attribute from the original dimensions
if (!$svgElement->hasAttribute('viewBox')) {
$origWidth = $svgElement->getAttribute('width');
$origHeight = $svgElement->getAttribute('height');
$svgElement->setAttribute('viewBox', '0 0 ' . floatval($origWidth) . ' ' . floatval($origHeight));
}
$coordinates = $this->computeResize();
$svgElement->setAttribute('x', $coordinates['target_x']);
$svgElement->setAttribute('y', $coordinates['target_y']);
$svgElement->setAttribute('width', $coordinates['target_width']);
$svgElement->setAttribute('height', $coordinates['target_height']);
$svgWrapElement = $doc->createElementNS('http://www.w3.org/2000/svg', 'svg');
$svgWrapElement->setAttribute('version', '1.1');
$svgWrapElement->setAttribute('width', $coordinates['width']);
$svgWrapElement->setAttribute('height', $coordinates['height']);
$svgWrapElement->appendChild($svgElement);
$doc->appendChild($svgWrapElement);
if ($this->fileObj->extension == 'svgz') {
$xml = gzencode($doc->saveXML());
} else {
$xml = $doc->saveXML();
}
$objCacheFile = new \File($this->getCacheName());
$objCacheFile->write($xml);
$objCacheFile->close();
}
示例3: checkFolders
/**
* Create the folders and protect them.
*/
protected function checkFolders()
{
// Get folders from config
$strBackupDB = $this->standardizePath($GLOBALS['SYC_PATH']['db']);
$strBackupFile = $this->standardizePath($GLOBALS['SYC_PATH']['file']);
$strTemp = $this->standardizePath($GLOBALS['SYC_PATH']['tmp']);
$objHt = new File('system/modules/syncCto/config/.htaccess');
$strHT = $objHt->getContent();
$objHt->close();
// Check each one
if (!file_exists(TL_ROOT . '/' . $strBackupDB)) {
new Folder($strBackupDB);
$objFile = new File($strBackupDB . '/' . '.htaccess');
$objFile->write($strHT);
$objFile->close();
}
if (!file_exists(TL_ROOT . '/' . $strBackupFile)) {
new Folder($strBackupFile);
$objFile = new File($strBackupFile . '/' . '.htaccess');
$objFile->write($strHT);
$objFile->close();
}
if (!file_exists(TL_ROOT . '/' . $strTemp)) {
new Folder($strTemp);
}
}
示例4: loadDebuggerstate
public function loadDebuggerstate($varValue, $dc)
{
$objFile = new File('system/config/initconfig.php');
$strContent = $objFile->getContent();
$objFile->close();
return $varValue && strpos($strContent, self::DEBUGCONFIG_STRING);
}
示例5: Poll
function Poll($id, $question, $answer1 = 'Yes', $answer2 = 'No')
{
// values
$id = isset($id) ? $id : '';
$question = isset($question) ? $question : '';
$answer1 = isset($answer1) ? $answer1 : '';
$answer2 = isset($answer2) ? $answer2 : '';
// json dir
$dir = PLUGINS_PATH . '/poll/db/db.json';
// clear vars init
$db = '';
$data = '';
// check if exists file if not make one
if (File::exists($dir)) {
$db = File::getContent($dir);
$data = json_decode($db, true);
if (!$data[$id]) {
// array of data
$data[$id] = array('question' => '', 'yes' => '', 'no' => '');
File::setContent($dir, json_encode($data));
// redirect
Request::redirect(Url::getCurrent());
}
} else {
File::setContent($dir, '[]');
}
// check session if exists show answer only
if (Session::get('user_poll' . $id)) {
$template = Template::factory(PLUGINS_PATH . '/poll/template/');
return $template->fetch('answer.tpl', ['id' => trim($id), 'question' => trim($question), 'answer1' => trim($answer1), 'answer2' => trim($answer2), 'yes' => $data[$id]['yes'], 'no' => $data[$id]['no']]);
} else {
// form post
if (Request::post('sendData_' . $id)) {
// check token
if (Request::post('token')) {
if (Request::post('answer') == 1) {
$good = $data[$id]['yes'] + 1;
$bad = $data[$id]['no'];
} elseif (Request::post('answer') == 0) {
$bad = $data[$id]['no'] + 1;
$good = $data[$id]['yes'];
}
// array of data
$data[$id] = array('question' => $question, 'yes' => $good, 'no' => $bad);
// set content
File::setContent($dir, json_encode($data));
// set session cookie
Session::set('user_poll' . $id, uniqid($id));
// redirect
Request::redirect(Url::getCurrent());
} else {
die('crsf detect !');
}
}
// show template form
$template = Template::factory(PLUGINS_PATH . '/poll/template/');
return $template->fetch('poll.tpl', ['id' => trim($id), 'question' => trim($question), 'answer1' => trim($answer1), 'answer2' => trim($answer2), 'yes' => $data[$id]['yes'], 'no' => $data[$id]['no']]);
}
}
示例6: decodeFile
/**
* Decode file content.
*
* @param string $filePath
* @return array
* @throws \InvalidArgumentException
*/
public function decodeFile($filePath)
{
$file = new File($filePath);
$fileData = $file->getContent();
$dataDecoder = new JsonDataDecoder();
$result = $dataDecoder->decodeData($fileData);
return $result;
}
示例7: testGetContentThrowsAnExceptionIfTheFileDoesNotExistsInTheFilesystem
public function testGetContentThrowsAnExceptionIfTheFileDoesNotExistsInTheFilesystem()
{
$fs = $this->getFilesystemMock();
$fs->expects($this->once())->method('has')->with($this->equalTo('myFile'))->will($this->returnValue(false));
$file = new File('myFile', $fs);
$this->setExpectedException('LogicException');
$file->getContent();
}
示例8: parseExtJs
protected function parseExtJs($objLayout, &$arrReplace)
{
$arrJs = array();
$objJs = ExtJsModel::findMultipleByIds(deserialize($objLayout->extjs));
if ($objJs === null) {
return false;
}
$cache = !$GLOBALS['TL_CONFIG']['debugMode'];
while ($objJs->next()) {
$objFiles = ExtJsFileModel::findMultipleByPid($objJs->id);
if ($objFiles === null) {
continue;
}
$strChunk = '';
$strFile = 'assets/js/' . $objJs->title . '.js';
$strFileMinified = str_replace('.js', '.min.js', $strFile);
$objGroup = new \File($strFile, file_exists(TL_ROOT . '/' . $strFile));
$objGroupMinified = new \File($strFileMinified, file_exists(TL_ROOT . '/' . $strFile));
$rewrite = $objJs->tstamp > $objGroup->mtime || $objGroup->size == 0 || $cache && $objGroupMinified->size == 0;
while ($objFiles->next()) {
$objFileModel = \FilesModel::findByPk($objFiles->src);
if ($objFileModel === null || !file_exists(TL_ROOT . '/' . $objFileModel->path)) {
continue;
}
$objFile = new \File($objFileModel->path);
$strChunk .= $objFile->getContent() . "\n";
if ($objFile->mtime > $objGroup->mtime) {
$rewrite = true;
}
}
// simple file caching
if ($rewrite) {
$objGroup->write($strChunk);
$objGroup->close();
// minify js
if ($cache) {
$objGroup = new \File($strFileMinified);
$objMinify = new \MatthiasMullie\Minify\JS();
$objMinify->add($strChunk);
$objGroup->write(rtrim($objMinify->minify(), ";") . ";");
// append semicolon, otherwise "(intermediate value)(...) is not a function"
$objGroup->close();
}
}
$arrJs[] = $cache ? "{$strFileMinified}|static" : "{$strFile}";
}
// HOOK: add custom css
if (isset($GLOBALS['TL_HOOKS']['parseExtJs']) && is_array($GLOBALS['TL_HOOKS']['parseExtJs'])) {
foreach ($GLOBALS['TL_HOOKS']['parseExtJs'] as $callback) {
$arrJs = static::importStatic($callback[0])->{$callback}[1]($arrJs);
}
}
if ($objJs->addBootstrap) {
$this->addTwitterBootstrap();
}
// inject extjs before other plugins, otherwise bootstrap may not work
$GLOBALS['TL_JAVASCRIPT'] = is_array($GLOBALS['TL_JAVASCRIPT']) ? array_merge($GLOBALS['TL_JAVASCRIPT'], $arrJs) : $arrJs;
}
示例9: testXpath
public function testXpath()
{
$f = new File("/" . FRAMEWORK_CORE_PATH . "tests/xml/xml_file.xml");
$xml_doc = new SimpleXMLElement(str_replace("xmlns", "ns", $f->getContent()));
$config_params = $xml_doc->xpath("/module-declaration/config-params");
$this->assertTrue($config_params, "Impossibile leggere i parametri di configurazione!!");
$install_data = $xml_doc->xpath('/module-declaration/action[@name="install"]');
$this->assertTrue($install_data, "Impossibile leggere i dati per l'installazione!!");
}
示例10: File
function import_data_from_file($filename_or_file)
{
if ($filename_or_file instanceof File) {
$f = $filename_or_file;
} else {
$f = new File($filename_or_file);
}
$this->import_data($f->getContent());
}
示例11: getResponsePart
public function getResponsePart($strFilename, $intFilecount)
{
$strFilepath = "/system/tmp/" . $intFilecount . "_" . $strFilename;
if (!file_exists(TL_ROOT . $strFilepath)) {
throw new \RuntimeException("Missing partfile {$strFilepath}");
}
$objFile = new \File($strFilepath);
$strReturn = $objFile->getContent();
$objFile->close();
return $strReturn;
}
示例12: testBlackHole
function testBlackHole()
{
$f = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/black_hole_test.php");
$this->assertTrue($f->exists(), "Il file del test non esiste!!");
$content = $f->getContent();
$f->delete();
$this->assertFalse($f->exists(), "Il file del test black hole non e' stato eliminato!!");
$f->touch();
$f->setContent($content);
$this->assertTrue($f->exists(), "Il file del test black hole non e' stato rigenerato!!");
}
示例13: loadTempList
protected function loadTempList()
{
$objCompareList = new File($this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], "synccomparelistTo-ID-" . $this->intClientID . ".txt"));
$strContent = $objCompareList->getContent();
if (strlen($strContent) == 0) {
$this->arrListCompare = array();
} else {
$this->arrListCompare = unserialize($strContent);
}
$objCompareList->close();
}
示例14: addJsonFile
/**
* Add the result from json file object
*
* @param \File $file
*/
public function addJsonFile(\File $file)
{
if (substr($file->name, -4, 4) != 'json') {
return;
}
$data = array();
$data = json_decode($file->getContent(), true);
if ($data) {
foreach ($data as $result) {
$this->addResult($result);
}
}
}
示例15: test
/**
* Runs the test.
*/
public function test()
{
$path = DIR_FILES . '/mail/logo.gif';
$name = 'logo.gif';
$mimeType = 'image/gif';
$attachment = new File($path, $name, $mimeType);
$this->assertEquals(file_get_contents($path), $attachment->getContent());
$this->assertEquals($name, $attachment->getName());
$this->assertEquals($mimeType, $attachment->getMimeType());
$this->assertEquals(\Jyxo\Mail\Email\Attachment::DISPOSITION_ATTACHMENT, $attachment->getDisposition());
$this->assertFalse($attachment->isInline());
$this->assertEquals('', $attachment->getCid());
$this->assertEquals('', $attachment->getEncoding());
}