Controller/Adminhtml/FastlyCdn/CustomSnippet/GetCustomSnippet.php
public function execute()
    {
        $result = $this->resultJson->create();

        try {
            $snippet = $this->getRequest()->getParam('snippet_id');

            $read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
            $snippetPath = $read->getRelativePath(Config::CUSTOM_SNIPPET_PATH . $snippet);

            if ($read->isExist($snippetPath)) {
                $explodeId = explode('.', $snippet, -1);
                $snippetParts = explode('_', $explodeId[0], 3);
                $type = $snippetParts[0];
                $priority = $snippetParts[1];
                $name = $snippetParts[2];
                $content = $read->readFile($snippetPath);
            } else {
                throw new LocalizedException(__('Custom snippet not found.'));
            }

            return $result->setData([
                'status'    => true,
                'type'      => $type,
                'priority'  => $priority,
                'name'      => $name,
                'content'   => $content,
                'original'  => $snippet
            ]);
        } catch (\Exception $e) {
            return $result->setData([
                'status'    => false,
                'msg'       => $e->getMessage()
            ]);
        }
    }
public function execute()
    {
        $result = $this->resultJson->create();

        try {
            $snippet = $this->getRequest()->getParam('snippet_id');

            $read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
            $snippetPath = $read->getRelativePath(Config::CUSTOM_SNIPPET_PATH . $snippet);

            if ($read->isExist($snippetPath)) {
                $explodeId = explode('.', $snippet, -1);
                $snippetParts = explode('_', $explodeId[0], 3);
                $type = $snippetParts[0];
                $priority = $snippetParts[1];
                $name = $snippetParts[2];
                $content = $read->readFile($snippetPath);
            } else {
                throw new LocalizedException(__('Custom snippet not found.'));
            }

            return $result->setData([
                'status'    => true,
                'type'      => $type,
                'priority'  => $priority,
                'name'      => $name,
                'content'   => $content,
                'original'  => $snippet
            ]);
        } catch (\Exception $e) {
            return $result->setData([
                'status'    => false,
                'msg'       => $e->getMessage()
            ]);
        }
    }
public function execute ( ) { $ result = $ this -> resultJson -> create ( ) ; try { $ snippet = $ this -> getRequest ( ) -> getParam ( 'snippet_id' ) ; $ read = $ this -> filesystem -> getDirectoryRead ( DirectoryList :: VAR_DIR ) ; $ snippetPath = $ read -> getRelativePath ( Config :: CUSTOM_SNIPPET_PATH . $ snippet ) ; if ( $ read -> isExist ( $ snippetPath ) ) { $ explodeId = explode ( '.' , $ snippet , - 1 ) ; $ snippetParts = explode ( '_' , $ explodeId [ 0 ] , 3 ) ; $ type = $ snippetParts [ 0 ] ; $ priority = $ snippetParts [ 1 ] ; $ name = $ snippetParts [ 2 ] ; $ content = $ read -> readFile ( $ snippetPath ) ; } else { throw new LocalizedException ( __ ( 'Custom snippet not found.' ) ) ; } return $ result -> setData ( [ 'status' => true , 'type' => $ type , 'priority' => $ priority , 'name' => $ name , 'content' => $ content , 'original' => $ snippet ] ) ; } catch ( \ Exception $ e ) { return $ result -> setData ( [ 'status' => false , 'msg' => $ e -> getMessage ( ) ] ) ; } }
Get custom snippet

@return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
Get custom snippet