本文整理汇总了PHP中Includes\Utils\FileManager::getHash方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::getHash方法的具体用法?PHP FileManager::getHash怎么用?PHP FileManager::getHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Includes\Utils\FileManager
的用法示例。
在下文中一共展示了FileManager::getHash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importImages
/**
* Import images
*
* @param \XLite\Model\Product $product Product
* @param string $data Data
*
* @return void
*/
protected function importImages(\XLite\Model\Product $product, $data)
{
// Save old images ids' list
$oldImageIds = array();
foreach ($product->getImages() as $image) {
$oldImageIds[] = $image->getId();
}
if ($data) {
// Load images
foreach (explode(';', $data) as $url) {
$url = trim($url);
$hash = \Includes\Utils\FileManager::getHash($url);
$image = null;
if ($hash) {
foreach ($product->getImages() as $i) {
if ($i->getHash() == $hash) {
$image = $i;
$key = array_search($i->getId(), $oldImageIds);
unset($oldImageIds[$key]);
break;
}
}
}
if (!$image) {
$image = new \XLite\Model\Image\Product\Image();
$image->setProduct($product);
$result = preg_match('/^(https?|ftp):\\/\\//Ss', $url) ? $image->loadFromURL($url) : $image->loadFromLocalFile($url);
if ($result) {
$product->addImages($image);
\XLite\Core\Database::getEM()->persist($image);
} else {
$this->logImportWarning(static::t('X image unable to load', array('url' => $url)), $this->importCell['position'], 'images', $url, $product);
}
}
}
}
// Remove old images
foreach ($product->getImages() as $image) {
if (in_array($image->getId(), $oldImageIds)) {
$product->getImages()->removeElement($image);
\XLite\Core\Database::getEM()->remove($image);
}
}
}
示例2: loadHashesForInstalledFiles
/**
* Calculate hashes for current version
*
* @return array
*/
protected function loadHashesForInstalledFiles()
{
$result = array();
$module = $this->getModuleInstalled();
if ($module) {
$pack = new \XLite\Core\Pack\Module($module);
foreach ($pack->getDirectoryIterator() as $file) {
if ($file->isFile()) {
$relativePath = \Includes\Utils\FileManager::getRelativePath($file->getPathname(), LC_DIR_ROOT);
if ($relativePath) {
$result[$relativePath] = \Includes\Utils\FileManager::getHash($file->getPathname(), true);
}
}
}
}
return $result ?: $this->getHashes(true);
}
示例3: addPackHash
/**
* Create list of archive file hashes and add it to the pack
*
* @param \PharData $phar PHAR archive
* @param \Iterator $iterator Directory iterator
*
* @return void
*/
protected static function addPackHash(\PharData $phar, \Iterator $iterator)
{
$data = array();
foreach ($iterator as $filePath => $fileInfo) {
$data[\Includes\Utils\FileManager::getRelativePath($filePath, LC_DIR_ROOT)] = \Includes\Utils\FileManager::getHash($filePath);
}
$phar->addFromString('.hash', json_encode($data));
}
示例4: renewByPath
/**
* Renew properties by path
*
* @param string $path Path
*
* @return boolean
*/
protected function renewByPath($path)
{
$result = parent::renewByPath($path);
if ($result) {
$data = @getimagesize($path);
if (is_array($data)) {
$this->setWidth($data[0]);
$this->setHeight($data[1]);
$this->setMime($data['mime']);
$hash = \Includes\Utils\FileManager::getHash($path);
if ($hash) {
$this->setHash($hash);
}
} else {
$result = false;
}
}
return $result;
}
示例5: detectImage
/**
* Detect image
*
* @param \XLite\Model\Product $product Product
* @param array $image Image info
*
* @return \XLite\Model\Image\Product\Image
*/
protected function detectImage(\XLite\Model\Product $product, array $image)
{
$hash = \Includes\Utils\FileManager::getHash($image['url']);
$model = null;
if ($hash) {
foreach ($product->getImages() as $oldImage) {
if ($oldImage->getHash() == $hash) {
$model = $oldImage;
break;
}
}
}
return $model;
}