aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile40
-rw-r--r--README.md10
-rw-r--r--app/class/Config.php8
-rw-r--r--app/class/Modelrender.php2
4 files changed, 43 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 13afc14..acae87e 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,9 @@ override WEBPACK_FLAGS += $(if $(filter $(ENV),dist),-p)
override COMPOSER_FLAGS += $(if $(filter $(ENV),dist),--no-dev --prefer-dist)
PREV_ENV_FILE := $(build_dir)/prev_env
PREV_ENV := $(strip $(shell cat $(PREV_ENV_FILE) 2>/dev/null))
+HOST := localhost
+PORT := 8080
+PHP_FLAGS += $(and $(XDEBUG3),-d xdebug.start_with_request=yes)
# Files variables.
js_sources := $(wildcard $(js_src_dir)/*.js)
@@ -35,11 +38,21 @@ dirs := $(phpcs_dir) $(phpunit_dir)
# Default target. This executes everything targets needed to get a fully
# working development environment.
.PHONY: all
-all: $(PREV_ENV_FILE) vendor build
+all: vendor build
# Build generated files.
.PHONY: build
-build: VERSION $(PREV_ENV_FILE) $(js_bundles)
+build: VERSION $(js_bundles)
+
+.PHONY: dev
+dev: ENV := dev
+dev: MAKEFLAGS += j2
+dev:
+ $(MAKE) serve .watch ENV=$(ENV)
+
+.PHONY: serve
+serve: vendor VERSION
+ php -S $(HOST):$(PORT) -t ./ $(PHP_FLAGS)
# Run webpack in watch mode.
.PHONY: watch
@@ -63,7 +76,7 @@ sentryrelease:
$(MAKE) .sentryrelease ENV=$(ENV)
.PHONY: .sentryrelease
-.sentryrelease: $(PREV_ENV_FILE) build $(js_srcmaps)
+.sentryrelease: build $(js_srcmaps)
sentry-cli releases new $(GIT_VERSION)
sentry-cli releases set-commits $(GIT_VERSION) --auto
sentry-cli releases files $(GIT_VERSION) upload-sourcemaps assets/js --url-prefix '~/assets/js' --rewrite
@@ -76,7 +89,7 @@ dist:
$(MAKE) .dist ENV=$(ENV)
.PHONY: .dist
-.dist: distclean $(zip_release) $(js_srcmaps)
+.dist: distclean $(zip_release)
dist/w_cms_%.zip: all
@echo Building Zip release...
@@ -109,7 +122,7 @@ dist/w_cms_%.zip: all
webpack.config.js
# Generate the js bundles (and sourcemaps).
-assets/js/%.bundle.js assets/js/%.bundle.js.map: $(js_src_dir)/%.js node_modules webpack.config.js
+assets/js/%.bundle.js assets/js/%.bundle.js.map: $(js_src_dir)/%.js node_modules webpack.config.js $(PREV_ENV_FILE)
@echo Building JS Bundles...
mkdir -p $(dir $@)
webpack $< -o $@ --env $(ENV) $(WEBPACK_FLAGS)
@@ -137,7 +150,7 @@ endif
endif
# Install PHP dependencies.
-vendor: composer.json composer.lock
+vendor: $(PREV_ENV_FILE) composer.json composer.lock
@echo Installing PHP dependencies...
composer install $(COMPOSER_FLAGS)
touch $@
@@ -145,7 +158,8 @@ vendor: composer.json composer.lock
# Install JS dependencies.
node_modules: package.json package-lock.json
@echo Installing JS dependencies...
- npm install --loglevel=error
+ npm install --loglevel=error --also=dev
+ touch $@
# Clean files generated by `make all`.
.PHONY: clean
@@ -171,26 +185,26 @@ buildclean:
# Run all checks.
.PHONY: check
-check: vendor lint analyse test
+check: lint analyse test
# Lint php code with phpcs.
.PHONY: lint
-lint: $(phpcs_dir)
- phpcs --report-full --report-summary --cache=$(phpcs_dir)/result.cache || printf "run 'make fix'\n\n"; exit 1
+lint: $(phpcs_dir) vendor
+ phpcs --report-full --report-summary --cache=$(phpcs_dir)/result.cache || { printf "run 'make fix'\n\n"; exit 1; }
# fix php code with phpcbf.
.PHONY: fix
-fix: $(phpcs_dir)
+fix: $(phpcs_dir) vendor
phpcbf || exit 0
# Analyse php code with phpstan.
.PHONY: analyse
-analyse:
+analyse: vendor
phpstan analyse
# Test php code with phpunit.
.PHONY: test
-test: $(phpunit_dir)
+test: $(phpunit_dir) vendor
phpunit
# Create dirs if the do not exist
diff --git a/README.md b/README.md
index 4d0786e..d81d1f6 100644
--- a/README.md
+++ b/README.md
@@ -114,7 +114,7 @@ Install from sources
make vendor
-3. _Optionnally_ install and build JS dependencies to get UI enhancements.
+3. _Optionally_ install and build JS dependencies to get UI enhancements.
make build
@@ -136,6 +136,10 @@ The build environment can be set either for each `make` command by changing it i
PHP development
---------------
+You can easily run a dev server using the `serve` target:
+
+ make serve
+
There is an error reporting debug mode using [Whoops](https://github.com/filp/whoops). It can be enabled by setting the value of `debug` in `config.json` to one of [editors supported by Whoops](https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md).
JS development
@@ -145,6 +149,10 @@ While developing JS code it is useful to run webpack in watch mode so that the b
make watch
+To run both the php dev server and webpack in watch mode, it is possible to run:
+
+ make dev
+
Run checks
---------
diff --git a/app/class/Config.php b/app/class/Config.php
index 7b2b50c..bfe0f08 100644
--- a/app/class/Config.php
+++ b/app/class/Config.php
@@ -91,6 +91,10 @@ abstract class Config
public static function tojson()
{
$arr = get_class_vars(get_class());
+ // get_class_vars returns default values, we need to update each of them with the current one
+ foreach ($arr as $key => $value) {
+ $arr[$key] = self::$$key;
+ }
$json = json_encode($arr, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT);
return $json;
}
@@ -106,7 +110,7 @@ abstract class Config
*/
public static function getdomain()
{
- self::$domain = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
+ self::$domain = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'];
}
/**
@@ -114,7 +118,7 @@ abstract class Config
*/
public static function checkdomain()
{
- return (self::$domain === $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']);
+ return (self::$domain === (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST']);
}
/**
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index 2e59da3..47c7d3c 100644
--- a/app/class/Modelrender.php
+++ b/app/class/Modelrender.php
@@ -359,7 +359,7 @@ class Modelrender extends Modelpage
public function media(string $text): string
{
$regex = '%(src|href)="([\w\-]+(\/([\w\-])+)*\.[a-z0-9]{1,5})"%';
- $text = preg_replace($regex, '$1="' . Model::mediapath() . '$2" target="_blank" class="media"', $text);
+ $text = preg_replace($regex, '$1="' . Model::mediapath() . '$2" target="_blank"', $text);
if (!is_string($text)) {
//throw new Exception('Rendering error -> media module');
}