A Silex skeleton project.
vagrant up
vagrant ssh
cd /var/www
nvm install v6.9.1
npm run watch
The site will be available at http://localhost:8081
from your host machine.
Config files are located in config/
.
The configuration provider uses the environment to determine which config file to load.
The environment is determined using the APPLICATION_ENV
environment variable, but defaults to vagrant
.
For local development, juse copy the config/local-sample.yml
file to config/local.yml
and update values therein.
npm is the package manager used for installing build tools as well as third-party dependencies. Configuration is located in package.json
.
Run npm install
to download required tools and modules.
JavaScript files are located in app/assets/js/
.
The main entry point for the app is app/assets/js/main.js
.
Scripts are compiled using webpack with the babel plugin.
An example module for your reference is located at app/assets/js/modules/module.js
.
SASS is used for extending CSS with new features and compiles into CSS.
The SASS files are located at app/assets/scss
, and the main SASS file is app/assets/scss/main.scss
.
Xylophone uses the Symfony Console Component to perform tasks.
Run app/zylophone
to see a list of available commands.
To create your own commands, extend the Knp\Command\Command
class.
An example command is located at src/Command/NamespaceCommand.php
.
Migrations are stored in the src/Resource/Migration
folder. Run ./app/xylophone
in the app root folder to view migration commands:
migrations
migrations:diff Generate a migration by comparing your current database to your mapping information.
migrations:execute Execute a single migration version up or down manually.
migrations:generate Generate a blank migration class.
migrations:migrate Execute a migration to a specified version or the latest available version.
migrations:status View the status of a set of migrations.
migrations:version Manually add and delete migration versions from the version table.
The abstract query repository can be found in src/QueryRepository/
. Extend it to create your own repositories. Then use them like so:
$myRepo = new Xylophone\QueryRepository\MyQueryRepo($app['db']);
$results = $myRepo->myMethod();
Add your route definitions to app/app.php
.
There is a home route there for your reference:
$app->get('/', 'Xylophone\Controller\HomeController::index')
->bind('home');
This route will direct the uri /
to the index method of the 'Xylophone\Controller\HomeController' class. The bind command will allow you to reference this route in your templates like this: {{ path('home') }}
.
Check out the official docs for more info.
If you want to cache a response, simply add the Cache-Control
header to something like s-maxage=3600, public
. The standard setup will use the cache folder to store response and serve responses from there without having to bootstrap the app.
Twig templates should be placed in frontend/twig
. Render a template using $app['twig']->render('filename.html.twig', ['mykey' => 'myvalue']);
.
Global Variables
debug Boolean containing the application debug state
js_filename dynamically revisioned name of the compiled JavaScript modules
css_filename dynamically revisioned name of the compiled SASS files
Put your phpunit tests in the tests/
folder. Extend the \Xylophone\Test\AbstractTestCase
class in order to have access to things like the web crawler. Here's an example:
use \Xylophone\Test\AbstractTestCase;
class SomeTest extends AbstractTestCase
{
public function testSomething()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Hello World")'));
}
}
Check out the official documentation for more info.
The logging service is available by using $app['monolog']. The log files reside in app/logs/
. Here are some examples:
$app['monolog']->info('script started');
$app['monolog']->error('Failed to call function', ['key', $value]);