/*
if exist local file, rename file
demo.html renamed to demo_dae4c9057b2ea5c3c9e96e8352ac28f0c7d87f7d.html

@access public
@param string $name file name
@return new file name
331321
public static function newName($name)
    {
        if (file_exists($name)) {
            $extension = self::getFileExtension($name);
            $name = substr($name,0,(-strlen($extension)-1)) . '_' . sha1(uniqid(rand(), true)) . ".$extension";
        }
        return $name;
    }
593415
public function setName($name)
	{
		if ( ! is_string($name)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, name, to be a string"
			);	
		}
		
		if ( ! is_readable($name)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, name, to be a readable filename"
			);
		}
		
		$this->name = $name;
		
		return $this;
	}
497700
public function setName($name) {
        $this->name = $name;
        $arg = pathinfo($name, PATHINFO_EXTENSION);
        if (!empty($arg)) {
            $this->extension = $arg;
        }
        return $this;
    }
703876
public function child($name) {
        $file = $this->getChild($name);
        if (is_dir($file)) {
            return new static($file);
        }
        if (is_file($file)) {
            return new File($file);
        }
        return false;
    }
1097272
public static function createTempPathNamed($name)
    {
        $dir = static::createTempPath();

        if (!unlink($dir)) {
            // @codeCoverageIgnoreStart
            throw new FileException(
                'The temporary file could not be deleted.'
            );
        }
        // @codeCoverageIgnoreEnd

        if (!mkdir($dir)) {
            // @codeCoverageIgnoreStart
            throw new FileException(
                'A new temporary directory could not be created.'
            );
        }
        // @codeCoverageIgnoreEnd

        $path = $dir . DIRECTORY_SEPARATOR . $name;

        if (!touch($path)) {
            // @codeCoverageIgnoreStart
            throw new FileException(
                'A new temporary file could not be created.'
            );
        }
        // @codeCoverageIgnoreEnd

        return $path;
    }
1151726
protected function getName($name)
    {
        $renames = $this->getRenames();

        if (isset($renames[$name])) {
            return $renames[$name];
        }
        return $name;
    }
500338
public function rename( $fileName )
	{
		if( !$fileName )
			throw new InvalidArgumentException( 'No File Name given.' );
		$result	= @rename( $this->fileName, $fileName );
		if( $result === FALSE )
			throw new RuntimeException( 'File "'.$this->fileName.'" could not been renamed.' );
		$this->__construct( $fileName );
		return $result;
	}
533595
protected function rename($file)
    {
        $tmpFile = $file . '.tmp';

        if (rename($file, $tmpFile)) {
            return $tmpFile;
        }

        throw new \RuntimeException(sprintf('Could not rename %s to %s', $file, $tmpFile));
    }
356516
public function setName($name) {
        // get the path info of the given name
        $pathinfo = pathinfo($name);
        
        // get the base file name
        $filename = $pathinfo['filename'];
        
        // set the file name
        $this->name = $filename . '.' . $this->extension();

        // done, return the instance of this, to make chaining possible
        return $this;
    }
1196427
public function createChildFile($name)
    {
        if (
            strpos($name, '\\') !== false
            || strpos($name, '/') !== false
            || strpos($name, '..') !== false
        ) {
            throw new InvalidArgumentException("Wrong file name {$name}");
        }

        $class = $this->fileClass;

        return new $class($this->absolutePath . '/' . $name);
    }
208172
public function renameFolder($name, $newname) {
        return imap_renamemailbox($this->imap, $this->mailbox . $name, $this->mailbox . $newname);
    }
865885
public static function create($name) {
    $name = (string) $name;
    $name = ltrim($name, '\\');
    $namespace_node = Parser::parseSnippet("namespace $name;");
    return $namespace_node;
  }
881390
protected function _getFileName($name){

		$name = trim($name);

		$name = iconv('ISO-8859-1', 'ASCII//TRANSLIT', $name);
		$name = preg_replace('/[^a-z0-9\-:]+/i', '_', $name);
		$name = str_replace(':', '.', $name);

		if($name == ''){

			throw new CacheException('Cache-entry name cannot be empty');
		}

		return "{$name}.cache";
	}
871500
public function make(string $name): Template
    {
        $name = \trim($name, '/\\');
        $file = $this->compile($name);

        return new Template($this, $name, $file);
    }
1200760
public function create($name = '')
    {

        $names = explode(",", $name);

        foreach ($names as $name) {

            $content = $this->migrate(RESOURCE . 'migrations/migration.php.dist', ['name' => $name]);

            $fileName = FacadeMigration::createName($name);
            if (!$this->file->exists($fileName)) {
                $this->file->create($fileName);
                $this->write(MIGRATION, $fileName, $content);
                $this->info(sprintf('%s migration created with successfully', $name));
            } else {
                $this->error(sprintf('%s file already exists in %s', $name, $fileName));
            }
        }

    }
1137892
public function setName($name) {
		if (is_array($name) && empty($name)) {
			$this->name = new \stdClass;
		} else {
			$this->name = $name;
		}

		return $this;
	}
690543
public function file($name = '')
    {
        if (empty($this->file)) {
            $this->file = isset($_FILES) ? $_FILES : [];
        }
        if (is_array($name)) {
            return $this->file = array_merge($this->file, $name);
        }
        $files = $this->file;
        if (!empty($files)) {
            // 处理上传文件
            $array = [];
            foreach ($files as $key => $file) {
                if (is_array($file['name'])) {
                    $item  = [];
                    $keys  = array_keys($file);
                    $count = count($file['name']);
                    for ($i = 0; $i < $count; $i++) {
                        if (empty($file['tmp_name'][$i]) || !is_file($file['tmp_name'][$i])) {
                            continue;
                        }
                        $temp['key'] = $key;
                        foreach ($keys as $_key) {
                            $temp[$_key] = $file[$_key][$i];
                        }
                        $item[] = (new File($temp['tmp_name']))->setUploadInfo($temp);
                    }
                    $array[$key] = $item;
                } else {
                    if ($file instanceof File) {
                        $array[$key] = $file;
                    } else {
                        if (empty($file['tmp_name']) || !is_file($file['tmp_name'])) {
                            continue;
                        }
                        $array[$key] = (new File($file['tmp_name']))->setUploadInfo($file);
                    }
                }
            }
            if (strpos($name, '.')) {
                list($name, $sub) = explode('.', $name);
            }
            if ('' === $name) {
                // 获取全部文件
                return $array;
            } elseif (isset($sub) && isset($array[$name][$sub])) {
                return $array[$name][$sub];
            } elseif (isset($array[$name])) {
                return $array[$name];
            }
        }
        return;
    }