下载对账单
@param string|File $file
@param array $args
@return int
@throws \Exception
190898
public function downloadBill($file, array $args = array()) {
        return $this->getBill()->parameters($this->merge($args))->save($file);
    }
869372
public function loadAndCache($file, $cachekey, $args=NULL) {
		if (isset($this->objectCache[$cachekey])) {
			return $this->objectCache[$cachekey];
		}

		$_x = $this->load($file, $args);
		if ($_x !== FALSE) {
			$this->objectCache[$cachekey] = $_x;
		}
		return $_x;
	}
1194528
public function run($args)
	{
		if(!isset($args[0]))
			$this->usageError('the configuration file is not specified.');
		if(!is_file($args[0]))
			$this->usageError("the configuration file {$args[0]} does not exist.");

		$config=require($args[0]);
		$translator='Yii::t';
		extract($config);

		if(!isset($sourcePath,$messagePath,$languages))
			$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
		if(!is_dir($sourcePath))
			$this->usageError("The source path $sourcePath is not a valid directory.");
		if(!is_dir($messagePath))
			$this->usageError("The message path $messagePath is not a valid directory.");
		if(empty($languages))
			$this->usageError("Languages cannot be empty.");

		if(!isset($overwrite))
			$overwrite = false;

		if(!isset($removeOld))
			$removeOld = false;

		if(!isset($sort))
			$sort = false;

		if(!isset($fileHeader))
			$fileHeader = true;

		$options=array();
		if(isset($fileTypes))
			$options['fileTypes']=$fileTypes;
		if(isset($exclude))
			$options['exclude']=$exclude;
		$files=CFileHelper::findFiles(realpath($sourcePath),$options);

		$messages=array();
		foreach($files as $file)
			$messages=array_merge_recursive($messages,$this->extractMessages($file,$translator));

		foreach($languages as $language)
		{
			$dir=$messagePath.DIRECTORY_SEPARATOR.$language;
			if(!is_dir($dir))
				@mkdir($dir);
			foreach($messages as $category=>$msgs)
			{
				$msgs=array_values(array_unique($msgs));
				$this->generateMessageFile($msgs,$dir.DIRECTORY_SEPARATOR.$category.'.php',$overwrite,$removeOld,$sort,$fileHeader);
			}
		}
	}
59593
public function run($args)
	{
		$options=array(
			'fileTypes'=>array('php'),
			'exclude'=>array(
				'.gitignore',
				'/messages',
				'/views',
				'/cli',
				'/yii.php',
				'/yiit.php',
				'/yiilite.php',
				'/web/js',
				'/vendors',
				'/i18n/data',
				'/utils/mimeTypes.php',
				'/test',
				'/zii',
				'/gii',
			),
		);
		$files=CFileHelper::findFiles(YII_PATH,$options);
		$map=array();
		foreach($files as $file)
		{
			if(($pos=strpos($file,YII_PATH))!==0)
				die("Invalid file '$file' found.");
			$path=str_replace('\\','/',substr($file,strlen(YII_PATH)));
			$className=substr(basename($path),0,-4);
			if($className[0]==='C')
				$map[$path]="\t\t'$className' => '$path',\n";
		}
		ksort($map);
		$map=implode($map);

		$yiiBase=file_get_contents(YII_PATH.'/YiiBase.php');
		$newYiiBase=preg_replace('/private\s+static\s+\$_coreClasses\s*=\s*array\s*\([^\)]*\)\s*;/',"private static \$_coreClasses=array(\n{$map}\t);",$yiiBase);
		if($yiiBase!==$newYiiBase)
		{
			file_put_contents(YII_PATH.'/YiiBase.php',$newYiiBase);
			echo "YiiBase.php is updated successfully.\n";
		}
		else
			echo "Nothing changed.\n";
	}
1289846
public function deleteFiles(array $files)
    {
        $count = 0;
        foreach ($files as $file) {
            if ($this->zip->deleteName($file) === false)
                throw new Exception($this->zip->getStatusString(), $this->zip->status);
            $count++;
        }

        // reopen archive to save changes
        $archive_filename = $this->zip->filename;
        $this->zip->close();
        $this->open($archive_filename);

        return $count;
    }
1337214
final protected function executeSqlFromFile($file)
    {
        if (is_file($file)) {
            return $this->executeSqlFromString(file_get_contents($file));
        } else {
            throw new RuntimeException(sprintf('Can not read file at "%s"', $file));
        }
    }
1108930
public function addFile($file, $resource = null)
    {
        if (!file_exists($file) || !is_file($file)) {
            throw new \Exception('The configuration file ' . $file . ' does not exist.');
        } else {
            if ($resource === null) {
                $resource = $file;
            }

            if (!array_key_exists($resource, self::$parameters)) {
                self::$parameters[$resource] = new ParameterBag();
            }

            $content = YamlParser::parse(file_get_contents($file));

            if ($content !== null) {
                $content = self::parseImports($content, $resource);

                $content = self::parseParameters($content, $resource);

                self::addConfig($content, $resource);
            }
        }

        return self::getInstance();
    }
1008679
protected static function _parse($file) {
		$header = '';
		$content = '';

		if (!$stream = fopen($file, 'r')) {
			throw new Exception('Failed to open file.');
		}

		$isHeader = false;

		while (!feof($stream)) {
			$line = rtrim(fgets($stream));

			if ($line === '---') {
				$isHeader = !$isHeader;
				continue;
			}
			if ($isHeader) {
				$header .= $line . "\n";
			} else {
				$content .= $line . "\n";
			}
		}
		if ($header) {
			$info = Yaml::parse($header);
		} else {
			$info = [];
		}

		fclose($stream);
		return [$info, $content];
	}
1184772
public function saveImage( $file, $args = [] ) {

		// Save only when filename is provided
		if( strlen( $file->name ) > 0 ) {

			$fileManager	= Yii::$app->fileManager;
			$model			= null;
			$attribute		= null;
			$width			= null;
			$height			= null;
			$mwidth			= null;
			$mheight		= null;
			$twidth			= null;
			$theight		= null;

			// The model and it's attribute used to refer to image
			if( isset( $args[ 'model' ] ) )		$model		= $args[ 'model' ];
			if( isset( $args[ 'attribute' ] ) ) $attribute	= $args[ 'attribute' ];

			// Update Image
			$fileId = $file->id;

			if( $file->changed ) {

				// Image dimensions to crop actual image uploaded by users
				if( isset( $args[ 'width' ] ) )		$width		= $args[ 'width' ];
				if( isset( $args[ 'height' ] ) )	$height		= $args[ 'height' ];
				if( isset( $args[ 'mwidth' ] ) )	$twidth		= $args[ 'mwidth' ];
				if( isset( $args[ 'mheight' ] ) )	$theight	= $args[ 'mheight' ];
				if( isset( $args[ 'twidth' ] ) )	$twidth		= $args[ 'twidth' ];
				if( isset( $args[ 'theight' ] ) )	$theight	= $args[ 'theight' ];

				// override controller args
				if( isset( $file->width ) && isset( $file->height ) ) {

					$width		= $file->width;
					$height		= $file->height;
				}

				if( isset( $file->mwidth ) && isset( $file->mheight ) ) {

					$mwidth		= $file->mwidth;
					$mheight	= $file->mheight;
				}

				if( isset( $file->twidth ) && isset( $file->theight ) ) {

					$twidth		= $file->twidth;
					$theight	= $file->theight;
				}

				// Process Image
				$fileManager->processImage( $file, $width, $height, $mwidth, $mheight, $twidth, $theight );
			}

			// New File
			if( !isset( $fileId ) || strlen( $fileId ) <= 0 || intval( $fileId ) <= 0 ) {

				// Unset Id
				$file->id = null;

				// Update File Size
				$file->resetSize();

				// Create
				$this->create( $file );

				// Update model attribute
				if( isset( $model ) && isset( $attribute ) ) {

					$model->setAttribute( $attribute, $file->id );
				}
			}
			// Existing File - Image Changed
			else if( $file->changed ) {

				// Update File Size
				$file->resetSize();

				$this->updateData( $file );
			}
			// Existing File - Info Changed
			else if( isset( $fileId ) && intval( $fileId ) > 0 ) {

				$this->update( $file );
			}

			$file->changed	= false;
		}

		return $file;
	}
394971
protected static function getPathFromFile(File $file)
    {
        $path = tempnam(TEMP_PATH, 'pdftextextractor_');
        if (false === $path) {
            throw new Exception(static::class . '->getPathFromFile() could not allocate temporary file name');
        }

        // Append extension to temp file if one is set
        if ($file->getExtension()) {
            $path .= '.' . $file->getExtension();
        }

        // Remove any existing temp files with this name
        if (file_exists($path)) {
            unlink($path);
        }

        $bytesWritten = file_put_contents($path, $file->getStream());
        if (false === $bytesWritten) {
            throw new Exception(static::class . '->getPathFromFile() failed to write temporary file');
        }

        return $path;
    }
438959
public function fetch($file)
    {
        $templateFile = $this->findTemplateFile($file);

        if (empty($templateFile)) {
            throw new Exception("Template file does not exists: $file");            
        }

        extract($this->vars);
        ob_start();
        include $templateFile;
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }
453033
public function get($file)
    {
        $target = $this->path . $file;

        if (!is_readable($target)) {
            throw new \Exception("No such content " . $target);
        }

        return file_get_contents($target);
    }
692799
public function showCode($file, $line)
    {
        $line = $line - 1; //数组下标从0开始的
        $contentArr = file($file);
        foreach ($contentArr as $k => $v) {
            if ($k > $line - $this->maxLine) {
                echo '<span class="line">' . ($k + 1) . '</span>' . $v;
            }
            if ($k == $line - 1) {
                break;
            }
        }
        echo '<span class="errorLine"><span class="line">' . ($line + 1) . '</span>' . $contentArr[$line] . '</span>';
        foreach ($contentArr as $k => $v) {
            if ($k > $line) {
                echo '<span class="line">' . ($k + 1) . '</span>' . $v;
            }
            if ($k == $line + $this->maxLine) {
                break;
            }
        }

    }
317293
public function commit($args = array()) {
        foreach ($args as $item) {
            $res = mysql_query($item, $this->driver);
            if (!$res) {
                throw new \Exception('事务执行失败！');
            }
        }
        $arg = mysql_query('COMMIT');
        $result = empty($arg);
        mysql_query('END', $this->driver);
        return $result;
    }
632028
private function findFile($file) {
        $filePath = MODULES_DIR . DS . self::$currentRoute['module'] . DS . 'Views' . DS . $file . '.php';
        if (!file_exists($filePath)) {
            $filePath = BASE_DIR . DS . 'base' . DS . 'views' . DS . $file . '.php';
            if (!file_exists($filePath)) {
                throw new \Exception(_message(ExceptionMessages::VIEW_FILE_NOT_FOUND, $file));
            }
        }

        return $filePath;
    }
1054521
public function fork($file, $options = array(), $start = true)
    {
        return $this->parallel(function ($process) use ($file) {
            if (is_string($file) && is_file($file)) {
                include($file);
            } else {
                throw new \RuntimeException('Bad file');
            }
        }, $options, $start);
    }
623966
public function parseFile($file)
    {
        $str = @\file_get_contents($file);
        if (false === $str) {
            throw new Exception('Can\'t read file.');
        }

        return $this->parse($str);
    }