Creates a file model.
@param string $scenario the scenario name.
@return File the file model.
@throws CException if the file model does not extend the "File" class.
559162
public function createModel($scenario = 'insert')
    {
        /* @var File $model */
        $model = new $this->modelClass($scenario);
        if (!$model instanceof File) {
            throw new CException(sprintf('Model class "%s" must extend "File".', $this->modelClass));
        }
        return $model;
    }
329516
public function createFile()
    {
        $cacheDependencyFileName = $this->getDependencyFileName();
        if ( ! file_exists(dirname($cacheDependencyFileName)) ) {
            FileHelper::createDirectory(dirname($cacheDependencyFileName));
        }
        file_put_contents($cacheDependencyFileName, uniqid());
        return $cacheDependencyFileName;
    }
1362254
public function actionLogin($scenario = null)
    {
        /** @var LoginForm */
        $model = $this->module->createFormModel('LoginForm');
        $scenarios = $model->scenarios();
        if ($scenario !== null && in_array($scenario, array_keys($scenarios))) {
            $model->scenario = $scenario;
        }

        if ($model->load($_POST)) {
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

                return \yii\widgets\ActiveForm::validate($model);
            }
            if ($model->validate()) {
                if (($model->scenario !== 'reset' || $model->resetPassword($model->newPassword)) && $model->login($this->module->rememberMeDuration)) {
                    return $this->afterLogin();
                } else {
                    Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
                }
            }
        }
        list($view, $params) = $this->getScenarioView($model->scenario, 'login');

        return $this->render($view, array_merge(['model' => $model], $params));
    }
1249194
public function getFile($file) {
		$timeStamp = microtime(true);
		if($file instanceof BundleEntity\File){
			return new ModelResponse($file, 1, 0, null, false, 'S:D:002', 'Entries successfully fetched from database.', $timeStamp, microtime(true));
		}
		$result = null;
		switch($file){
			case is_numeric($file):
				$result = $this->em->getRepository($this->entity['f']['name'])->findOneBy(array('id' => $file));
				break;
			case is_string($file):
				$result = $this->em->getRepository($this->entity['f']['name'])->findOneBy(array('url_key' => $file));
				if(is_null($result)){
					$result = $this->em->getRepository($this->entity['f']['name'])->findOneBy(array('source_original' => $file));
					if(is_null($result)){
						$result = $this->em->getRepository($this->entity['f']['name'])->findOneBy(array('source_preview' => $file));
					}
				}
				break;
		}
		if(is_null($result)){
			return new ModelResponse($result, 0, 0, null, true, 'E:D:002', 'Unable to find request entry in database.', $timeStamp, microtime(true));
		}

		return new ModelResponse($result, 1, 0, null, false, 'S:D:002', 'Entries successfully fetched from database.', $timeStamp, microtime(true));
	}
1277382
public function create($context)
    {
        $providerManager = $this->providerService->getProviderManager($context);

        $media = $this->mediaManager->createMedia($context);

        $mediaProvider = $providerManager->getMediaProviderManager()->createMediaProvider();
        $mediaProvider->setMedia($media);

        return $mediaProvider;
    }
200025
public function createFile(string $path): File {
    $localFile = $this->instantiateFile($path);
    $localFile->create();
    return $localFile;
  }
1372470
static public function createFromFile($filename) {
		if (!file_exists($filename))
			throw new Exception('Invalid (filename) parameter! File does not exist!');

		$image_info = getimagesize($filename);
		if ($image_info === false)
			throw new Exception('Invalid (filename) parameter! File is corrupted!');

		switch ($image_info[2]) {
			case IMAGETYPE_JPEG:
			case IMAGETYPE_JPEG2000:
				$image = imagecreatefromjpeg($filename);
				break;
			case IMAGETYPE_PNG:
				$image = imagecreatefrompng($filename);
				break;
			case IMAGETYPE_GIF:
				$image = imagecreatefromgif($filename);
				break;
			case IMAGETYPE_WBMP:
				$image = imagecreatefromwbmp($filename);
				break;
			case IMAGETYPE_BMP:
				$image = imagecreatefrombmp($filename);
				break;
			default:
				throw new Exception('Unknown image format!');
				break;
		}

		return new self($image);
	}
769894
protected function mergeExternalFiles(string $file, MutableBag $envs): MutableBag
    {
        $extPos = strrpos($file, '.');
        $pathTemplate = substr_replace($file, '.%s.', $extPos, 1);
        foreach ($envs as $name => $config) {
            // config.yml -> config.production.yml
            $envFile = sprintf($pathTemplate, $name);
            if (!is_readable($envFile)) {
                continue;
            }
            $envConfig = $this->parse($envFile);
            $envs[$name] = $config->replaceRecursive($envConfig);
        }

        return $envs;
    }
93376
public function export($strategy)
    {
        // Check if the strategy is available and allowed to be used
        if ( ! $this->isExportStrategyAvailable($strategy)) {
            abort(403, "Not possible or allowed to perform export '{$strategy}'");
        }

        // Prepare the strategy instance
        $exporter = $this->getExportStrategyInstance($strategy);
        $filename = $this->getExportDownloadFilename($strategy, $exporter->extension());

        $this->checkListParents()
             ->checkActiveSort(false)
             ->checkScope(false)
             ->checkFilters()
             ->checkActivePage(false)
             ->applySort()
             ->applyScope($this->modelRepository);

        $query = $this->getModelRepository()->query();

        $this->applyFilter($query)
             ->applyListParentToQuery($query);

        $download = $exporter->download($query, $filename);

        if (false === $download) {
            // @codeCoverageIgnoreStart
            abort(500, "Failed to export model listing for strategy '{$strategy}'");
            // @codeCoverageIgnoreEnd
        }

        event( new Events\ModelListExportedInCms($this->modelInformation->modelClass(), $strategy) );

        return $download;
    }
938180
public function onValidationScenario($scenario, array $parameters = [])
    {
        list($on, $extend) = $this->getValidationSchemasName($scenario);

        $this->validationScenarios = [
            'on'         => method_exists($this, $on) ? $on : null,
            'extend'     => method_exists($this, $extend) ? $extend : null,
            'parameters' => $parameters,
        ];

        return $this;
    }
209370
protected function findScenario($scenario = null)
    {
        $scenarios = $this->scenarios();
        if ($scenario === null) {
            $scenario = $this->getScenario();
        }
        return isset($scenarios[$scenario]) ? $scenarios[$scenario] : [];
    }
768793
protected function getValidationSchemasName(string $scenario): array
    {
        $scenario = \ucfirst($scenario);

        $on = "on{$scenario}";
        $extend = "extend{$scenario}";

        return [
            \method_exists($this, $on) ? $on : null,
            \method_exists($this, $extend) ? $extend : null,
        ];
    }
360569
final public function onValidationScenario(string $scenario, array $parameters = []): self
    {
        [$on, $extend] = $this->getValidationSchemasName($scenario);

        $this->validationScenarios = \compact('on', 'extend', 'parameters');

        return $this;
    }
641525
public static function createModel($options) {
        $modelDir = APP_PATH."modules/{$options['module']}/dao/";
        if ( !is_writable(dirname($modelDir)) ) {
            return tprintError("Error: directory '{$modelDir}' is not writeadble， please add permissions.");
        }
        //create directory
        FileUtils::makeFileDirs($modelDir);
        $options['module_dir'] = $modelDir;
        if ( $options['xmlpath'] ) {
            $options['xmlpath'] = self::getXmlFilename($options['xmlpath']);
            $xml = new SimpleHtmlDom(file_get_contents($options['xmlpath']));
            return ModelFactory::createModelByXml($xml, $options);
        } else {
            return ModelFactory::createModel($options);
        }
    }
33761
public function generate($schema, $className, Context $context)
    {
        $files = [];

        foreach ($schema->getClasses() as $class) {
            $properties = [];
            $methods    = [];

            foreach ($class->getProperties() as $property) {
                $properties[] = $this->createProperty($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createGetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createSetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
            }

            $model = $this->createModel(
                $class->getName(),
                $properties,
                $methods
            );

            $namespace = new Stmt\Namespace_(new Name($schema->getNamespace()."\\Model"), [$model]);

            $files[] = new File($schema->getDirectory().'/Model/'.$class->getName().'.php', $namespace, self::FILE_TYPE_MODEL);
        }

        return $files;
    }
1355760
public function format(array $scenarios)
    {
        return rtrim(implode(
            array_map(
                function (ScenarioInterface $scenario) {
                    return $this->getTags($scenario)
                    . $this->getScenarioDescription($scenario)
                    . $this->getSteps($scenario)
                    . $this->getExamples($scenario);
                },
                $scenarios
            )
        )) . "\n";
    }
690207
public static function create($file)
    {
        // Verify ZipArchive is installed
        $zipArchive = class_exists('ZipArchive');

        try {
            return self::makeZipArchiver($file, ! $zipArchive, true);
        } catch ( Exception $e ) {
            return self::makeZipArchiver($file, $zipArchive, true);
        }
    }