amnuts / opcache-gui

A clean, effective and responsive interface for Zend OPcache
1.21k stars 197 forks source link

split class and html render #49

Closed llaville closed 3 years ago

llaville commented 4 years ago

Hello,

I'd like that the OpcacheGui\OpcacheService class and html render are split in two different files. That will allow to re-used the class with another renderer than the default provided, and include it in our custom design.

Currently i must to the trick as follow :

ob_start();
require_once 'vendor/amnuts/opcache-gui/index.php';
$html = ob_get_clean();

// specify your options (see next section)
$options = [/* ... */];

// setup the class
$opcache = \OpcacheGui\OpCacheService::init($options);

$version = $opcache->getData()['version'];
$overview = $opcache->getData()['overview'];
$files = $opcache->getData()['files'];

Thanks Laurent

amnuts commented 4 years ago

Hi @llaville, that is something I'm planning to do but need to make sure that the fully built index.php is still available, because one of the good things about this gui is that it's one file only to get up and running. But one day it'll be done. 😀

amnuts commented 4 years ago

I've tidied this up in the v3 branch - plus I've changed the namespace of the class.

I haven't completed all the work I want to do on it yet, but it's a better split if you just want to use the class to integrate into your own setup, or if you want to compile to a single index.php file (by using composer build).

If you want to check it out and see if works for you, please feel free and drop any feedback. Just remember that it's not quite complete yet.

llaville commented 4 years ago

Hello @amnuts I've just tested the branch v3, and the new code LGTM. Only test the standalone class Amnuts\Opcache\Service like that in a Symfony Controller :

namespace App\Controller;

use Amnuts\Opcache\Service;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class ToolsController extends AbstractController
{
    /**
     * @Route("/opcache", name="opcache")
     */
    public function opcacheGui()
    {
        // custom options - empty if we used defaults
        $options = [];

        $opcache = new Service($options);

        return $this->render('default/opcache.html.twig', [
            'opcache_gui_html' => $opcache->getData()['version'],
            'opcache_overview' => $opcache->getData()['overview'],
            'opcache_files' => $opcache->getData()['files'],
        ]);
    }
}

Thanks a lot to do the work !

amnuts commented 3 years ago

I've now merged into master and released version 3.0.0, which includes better separation between the PHP and JavaScript as mentioned above.