Creates output for resources

@param array|null $resources
@return string|null
@throws \Laranix\Support\Exception\InvalidInstanceException
334503
protected function createResourceOutput(?array $resources) : ?string
    {
        if (empty($resources)) {
            return null;
        }

        $output = [];

        foreach ($resources as $resource) {
            $str = <<<'SCRIPTSTR'
<script type="application/javascript" src="{{url}}"{{async}}{{defer}}{{integ}}{{cors}}></script>
SCRIPTSTR;

            $output[] = Str::format($str, [
                'url'   => $this->parseOutputUrl($resource->url, $resource->filename),
                'async' => $resource->async ? ' async' : null,
                'defer' => $resource->defer ? ' defer' : null,
                'integ' => $resource->integrity !== null ? ' integrity="' . $resource->integrity . '"' : null,
                'cors'  => $resource->crossorigin !== null ? ' crossorigin="' . $resource->crossorigin . '"' : null,
            ]);
        }

        return implode("\n", $output);
    }
201411
protected function getResourceName($resource)
    {
        if ($resource instanceof ResourceInterface) {
            $resource = $resource->getName();
        }

        if (false === is_string($resource)) {
            throw new InvalidArgumentException(
                'Resource argument must be string or an object implemented "Rad\Authorization\Rbac\ResourceInterface".'
            );
        }

        return $resource;
    }
122504
private function generateResourceName($resource)
    {
        if (false === $this->pluralize) {
            return $resource;
        }

        return $this->inflector->pluralize($resource);
    }
55905
private function getResourceData($resource)
    {
        $data = false;
        if(!is_null($resource) && $resource->exists()) {
            $resourceTypes = array_keys($resource->getTypes());
            $data = [
                'uri'        => $resource->getUri(),
                'classUri'   => $resourceTypes[0],
                'label'      => $resource->getLabel(),
                'type'       => 'instance'
            ];
        }
        return $data;
    }
716261
protected function loadResource($resources, $parent = null)
    {
        if (!is_array($resources) && !($resources instanceof \Traversable)) {
            throw new \InvalidArgumentException('Resources argument must be traversable: ' . print_r($resources, true));
        }

        foreach ($resources as $key => $value) {
            if ($value instanceof ResourceInterface) {
                $key = $value;
            } elseif (is_string($key)) {
                $key = new GenericResource($key);
            } elseif (is_int($key)) {
                $key = new GenericResource($value);
            }

            if (is_array($value) || ($value instanceof \Traversable)) {
                $this->acl->addResource($key, $parent);
                $this->loadResource($value, $key);
            } elseif (!$this->acl->hasResource($key)) {
                $this->acl->addResource($key, $parent);
            }
        }
    }
1129273
public function generate(Resource $resource, array $data = array()) : void
    {
        $filepath  = $resource->getSrcFilename();
        $name      = $data['name'];
        $arguments = $data['arguments'];

        $argString = $this->argumentBuilder->buildFrom($arguments);

        $values = array('%name%' => $name, '%arguments%' => $argString);
        if (!$content = $this->templates->render('method', $values)) {
            $content = $this->templates->renderString(
                $this->getTemplate(), $values
            );
        }

        $code = $this->filesystem->getFileContents($filepath);
        $code = preg_replace('/}[ \n]*$/', rtrim($content) ."\n}\n", trim($code));
        $this->filesystem->putFileContents($filepath, $code);

        $this->io->writeln(sprintf(
                "\n<info>Method <value>%s::%s()</value> has been created.</info>",
                $resource->getSrcClassname(), $name
            ), 2);
    }
109425
public function serialize($resource, OutputStream $out): OutputStream
    {
        $out->write((string) $resource);
        return $out;
    }
256603
protected function _loadResource($resource) {
        return $this->cache([__METHOD__, $resource], function() use ($resource) {
            $data = $this->getLocaleBundle()->loadResource(null, $resource);

            if ($parent = $this->getParentLocale()) {
                $data = array_merge(
                    $parent->getLocaleBundle()->loadResource(null, $resource),
                    $data
                );
            }

            return $data;
        });
    }
215228
protected function executeOnMulitpleResources(array $resources): array
    {
        $results = [];

        foreach ($resources as $resource) {
            $results[$resource->name()] = $this->executeOn($resource);
        }

        return $results;
    }
419958
public function getActionsByResource($resource)
    {
        if (!isset($this->resources[$resource])) {
            return null; // no resource found
        }

        $actions = array();
        foreach ($this->resources[$resource] as $action => $path) {
            $actions[] = $action;
        }

        return $actions;
    }
1362488
private function generateRouteName(array $resources)
    {
        $routeName = '';
        foreach ($resources as $resource) {
            if (null !== $resource) {
                $routeName .= '_'.basename($resource);
            }
        }

        return $routeName;
    }
124473
public function getFromArray(
        array $resources
    ) {
        $root = (empty($resources[0])) ? null : $resources[0];
        $siteId = (empty($resources[1])) ? null : $resources[1];
        $pages = (empty($resources[2])) ? null : $resources[2];
        $pageType = (empty($resources[3])) ? null : $resources[3];
        $pageName = (empty($resources[4])) ? null : $resources[4];

        return $this->get(
            $root,
            $siteId,
            $pages,
            $pageType,
            $pageName
        );
    }
740715
protected function _outputHandle($output=null)
    {
        if ($output === null) {
            // do nothing
        } elseif ($output instanceof ResponseInterface) {
            $this->response = $output;
        } elseif ($output) {
            if (is_scalar($output)) {
                $this->response = $this->renderText($output);
            } elseif (is_array($output)) {
                $this->response = $this->renderJson($output);
            } elseif ($output instanceof Collection) {
                $this->response = $this->renderJson($output->all());
            }
        }
        
        if ($data = $this->getRenderBuffer()) {
            $this->response->write($data);
        }
        
        return $this->response;
    }
1317660
public function on($resource)
    {
        if (!$this->runnable()) {
            throw new \InvalidArgumentException('Command execution is restricted.');
        }

        if (is_array($resource)) {
            return $this->executeOnMulitpleResources($resource);
        }

        return $this->executeOn($resource);
    }
1024034
public static function createFromResource($resource): Stream
    {
        if (!\is_resource($resource))
        {
            throw new \InvalidArgumentException('Stream must be a resource');
        }

        $obj           = new self();
        $obj->stream   = $resource;
        $meta          = stream_get_meta_data($obj->stream);
        $obj->seekable = $meta['seekable'];
        $obj->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
        $obj->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
        $obj->uri      = $obj->getMetadata('uri');

        return $obj;
    }
663280
public function getResource($resource)
    {
        if (array_key_exists($resource, $this->cache)) {
            return $this->cache[$resource];
        }

        if (!array_key_exists($resource, $this->resources)) {
            throw new ResourceNotImplemented($resource);
        }

        $params = $this->resources[$resource];
        $instance = $params['instance'];

        if (is_null($instance)) {
            $class = $params['class'];

            $instance = new $class($this);
        }

        return $this->cache[$resource] = $instance;
    }
1229341
protected function generatePaginationData($resources)
    {
        $paginationData = [
            'total'             => $resources->total(),
            'per_page'          => $resources->perPage(),
            'current_page'      => $resources->currentPage(),
            'last_page'         => $resources->lastPage(),
            'previous_page_url' => $resources->previousPageUrl(),
            'next_page_url'     => $resources->nextPageUrl(),
            'from'              => $resources->firstItem(),
            'to'                => $resources->lastItem()
        ];

        return $paginationData;
    }