Returns a loader according to the given format.

@param string $format
@throws \RuntimeException
@return LoaderInterface
425094
public function getLoader($format)
    {
        $loader = null;
        $i = 0;
        $ids = array_keys($this->loaderIds);

        while ($i < count($ids) && null === $loader) {
            if (in_array($format, $this->loaderIds[$ids[$i]])) {
                $loader = $this->container->get($ids[$i]);
            }
            $i++;
        }

        if (!($loader instanceof LoaderInterface)) {
            throw new \RuntimeException(sprintf('No loader found for "%s" format.', $format));
        }

        return $loader;
    }
945026
protected static final function get_class_name($format) {
        global $CFG;
        static $classnames = array('site' => 'format_site');
        if (!isset($classnames[$format])) {
            $plugins = core_component::get_plugin_list('format');
            $usedformat = self::get_format_or_default($format);
            if (isset($plugins[$usedformat]) && file_exists($plugins[$usedformat].'/lib.php')) {
                require_once($plugins[$usedformat].'/lib.php');
            }
            $classnames[$format] = 'format_'. $usedformat;
            if (!class_exists($classnames[$format])) {
                require_once($CFG->dirroot.'/course/format/formatlegacy.php');
                $classnames[$format] = 'format_legacy';
            }
        }
        return $classnames[$format];
    }
202709
static public function getReaderByFormat( $format )
    {
        if ( !isset( self::$readHandlers[$format] ) )
        {
            throw new ezcDbSchemaUnknownFormatException( $format, 'read' );
        }
        return self::$readHandlers[$format];
    }
465080
public function render($format)
    {
        if (!isset($this->formatters[$format])) {
            throw new \InvalidArgumentException(
                sprintf("Unable to find a formatter service for format '%s'.", $format)
            );
        }

        $formatter = $this->formatters[$format];
        $formatter->setFeed($this);

        return $formatter->render();
    }
1014072
public function setFormat($format = null)
    {
        if ( ! is_null($format)) {
            self::checkFormat($format);
            $this->format = $format;
        }

        return $this;
    }
889931
public function setFormat($format)
    {
        if ($this->app['debug']) {
            if (false === is_string($format)) {
                throw new \InvalidArgumentException(sprintf('Format must be a string, got "%s".', is_object($format) ? get_class($format) : gettype($format)));
            }

            if (false === strpos($format, '%key%')) {
                throw new \InvalidArgumentException(sprintf('Format must contain "%%key%%", got "%s".', $format));
            }

            if (false === strrpos($format, '.')) {
                throw new \InvalidArgumentException(sprintf('Format missing extension, got "%s".', $format));
            }
        }

        $this->format = $format;

        if (strlen($format) > 5 && '.dist' === substr($format, -5)) {
            $format = substr($format, strrpos($format, '.', -6) + 1);
        } else {
            $format = substr($format, strrpos($format, '.') + 1);
        }

        switch ($format) {
            case 'json':
            case 'json.dist':
                $this->loader = new JsonLoader();
                break;
            case 'yml':
            case 'yml.dist':
            case 'yaml':
            case 'yaml.dist':
                if (false === class_exists('Symfony\\Component\\Yaml\\Yaml')) {
                    throw new \RuntimeException('Missing Symfony Yaml component.');
                }

                $this->loader = new YamlLoader();
                break;
            case 'php':
            case 'php.dist':
                $this->loader = new PHPLoader();
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Unsupported file format "%s".', $format));
        }

        $this->flushAll();

        return $this;
    }
205288
public function getFormatInstance($format = null)
    {
        $format = $format ?: $this->format;

        if (!($format instanceof FormatInterface)) {
            if (!isset($this->formats[$format])) {
                $event = new NewFormatEvent($this, new $format($this));
                $this->trigger($event);
                $this->formats[$format] = $event->getFormat();
            }

            $format = $this->formats[$format];
        }

        return $format;
    }
1072826
public function get($format)
    {
        if ('plain' == $format || 'string' == $format) {
            return $this->makePlain();
        }
        if ('json' == $format) {
            return $this->makeJson();
        }

        return json_decode($this->response, true);
    }
513268
public function format($format)
    {
        if (!$this->image) {
            $this->image();
        }

        $this->format = $format;

        return $this;
    }
417052
protected function getLoader(Console\Input\InputInterface $input)
    {
        $inputFile = $input->getOption('input');

        if ($input->getOption('edit')) {
            if ($inputFile !== $this->getDefinition()->getOption('input')->getDefault()) {
                throw new \InvalidArgumentException("You cannot specify both --edit (-e) and --input (-i)");
            }
            $inputFile = $input->getOption('edit');
        }

        if ($inputFile === '-') {
            $inputFile = 'php://stdin';
            if (!($inputFormat = $input->getOption('input-format'))) {
                $inputFormat = 'json';
            }
        } elseif (!($inputFormat = $input->getOption('input-format'))) {
            // guess type based on extension.
            $inputFormat = Loader\Factory::guessType($inputFile);
        }

        $input->setOption('input-format', $inputFormat);

        $loader = Loader\Factory::createLoader($inputFormat);
        $inputStream = fopen($inputFile, 'r');
        if (!$inputStream) {
            throw new \RuntimeException("Could not open input");
        }

        if ($input->getOption('buffer') || $input->getOption('edit')) {
            $tmp = fopen('php://memory', 'rw');
            fwrite($tmp, stream_get_contents($inputStream));
            fseek($tmp, 0);
            $inputStream = $tmp;
        }
        $loader->setInput($inputStream);
        return $loader;
    }
696438
public function get($format)
    {
        switch ($format) {
            case 'json':
                return $this->toJson();
                break;
            case 'serialize':
                return $this->serialize();
                break;
            case 'array':
                return $this->toArray();
                break;
            case 'xml':
                return $this->toXml();
                break;
            default:
                return $this;
        }
    }
1279646
public function dateTime(string $format = DateTime::DISPLAY_FORMAT) : DateTimeFieldBuilder
    {
        return new DateTimeFieldBuilder($this->field->type(new DateTimeType($format)));
    }
779347
public function getLoader($filter)
    {
        $config = $this->filterConfig->get($filter);

        $loaderName = empty($config['data_loader']) ? $this->defaultLoader : $config['data_loader'];

        if (!isset($this->loaders[$loaderName])) {
            throw new \InvalidArgumentException(sprintf(
                'Could not find data loader "%s" for "%s" filter type',
                $loaderName,
                $filter
            ));
        }

        return $this->loaders[$loaderName];
    }
1059224
public function getLoader(): LoaderInterface
    {
        if (!isset($this->i__loader)) {
            $this->i__loader = new DelegateLoader();
        }

        return $this->i__loader;
    }
1292748
public function getParser(FormatInterface $format)
    {
        switch ($format->getType()) {
            case 'csv':
                if ($format instanceof CsvFormatInterface) {
                    return new CsvParser($format);
                } else {
                    throw new InvalidArgumentException(
                        "Format indicates it is csv but does not implement CsvFormatInterface"
                    );
                }

            // fallthrough
            case 'json':
                if ($format instanceof JsonFormatInterface) {
                    return new JsonParser($format);
                } else {
                    throw new InvalidArgumentexception(
                        "Format indicates it is json but does not implement JsonFormatInterface"
                    );
                }

            // fallthrough
            default:
                throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown");
        }
    }
829654
private function getResourceLookup($format)
    {
        if(in_array($format, self::$formats)){
            if(!isset($this->lookups)){
                $this->lookups = [
                    'list' => $this->getServiceManager()->get(ListResourceLookup::SERVICE_ID),
                    'tree' => $this->getServiceManager()->get(TreeResourceLookup::SERVICE_ID)
                ];
            }
            return $this->lookups[$format];
        }
        return null;
    }
546496
public function getApiURL($format = null)
    {
        $apiUrl = str_replace(['.'.$this->format, '?limit=0'], '', $this->apiURL);
        return $apiUrl.(empty($format) ? '' : '.'.$format );
    }