Create a new instance from a file path.

@param null|resource $context

@throws SyntaxError If the File is not readable
198983
public static function createFromPath(string $path, $context = null): self
    {
        $file_args = [$path, false];
        $mime_args = [$path, FILEINFO_MIME];
        if (null !== $context) {
            $file_args[] = $context;
            $mime_args[] = $context;
        }

        $content = @file_get_contents(...$file_args);
        if (false === $content) {
            throw new SyntaxError(sprintf('`%s` failed to open stream: No such file or directory', $path));
        }

        return new self(
            str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args))
            .';base64,'.base64_encode($content)
        );
    }
16489
public static function create()
    {
        $key = static::getContextKey();
        if(!isset(static::$context[$key]))
        {
            static::$context[$key] = RequestContext::getServerBean('ConnectContextStore')->read($key);
        }
    }
144845
public function initializeContext(Context $context)
    {
        if ($context instanceof ResourceContext) {
            $reflector = new ReflectionClass(get_class($context));

            if ($this->builder->getLoader() instanceof FileResourceLoader) {
                if ($this->builder->getLoader()->getBasePath() == null) {
                    $this->builder->getLoader()->setBasePath(dirname($reflector->getFileName()));
                }
            }

            if ($context->getResourceFactory()) {
                $this->builder->setFactory($context->getResourceFactory());
            }

            $context->setResourceBuilder($this->builder);
        }
    }
970880
public function initializeContext(Context $context)
    {
        if (!$context instanceof MinkAwareContext) {
            return;
        }

        $context->setMink($this->mink);
        $context->setMinkParameters($this->parameters);
    }
1204683
public static function fromString($resource = '', $size = null)
    {
        $stream = fopen('php://temp', 'r+');

        if ($resource !== '') {
            fwrite($stream, $resource);
            fseek($stream, 0);
        }

        return new self($stream, $size);
    }
58791
public static function StaticBaseUri( $context )
	{
		if ( is_null( $context->RunningContext->BaseUri ) )
		    return Undefined::getValue();

		return new AnyUriValue( $context->RunningContext->BaseUri );
	}
114579
protected function readStreamTask(Context $context, string $path): \Generator
    {
        if (!yield $this->pool->submit($context, new MethodCall(static::class, 'checkFileReadableJob', $path))) {
            throw new FilesystemException(\sprintf('File is not readable: "%s"', $path));
        }
        
        if (!$this->fileTransferSupported) {
            return new ReadableFileStream($this->pool, $path);
        }
        
        $file = yield $this->pool->submit($context, new MethodCall(FileDescriptor::class, 'open', $path, 'rb'));
        
        return new ReadableDescriptorStream($this->pool, $path, $file);
    }
17804
public function create($filePath = null, $mode = 'wb')
    {
        $filePath = isset($filePath) ? $filePath : $this->filePath;
        $dir = dirname($filePath);

        if ( ! is_writable($dir)) {
            if ( ! file_exists($dir)) {
                mkdir($dir, 0777, true);
            }
        }

        if ( ! $fp = @fopen($filePath, $mode)) {
            return false;
        }

        parent::__construct($filePath);

        return $fp;
    }
394467
private function parseContext($context)
    {
        $debugBackTrace = debug_backtrace();
        if(!isset($context['trace']))
        {
            $context['trace'] = $this->getTrace($debugBackTrace);
        }
        if(!isset($context['errorFile']))
        {
            list($file, $line) = $this->getErrorFile($debugBackTrace);
            $context['errorFile'] = $file;
            $context['errorLine'] = $line;
        }
        return $context;
    }
977144
public function context(Context $context = null) : Context
    {
        if (!$this->context) {
            $this->context = $context ?: new SimpleContext;
        }

        return $this->context;
    }
1090587
public static function fromFile(string $file, string $locale): Resource
    {
        if (!is_file($file)) {
            throw new \InvalidArgumentException("$file is not a file");
        }
        
        $contents = file_get_contents($file);
        
        if ($contents === false) {
            throw new \RuntimeException("Error reading file at $file.");
        }
        
        return static::fromString($contents, $locale);
    }
897639
public function canCreate($member = null, $context = array())
    {
        return $this->Action()->WorkflowDef()->canCreate($member, $context);
    }
1251638
final public function make(string $alias, array $parameters = [], string $context = null)
    {
        if (!isset($this->bindings[$alias])) {
            //No direct instructions how to construct class, make is automatically
            return $this->autowire($alias, $parameters, $context);
        }

        $binding = $this->bindings[$alias];

        if (is_object($binding)) {
            //When binding is instance, assuming singleton
            return $binding;
        }

        if (is_string($binding)) {
            //Binding is pointing to something else
            return $this->make($binding, $parameters, $context);
        }

        if ($binding[0] === $alias) {
            $instance = $this->autowire($alias, $parameters, $context);
        } else {
            $instance = $this->evaluateBinding($alias, $binding[0], $parameters, $context);
        }

        if ($binding[1]) {
            //Indicates singleton
            $this->bindings[$alias] = $instance;
        }

        return $instance;
    }
682595
@Override
	public InputStream createResourceAsStream(GeneratorContext context) {

		InputStream is = null;
		if (FileNameUtils.hasImageExtension(context.getPath())) {
			is = helper.createStreamResource(context);
		}

		return is;
	}
581337
public static function Create( $context, $node )
	{
		if ( is_a( $node, __CLASS__ ) )
		{
			/**
			 * @var PathStep $res
			 */
			$res = $node;
			return $res;
		}

		if ( $node instanceof PathExprNode )
		{
			/**
			 * @var PathExprNode $pathExpr
			 */
			$pathExpr = $node;
			return $pathExpr->FirstStep;
		}

		return PathStep::fromNode( AbstractNode::Create( $context, $node ) );
	}
660431
public function rename($newFilename, $context = null)
    {
        $params[] = $this->getRealPath();
        $params[] = dirname($this->getRealPath()) . DIRECTORY_SEPARATOR . $newFilename;
        $params[] = $context;

        return call_user_func_array('rename', $params);
    }
1144317
public function assemble(ContextInterface $context)
    {
        try {
            $interfaceAssembler = new InterfaceAssembler(ResultInterface::class);
            if ($interfaceAssembler->canAssemble($context)) {
                $interfaceAssembler->assemble($context);
            }
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }