1. Go to this page and download the library: Download jeremeamia/xstatic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeremeamia / xstatic example snippets
// Include the Composer autoloader, of course
tatic\ProxyManager;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
// Setup your Silex app/container
$app = new Application;
$app->register(new TwigServiceProvider, array(
'twig.path' => __DIR__ . '/templates',
));
$app['db'] = function () {
return new PDO('mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass');
};
$app->get('/', 'MyApp\Controller\Home::index'); // Routes "/" to a controller object
// Setup and enable XStatic
$acclimator = new ContainerAcclimator();
$proxyManager = new ProxyManager($acclimator->acclimate($app));
$proxyManager->addProxy('View', 'MyApp\Proxy\Twig');
$proxyManager->addProxy('DB', 'MyApp\Proxy\Pdo');
$proxyManager->enable(ProxyManager::ROOT_NAMESPACE_ANY);
// Run the app
$app->run();
namespace MyApp\Proxy
{
use XStatic\StaticProxy;
class Pdo extends StaticProxy
{
public static function getInstanceIdentifier()
{
return 'db';
}
}
class Twig extends StaticProxy
{
public static function getInstanceIdentifier()
{
return 'twig';
}
}
}
namespace MyApp\Controller;
class Home
{
public function index()
{
// It just works!
View::render('home.index', array(
'articles' => DB::query('SELECT * FROM articles')
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.