当前位置: 首页>>代码示例>>PHP>>正文


PHP Uuid::uuid方法代码示例

本文整理汇总了PHP中Uuid::uuid方法的典型用法代码示例。如果您正苦于以下问题:PHP Uuid::uuid方法的具体用法?PHP Uuid::uuid怎么用?PHP Uuid::uuid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Uuid的用法示例。


在下文中一共展示了Uuid::uuid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: file

 /**
  * Copy a random file from the source directory to the target directory and returns the filename/fullpath
  *
  * @param string $sourceDirectory
  *        	The directory to look for random file taking
  * @param string $targetDirectory        	
  * @param boolean $fullPath
  *        	Whether to have the full path or just the filename
  * @return string
  */
 public static function file($sourceDirectory = '/tmp', $targetDirectory = '/tmp', $fullPath = true)
 {
     if (!is_dir($sourceDirectory)) {
         throw new \InvalidArgumentException(sprintf('Source directory %s does not exist or is not a directory.', $sourceDirectory));
     }
     if (!is_dir($targetDirectory)) {
         throw new \InvalidArgumentException(sprintf('Target directory %s does not exist or is not a directory.', $targetDirectory));
     }
     if ($sourceDirectory == $targetDirectory) {
         throw new \InvalidArgumentException('Source and target directories must differ.');
     }
     // Drop . and .. and reset array keys
     $files = array_filter(array_values(array_diff(scandir($sourceDirectory), array('.', '..'))), function ($file) use($sourceDirectory) {
         return is_file($sourceDirectory . DIRECTORY_SEPARATOR . $file) && is_readable($sourceDirectory . DIRECTORY_SEPARATOR . $file);
     });
     if (empty($files)) {
         throw new \InvalidArgumentException(sprintf('Source directory %s is empty.', $sourceDirectory));
     }
     $sourceFullPath = $sourceDirectory . DIRECTORY_SEPARATOR . static::randomElement($files);
     $destinationFile = Uuid::uuid() . '.' . pathinfo($sourceFullPath, PATHINFO_EXTENSION);
     $destinationFullPath = $targetDirectory . DIRECTORY_SEPARATOR . $destinationFile;
     if (false === copy($sourceFullPath, $destinationFullPath)) {
         return false;
     }
     return $fullPath ? $destinationFullPath : $destinationFile;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:36,代码来源:File.php


注:本文中的Uuid::uuid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。