Skip to content

Commit

Permalink
Jelix scripts generates jelix-*.json files instead of module.xml or p…
Browse files Browse the repository at this point in the history
…roject.xml
  • Loading branch information
laurentj committed May 14, 2015
1 parent df5ad4e commit b6062dd
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 238 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
What is Jelix?
==============

Jelix is an open-source framework for PHP5.
Jelix is an open-source framework for PHP 5.5 and higher.

It has a modular and extensible architecture. Applications based on Jelix are made
with modules, which allow to reuse features in several projects.

For more informations, read http://jelix.org/articles/en/features

About stable versions and branches
==============================
==================================

**WARNING**: many changes occurs in the master branch, because of a "namespacification"
which is not finished yet. So API may change or may be broken (even if we try to no do it)
Expand Down Expand Up @@ -41,10 +41,7 @@ package dependency:
"require": {
"php": ">=5.4",
"jelix/jelix": "dev-master"
},
"repositories" : [
{ "type": "composer", "url":"http://packages.jelix.org" }
]
}
}
```

Expand All @@ -60,7 +57,7 @@ Documentation and community
========================

[The documentation](http://docs.jelix.org) is not updated yet with all changes since the
release of Jelix 1.6.x. But it should be ok for most of things.
release of Jelix 1.7.x. But it should be ok for most of things.

You can ask your questions [on the forum](http://jelix.org/forums/forum/cat/2-english) or
on our IRC Channel, #jelix, on the irc.freenode.net network.
Expand Down
1 change: 0 additions & 1 deletion UPGRADE-TO-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Migration
Here are instructions to migrate your Jelix application from Jelix 1.6 to the dev-master
version.


## Composerify your application


Expand Down
4 changes: 4 additions & 0 deletions build/manifests/jelix-deprecated-dev.mn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ cd lib/jelix-scripts/templates
template.tpl
zone.tpl
locales.tpl
project.xml.tpl

cd lib/jelix-scripts/templates/module
module.xml.tpl

cd lib/jelix-scripts/templates/var/config/
dbprofils.ini.php.tpl
Expand Down
4 changes: 2 additions & 2 deletions build/manifests/jelix-scripts.mn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cd lib/jelix-scripts/includes
JelixScriptCommandConfig.class.php
scripts.inc.php
cd lib/jelix-scripts/templates
project.xml.tpl
jelix-app.json.tpl
application.init.php.tpl
cmd.php.tpl
composer.json.tpl
Expand All @@ -63,7 +63,7 @@ cd lib/jelix-scripts/templates/module/
locales.tpl
main.tpl.tpl
masteradminmenu.listener.php.tpl
module.xml.tpl
jelix-module.json.tpl
template.tpl
urls.xml.tpl
zone.tpl
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=5.3.3",
"php": ">=5.5",
"phpmailer/phpmailer": "5.2.9",
"tecnick.com/tcpdf": "6.0.*",
"mrclay/minify": "2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/Jelix/Core/Config/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Jelix\Core\Config;

/**
* Autoloader for informations stored in module.xml files
* Autoloader for informations stored in jelix-module.json or module.xml files
*/
class Autoloader {

Expand Down
2 changes: 1 addition & 1 deletion lib/Jelix/Core/Config/defaultconfig.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
; dao_db_profile = ""

; list of selectors of classes to load before the session_start
; @deprecated please use autoload configuration in module.xml files instead
; @deprecated please use autoload configuration in jelix-app.json/module.xml files instead
loadClasses=

[forms]
Expand Down
43 changes: 43 additions & 0 deletions lib/Jelix/Core/Infos/AppInfos.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,47 @@ public function getEntryPointInfo($name) {

return null;
}

public function addEntryPointInfo($fileName, $configFileName, $type) {
$this->entrypoints[$fileName] = $entrypoint = array('file'=>$fileName,
'config'=>$configFileName, 'type'=>$type);
if ($this->isXmlFile()) {
$doc = new \DOMDocument();

if (!$doc->load($this->path.'project.xml')) {
throw new Exception("addEntryPointInfo: cannot load project.xml");
}
if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE.'project/1.0'){
throw new Exception("addEntryPointInfo: bad namespace in project.xml");
}

$elem = $doc->createElementNS(JELIX_NAMESPACE_BASE.'project/1.0', 'entry');
$elem->setAttribute("file", $fileName);
$elem->setAttribute("config", $configFileName);
$elem->setAttribute("type", $type);

$ep = $doc->documentElement->getElementsByTagName("entrypoints");
if (!$ep->length) {
$ep = $doc->createElementNS(JELIX_NAMESPACE_BASE.'project/1.0', 'entrypoints');
$doc->documentElement->appendChild($ep);
$ep->appendChild($elem);
}
else {
$ep->item(0)->appendChild($elem);
}

$doc->save($this->path.'project.xml');
}
else {
$json = @json_decode(file_get_contents($this->path.'jelix-app.json'), true);
if (!is_array($json)) {
throw new \Exception($this->path ."jelix-app.json is not a JSON file");
}
if (!isset($json['entrypoints'])) {
$json['entrypoints'] = array();
}
$json['entrypoints'][] = $entrypoint;
file_put_contents($this->path.'jelix-app.json', json_encode($json));
}
}
}
2 changes: 1 addition & 1 deletion lib/Jelix/Installer/ModuleInstallLauncher.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function getUpgraders(EntryPoint $ep) {
continue;
}
if (\jVersionComparator::compareVersion($this->moduleInfos->version, $version) < 0 ) {
// we don't execute upgraders having a version higher than the version indicated in the module.xml
// we don't execute upgraders having a version higher than the version indicated in the module.xml/jelix-module.json
continue;
}
$foundVersion = $version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function atStart($config) {

$config->sessions['_class_to_load'] = array();
if ($config->sessions['loadClasses'] != '') {
trigger_error("Configuration: loadClasses is deprecated, use instead autoload configuration in module.xml files", E_USER_NOTICE);
trigger_error("Configuration: loadClasses is deprecated, use instead autoload configuration in jelix-module.json or module.xml files", E_USER_NOTICE);
$list = preg_split('/ *, */',$config->sessions['loadClasses']);
foreach($list as $sel) {
if(preg_match("/^([a-zA-Z0-9_\.]+)~([a-zA-Z0-9_\.\\/]+)$/", $sel, $m)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function compile($aSelector) {
$this->createUrlContent = "<?php \nif (jApp::config()->compilation['checkCacheFiletime'] &&( \n";
$this->createUrlContent .= "filemtime('".$sourceFile.'\') > '.filemtime($sourceFile);
$this->createUrlContentInc = '';
$this->readProjectXml();
$this->readAppInfos();
$this->modulesPath = jApp::getAllModulesPath();

// for an app on a simple http server behind an https proxy, we shouldn't check HTTPS
Expand Down Expand Up @@ -308,22 +308,20 @@ public function compile($aSelector) {
return true;
}

protected function readProjectXml() {
$xml = simplexml_load_file(jApp::appPath('project.xml'));
foreach ($xml->entrypoints->entry as $entrypoint) {
$file = (string)$entrypoint['file'];
if (substr($file, -4) != '.php')
$file.='.php';
$configFile = (string)$entrypoint['config'];
$this->entryPoints[$file] = $configFile;
protected function readAppInfos() {
$infos = new \Jelix\Core\Infos\AppInfos(jApp::appPath());
foreach ($infos->entrypoints as $file => $entrypoint) {
$this->entryPoints[$file] = $entrypoint['config'];
}
}

protected function getEntryPointConfig($entrypoint) {
if (substr($entrypoint, -4) != '.php')
if (substr($entrypoint, -4) != '.php') {
$entrypoint.='.php';
if (!isset($this->entryPoints[$entrypoint]))
throw new Exception('The entry point "'.$entrypoint.'" is not declared into project.xml');
}
if (!isset($this->entryPoints[$entrypoint])) {
throw new Exception('The entry point "'.$entrypoint.'" is not declared into project.xml/jelix-app.json');
}
return jApp::configPath($this->entryPoints[$entrypoint]);
}
/**
Expand Down
5 changes: 3 additions & 2 deletions lib/jelix-scripts/commands-single/createapp.cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function run() {
$appName = basename($appPath);
$appPath .= '/';

if (file_exists($appPath.'/project.xml')) {
if (file_exists($appPath.'/jelix-app.json') || file_exists($appPath.'/project.xml')) {
throw new Exception("this application is already created");
}

Expand Down Expand Up @@ -171,7 +171,8 @@ public function run() {

$this->createFile($appPath.'.htaccess', 'htaccess_deny', $param, "Configuration file for Apache");
$this->createFile($appPath.'.gitignore','git_ignore.tpl', $param, ".gitignore");
$this->createFile($appPath.'project.xml','project.xml.tpl', $param, "Project description file");

$this->createFile($appPath.'jelix-app.json','jelix-app.json.tpl', $param, "Project description file");
$this->createFile($appPath.'composer.json','composer.json.tpl', $param, "Composer file");
$this->createFile($appPath.'cmd.php','cmd.php.tpl', $param, "Script for developer commands");
$this->createFile($configPath.'mainconfig.ini.php', 'var/config/mainconfig.ini.php.tpl', $param, "Main configuration file");
Expand Down
29 changes: 5 additions & 24 deletions lib/jelix-scripts/commands/createentrypoint.cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function run() {

$entryPointDir = dirname($entryPointFullPath).'/';

$this->loadProjectXml();
$this->loadAppInfos();

// retrieve the config file name
$configFile = $this->getParam('config');
Expand Down Expand Up @@ -154,33 +154,14 @@ public function run() {
$inifile->save();
}

$this->updateProjectXml($name.".php", $configFile , $type);
if ($this->verbose())
echo "Project.xml has been updated.\n";
$this->appInfos->addEntryPointInfo($name.".php", $configFile , $type);
if ($this->verbose()) {
echo "Project.xml/jelix-app.json has been updated.\n";
}

$installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning'));
$installer->installEntryPoint($name.".php");
if ($this->verbose())
echo "All modules have been initialized for the new entry point.\n";
}

protected function updateProjectXml ($fileName, $configFileName, $type) {

$elem = $this->projectXml->createElementNS(JELIX_NAMESPACE_BASE.'project/1.0', 'entry');
$elem->setAttribute("file", $fileName);
$elem->setAttribute("config", $configFileName);
$elem->setAttribute("type", $type);

$ep = $this->projectXml->documentElement->getElementsByTagName("entrypoints");

if (!$ep->length) {
$ep = $this->projectXml->createElementNS(JELIX_NAMESPACE_BASE.'project/1.0', 'entrypoints');
$doc->documentElement->appendChild($ep);
$ep->appendChild($elem);
}
else
$ep->item(0)->appendChild($elem);

$this->projectXml->save(App::appPath('project.xml'));
}
}
6 changes: 3 additions & 3 deletions lib/jelix-scripts/commands/createmodule.cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class createmoduleCommand extends JelixScriptCommand {
public $syntaxhelp = "[-nosubdir] [-nocontroller] [-cmdline] [-addinstallzone] [-defaultmodule] [-admin] MODULE [REPOSITORY]";
public $help=array(
'fr'=>"
Crée un nouveau module, avec son fichier module.xml, et un contrôleur
Crée un nouveau module, avec son fichier jelix-module.json, et un contrôleur
par défaut, ainsi que tous les sous-répertoires courants
(zones, templates, daos, locales, classes...).
Expand Down Expand Up @@ -108,7 +108,7 @@ public function run(){
$param['default_id'] = $module.$this->config->infoIDSuffix;
$param['version'] = $initialVersion;

$this->createFile($path.'module.xml', 'module/module.xml.tpl', $param);
$this->createFile($path.'jelix-module.json', 'module/jelix-module.json.tpl', $param);

// create all sub directories of a module
if (!$this->getOption('-nosubdir')) {
Expand Down Expand Up @@ -149,7 +149,7 @@ public function run(){
$install = new jIniFileModifier(App::configPath('installer.ini.php'));

// install the module for all needed entry points
foreach ($list as $k => $entryPoint) {
foreach ($list as $entryPoint) {

$configFile = App::configPath($entryPoint['config']);
$epconfig = new jIniFileModifier($configFile);
Expand Down
2 changes: 1 addition & 1 deletion lib/jelix-scripts/commands/initadmin.cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function run(){
$cmd = JelixScript::getCommand('createentrypoint', $this->config);
$cmd->initOptParam(array(),array('name'=>$entrypoint));
$cmd->run();
$this->projectXml = null;
$this->appInfos = null;
$ep = $this->getEntryPointInfo($entrypoint);
}
catch (Exception $e) {
Expand Down
Loading

0 comments on commit b6062dd

Please sign in to comment.