Example #1
0
 /**
  * 2015-12-06
  * @return void
  */
 private function unlock()
 {
     df_fs_w(DirectoryList::TMP)->delete($this->fileBaseName());
 }
Example #2
0
/**
 * 2015-11-29
 * @return DirectoryWrite|DirectoryWriteInterface
 */
function df_media_writer()
{
    return df_fs_w(DirectoryList::MEDIA);
}
Example #3
0
/**
 * 2015-11-29
 * @param string $directory
 * @param string $relativeFileName
 * @param string $contents
 * @return void
 */
function df_file_write($directory, $relativeFileName, $contents)
{
    /** @var DirectoryWrite|DirectoryWriteInterface $writer */
    $writer = df_fs_w($directory);
    /** @var FileWriteInterface|FileWrite $file */
    $file = $writer->openFile($relativeFileName, 'w');
    /**
     * 2015-11-29
     * По аналогии с @see \Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize()
     * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php#L61-L68
     * Обратите внимание, что к реализации этого метода у меня аж 4 замечания:
     *
     * 1) https://mage2.pro/t/274
     * «\Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize() wrongly leaves a file in the locked state in case of an exception»
     *
     * 2) https://mage2.pro/t/271
     * «\Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize() suppresses its exceptions for a questionably reason»
     *
     * 3) https://mage2.pro/t/272
     * «\Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize() duplicates the code in the try and catch blocks, propose to use a «finally» block»
     *
     * 4) https://mage2.pro/t/273
     * «\Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize() contains a wrong PHPDoc comment for the $file variable»
     */
    try {
        $file->lock();
        try {
            $file->write($contents);
        } finally {
            $file->unlock();
        }
    } finally {
        $file->close();
    }
}