├── .gitignore ├── index.html ├── package.json ├── LICENSE ├── README.md └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | php 3 | project 4 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-symfony", 3 | "version": "0.1.0", 4 | "description": "A Symfony application inside Electron.", 5 | "main": "main.js", 6 | "scripts": { 7 | "start": "electron main.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/garak/electron-symfony.git" 12 | }, 13 | "keywords": [ 14 | "Electron", 15 | "Symfony", 16 | "php" 17 | ], 18 | "author": "Massimiliano Arione", 19 | "license": "MIT", 20 | "homepage": "https://massimilianoarione.it", 21 | "devDependencies": { 22 | "electron": "^1.3", 23 | "gulp-connect-php": "^0.0.8" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Massimiliano Arione 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Electron Symfony 2 | ================ 3 | 4 | This simple project allows to run a Symfony application inside Electron. 5 | It's simply a default Electron build (see https://github.com/electron/electron-quick-start) 6 | with gulp-connect-php, needed to run PHP. 7 | Indeed, you can use this to run any PHP application, not just a Symfony one. 8 | 9 | You need npm installed on your machine to get this working. 10 | 11 | Installation 12 | ------------ 13 | 14 | * clone this repository 15 | * run `npm install` 16 | * put your Symfony project under `project` directory. If you prefer a different name, just edit `main.js` accordingly 17 | * for portability, you should put a php static installation under `php` directory. If want to just give a try, 18 | you could use your already system-wide installed PHP. In this case, edit `main.js` and point the PHP path 19 | to your actual path (in the `bin` option of `php.server()`). E.g., for Ubuntu the path is `usr/bin/php` 20 | * for portability, you should use a sqlite database. If you want to just give a try, you can use a "classic" database 21 | (like MySql) 22 | * if your Symfony project is using assets from a CDN, you must copy such assets in your local folders, since 23 | CDN assets are not working inside electron. 24 | For example, if you're using something like `//code.jquery.com/jquery-2.2.3.js`, you need to 25 | downalod `jquery-2.2.3.js` file and put it under `web/js` directory, then adjust your templates accordingly. 26 | * Also, if you use jquery, take a look to [this issue](http://stackoverflow.com/a/37480521/369194) 27 | 28 | Execution 29 | --------- 30 | 31 | Run `npm start` 32 | 33 | The following screenshot shows an example of Symfony Standard Edition running with DevTools open: 34 | 35 | ![screenshot](https://cloud.githubusercontent.com/assets/179866/15629379/f3c89fca-2517-11e6-9455-9ba87abeba54.png) 36 | 37 | If you want to use DevTools, uncomment the relevant line in `main.js` 38 | 39 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const electron = require('electron'); 3 | const app = electron.app; // Module to control application life. 4 | const BrowserWindow = electron.BrowserWindow; // Module to create native browser window. 5 | 6 | // php ruleZ 7 | var path = require("path"); 8 | var php = require("gulp-connect-php"); 9 | php.server({ 10 | port: 8088, 11 | base: path.resolve(__dirname) + '/project/web', 12 | // this is now pointing to a possible local installation of php, that is best for portability 13 | // feel free to change with a system-wide installed php, that is dirty & working, but less portable 14 | bin: path.resolve(__dirname) + "/php/bin/php" 15 | }); 16 | 17 | 18 | // Keep a global reference of the window object, if you don't, the window will 19 | // be closed automatically when the JavaScript object is garbage collected. 20 | let mainWindow; 21 | 22 | // Quit when all windows are closed. 23 | app.on('window-all-closed', function () { 24 | // On OS X it is common for applications and their menu bar 25 | // to stay active until the user quits explicitly with Cmd + Q 26 | if (process.platform != 'darwin') { 27 | app.quit(); 28 | } 29 | }); 30 | 31 | // This method will be called when Electron has finished 32 | // initialization and is ready to create browser windows. 33 | app.on('ready', function() { 34 | // Create the browser window. 35 | mainWindow = new BrowserWindow({width: 900, height: 600}); 36 | 37 | // and load the app's front controller. Feel free to change with app_dev.php 38 | mainWindow.loadURL("http://127.0.0.1:8088/app_dev.php"); 39 | 40 | // Uncomment to open the DevTools. 41 | //mainWindow.webContents.openDevTools(); 42 | 43 | // Emitted when the window is closed. 44 | mainWindow.on('closed', function () { 45 | // Dereference the window object, usually you would store windows 46 | // in an array if your app supports multi windows, this is the time 47 | // when you should delete the corresponding element. 48 | mainWindow = null; 49 | }); 50 | }); 51 | --------------------------------------------------------------------------------