Skip to content

Commit

Permalink
- replace 'directory' for 'path'
Browse files Browse the repository at this point in the history
- asset_paths configuration can contain an array of paths
  • Loading branch information
christopheg committed Mar 11, 2022
1 parent c78cc2e commit 408ce63
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 175 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Each key/value pair will be available in your project.

Include a config directory

\Skeleton\Core\Config::include_directory('/config');
\Skeleton\Core\Config::include_path('/config');

PHP files stored in the config directory will be evaluated in alphabetical
order. In case you have environment-specific configuration, you can create a
Expand All @@ -54,13 +54,13 @@ Get a config object

Skeleton needs at least these config items to operate properly:

'application_dir': The root directory where skeleton can find Skeleton
'application_path': The root path where skeleton can find Skeleton
Applications

Your webserver should rewrite every request to a single PHP file. This file
will start your skeleton project. It should include at least the following

\Skeleton\Core\Config::include_directory('config');
\Skeleton\Core\Config::include_path('config');
\Skeleton\Core\Web\Handler::Run();

Altough a skeleton project can have any desired directory structure, we
Expand All @@ -86,7 +86,7 @@ There are various types of applications. Skeleton-core includes the most-used:

\Skeleton\Core\Application\Web

Other applications are available via skeleton packages (eg
Other applications are available via skeleton packages (eg
[skeleton-application-api](https://github.com/tigron/skeleton-application-api)

A Skeleton Application\Web is a common application that handles any type of
Expand All @@ -108,15 +108,15 @@ directory structure within the application:
- javascript
- image

If you want media files to be served from an additional directory, for example
If you want media files to be served from additional paths, for example
if you have a package manager such as `bower`, `yarn` or even the
`fxp/composer-asset-plugin`, you can specify an additional directory which will
`fxp/composer-asset-plugin`, you can specify additional paths which will
be searched in addition to the default `media` one.

To enable media serving from an additional asset directory, include the
To enable media serving from an additional asset path, include the
following configuration directive in your skeleton project:

'asset_dir': The asset directory where media files can be served from if
'asset_paths': The asset paths where media files can be served from if
they are not found in your application.


Expand All @@ -135,7 +135,7 @@ The following optional configurations can be set:
|----|----|----|----|
|hostnames|(required)an array containing the hostnames to listen for. Wildcards can be used via `*`.| []| [ 'www.example.be, '*.example.be' ]|
|base_uri|Specifies the base uri for the application. If a base_uri is specified, it will be included in the reverse url generation|'/'|'/v1'|
|default_language|This is the ISO 639-1 code for the default language to be used, if no more specific one can be found|'en'|'en', 'nl', any language iso2 code provided by skeleton-i18n|
|default_language|This is the ISO 639-1 code for the default language to be used, if no more specific one can be found|'en'|'en', 'nl', any language iso2 code provided by skeleton-i18n|
|session_name|The name given to your session|'App'|any string|
|sticky_session_name|The key in your session where sticky session information is stored|'sys_sticky_session'|any string|
|csrf_enabled|Enable CSRF|false|true/false|
Expand Down Expand Up @@ -213,7 +213,7 @@ This can be best explained with some examples:

As you can see in the last two examples, the `index` modules are a bit special,
in that they can be used instead of the underlying one if they sit in a
subfolder. The `index` is configurable via configuration directive
subfolder. The `index` is configurable via configuration directive
`module_default`

### Routing to the correct method
Expand Down Expand Up @@ -318,8 +318,8 @@ Events can be created to perform a task at specific key points during the
application's execution.

Events are defined in `Event` context classes. These classes are optional, but
when they are used, they should be located in the `event` directory of your
application. The filename should be in the form of `Context_name.php`, for
when they are used, they should be located in the `event` directory of your
application. The filename should be in the form of `Context_name.php`, for
example `Application.php`.

The class should extend from `Skeleton\Core\Event` and the classname should be
Expand Down
73 changes: 0 additions & 73 deletions console/app_create.php

This file was deleted.

81 changes: 24 additions & 57 deletions lib/Skeleton/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ public function __construct($name) {
protected function get_details() {
$config = clone Config::get();
$this->config = $config;
$application_path = realpath($config->application_dir . '/' . $this->name);

/**
* @deprecated: this is for backwards compatibility
*/
if (isset($config->application_dir) and !isset($config->application_path)) {
$config->application_path = $config->application_dir;
}

$application_path = realpath($config->application_path . '/' . $this->name);

if (!file_exists($application_path)) {
throw new \Exception('Application with name "' . $this->name . '" not found');
Expand Down Expand Up @@ -145,7 +153,7 @@ protected function load_config() {
*/
$this->config->application_type = '\Skeleton\Core\Application\Web';

$this->config->read_directory($this->path . '/config');
$this->config->read_path($this->path . '/config');
}

/**
Expand Down Expand Up @@ -377,17 +385,25 @@ public static function detect($hostname, $request_uri) {
*/
public static function get_all() {
$config = Config::get();
if (!isset($config->application_dir)) {
throw new \Exception('No application_dir set. Please set Config::$application_dir');

/**
* @deprecated: this is for backwards compatibility
*/
if (isset($config->application_dir) and !isset($config->application_path)) {
$config->application_path = $config->application_dir;
}
$application_directories = scandir($config->application_dir);

if (!isset($config->application_path)) {
throw new \Exception('No application_path set. Please set "application_path" in project configuration');
}
$application_paths = scandir($config->application_path);
$application = [];
foreach ($application_directories as $application_directory) {
if ($application_directory[0] == '.') {
foreach ($application_paths as $application_path) {
if ($application_path[0] == '.') {
continue;
}

$application = self::get_by_name($application_directory);
$application = self::get_by_name($application_path);
$applications[] = $application;
}
return $applications;
Expand All @@ -406,53 +422,4 @@ public static function get_by_name($name) {
$application_type = $config->application_type;
return new $application_type($name);
}

/**
* Create an app
*
* @access public
* @param string $name
* @return Application $application
*/
public static function create($name, $settings) {
$name = strtolower($name);
$application_path = realpath(Config::$application_dir);

if (!file_exists($application_path)) {
throw new \Exception('There is no application path defined. Please specificy a path in \Skeleton\Core\Config::$application_dir');
}

if (file_exists($application_path . '/' . $name)) {
throw new \Exception('There is already an app with this name created');
}

// Create the required directories
mkdir($application_path . '/' . $name);
mkdir($application_path . '/' . $name . '/config');
mkdir($application_path . '/' . $name . '/media');
mkdir($application_path . '/' . $name . '/module');
mkdir($application_path . '/' . $name . '/template');
mkdir($application_path . '/' . $name . '/event');

$root_path = dirname(__FILE__) . '/../../../';

$config = file_get_contents($root_path . '/template/config/Config.php.tpl');
$config = str_replace('%%APP_NAME%%', ucfirst($name), $config);

foreach ($settings['hostnames'] as $key => $hostname) {
$settings['hostnames'][$key] = "'" . $hostname . "'";
}

$config = str_replace('%%HOSTNAMES%%', '[' . implode(', ', $settings['hostnames']) . ']', $config);
file_put_contents($application_path . '/' . $name . '/config/Config.php', $config);

$module = file_get_contents($root_path . '/template/module/index.php.tpl');
file_put_contents($application_path . '/' . $name . '/module/index.php', $module);

$template = file_get_contents($root_path . '/template/template/index.twig.tpl');
file_put_contents($application_path . '/' . $name . '/template/index.twig', $template);

return self::get_by_name($name);
}

}
16 changes: 1 addition & 15 deletions lib/Skeleton/Core/Application/Web/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function get_module_path() {
$application = Application::Get();
$path = '/' . str_replace($application->module_path, '', $reflection->getFileName());
$path = strtolower($path);

return str_replace('.php', '', $path);
}

Expand Down Expand Up @@ -187,18 +187,4 @@ public static function resolve($request_relative_uri) {
throw new \Exception('Module not found');
}

/**
* Check if a module exists
*
* @param string Name of the module
* @access public
* @return bool
*/
public static function exists($name) {
if (Config::$application_dir === null) {
throw new \Exception('No application_dir set. Please set Config::$application_dir');
}

return (file_exists(Config::$application_dir . '/module/' . $name . '.php'));
}
}
28 changes: 18 additions & 10 deletions lib/Skeleton/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public function read_file($file) {
*
* @access public
*/
public function read_directory($directory) {
if (!file_exists($directory)) {
public function read_path($path) {
if (!file_exists($path)) {
throw new \Exception('Config directory does not exist');
}

$files = scandir($directory);
$files = scandir($path);
foreach ($files as $file) {
if ($file[0] == '.') {
continue;
Expand All @@ -142,22 +142,21 @@ public function read_directory($directory) {
continue;
}

$this->read_file($directory . DIRECTORY_SEPARATOR . $info['basename']);
$this->read_file($path . DIRECTORY_SEPARATOR . $info['basename']);
}

if (file_exists($directory . DIRECTORY_SEPARATOR . 'environment.php')) {
$this->read_file($directory . DIRECTORY_SEPARATOR . 'environment.php');
if (file_exists($path . DIRECTORY_SEPARATOR . 'environment.php')) {
$this->read_file($path . DIRECTORY_SEPARATOR . 'environment.php');
}
}


/**
* Include a config directory
*
* @access public
*/
public static function include_directory($directory) {
if (!file_exists($directory)) {
public static function include_path($path) {
if (!file_exists($path)) {
throw new \Exception('Config directory does not exist');
}

Expand All @@ -167,8 +166,17 @@ public static function include_directory($directory) {
$config = new self();
self::$config = $config;
}
$config->read_directory($directory);
$config->read_path($path);
self::$config = $config;
}

/**
* Include a config directory
*
* @access public
*/
public static function include_directory($directory) {
self::include_path($directory);
}

}
12 changes: 6 additions & 6 deletions lib/Skeleton/Core/Skeleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static function get_all() {
/**
* Search for other Skeleton packages installed
*/
$composer_dir = realpath(__DIR__ . '/../../../../../');
$installed = file_get_contents($composer_dir . '/composer/installed.json');
$composer_path = realpath(__DIR__ . '/../../../../../');
$installed = file_get_contents($composer_path . '/composer/installed.json');
$installed = json_decode($installed);

// The structure of the installed.json file in composer 2 is slightly different
Expand All @@ -80,10 +80,10 @@ public static function get_all() {

$skeleton = new self();
$skeleton->name = $name;
$skeleton->path = $composer_dir . '/tigron/' . $name;
$skeleton->template_path = $composer_dir . '/tigron/' . $name . '/template';
$skeleton->asset_path = $composer_dir . '/tigron/' . $name . '/media';
$skeleton->migration_path = $composer_dir . '/tigron/' . $name . '/migration';
$skeleton->path = $composer_path . '/tigron/' . $name;
$skeleton->template_path = $composer_path . '/tigron/' . $name . '/template';
$skeleton->asset_path = $composer_path . '/tigron/' . $name . '/media';
$skeleton->migration_path = $composer_path . '/tigron/' . $name . '/migration';

$skeletons[] = $skeleton;
}
Expand Down
Loading

0 comments on commit 408ce63

Please sign in to comment.