Skip to content

Commit

Permalink
Version v0.0.1-pre-alpha
Browse files Browse the repository at this point in the history
- Developed basic functionality of the framework
- Developed basic services
  • Loading branch information
alessandro1105 committed Jan 1, 2019
2 parents a969337 + dc56b4f commit 552be4f
Show file tree
Hide file tree
Showing 55 changed files with 3,861 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<IfModule mod_rewrite.c>
RewriteEngine On

# Enable this option to do not redirect the request to index.php for the "assets/" directory.
# Change {{BASE}} with your base url
#RewriteCond %{REQUEST_URI} !^/{{BASE}}/assets/

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*)$ index.php/$1 [L,QSA,NC]
</IfModule>
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# AzzurroFramework
# AzzurroFramwork

AzzurroFramwork is a PHP framework inspired by AngularJS and its dependency injection. I created this framework trying to emulate all the concepts introduced with AngularJS itself, so if you are familiar with them you will have less problems deveping mudularized PHP application using AzzurroFramework in the same way. I hope you like it :)

## Getting Started

Just download the lastest realease and extract it on the root of your web server.

### Installing

The framework is already app and running. You must create your application starting from app/app.php where it resides the definition of your main module.

## Authors

* **Alessandro Pasqualini** - [alessandro1105](https://github.com/alessandro1105)

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
12 changes: 12 additions & 0 deletions app/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/*
User application main file
This file is the main file of your application.
Inside this file you can develop your application or call an autoloader.
DO NOT DELETE THIS FILE otherwise your application will not be loaded.
*/

// Application main module
$azzurro->app("app", []);
54 changes: 54 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/*
Index file
- define basic constants
- require the vendros/azzurroframework/bootstrap.php file
---- Changelog ---
Rev 1.0 - November 20th, 2017
- Basic functionality
Copyright 2017 Alessandro Pasqualini
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@author Alessandro Pasqualini <[email protected]>
@url https://github.com/alessandro1105
*/

use \AzzurroFramework\Core\AzzurroFramework;

// --- VERSION ---
define("__AF_VERSION__", "0.0.1-pre-alfa");

// --- PATH CONSTANTS ---
// Server root
define("__AF_ROOT__", __DIR__);
// Vendors directory
define("__AF_VENDOR_DIR__", __AF_ROOT__ . DIRECTORY_SEPARATOR . "vendors");
// Azzurro Framework core directory
define("__AF_DIR__", __AF_VENDOR_DIR__ . DIRECTORY_SEPARATOR . "azzurroframework");
// Logs directory
define("__AF_LOGS_DIR__", __AF_ROOT__ . DIRECTORY_SEPARATOR . "logs");
// User application directory
define("__AF_APP_DIR__", __AF_ROOT__ . DIRECTORY_SEPARATOR . "app");


// --- LOAD AZZURRO FRAMEWORK ---
require_once(__AF_DIR__ . "/autoloader.php");

// --- LOAD USER APPLICATION ---
require_once(__AF_APP_DIR__ . "/app.php");

// --- BOOTSTRAP THE FRAMEWORK ---
$azzurro->boostrap();
27 changes: 27 additions & 0 deletions vendors/azzurroframework/autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
Azzurro Framework loader
This autoloader file requires the external module autoloader and the core autoloader files.
Copyright 2017 Alessandro Pasqualini
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@author Alessandro Pasqualini <[email protected]>
@url https://github.com/alessandro1105
*/

// --- REQUIRE CORE AUTOLOADER ---
require_once(__DIR__ . "/core/autoloader.php");

// --- REQUIRE EXTERNAL MODULES AUTOLOADER ---
require_once(__DIR__ . "/modules/autoloader.php");
213 changes: 213 additions & 0 deletions vendors/azzurroframework/core/AzzurroFramework.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<?php
/*
Azzurro Framework main class
Main class of the framework. It permits to register modules and handle all the framework functionality.
Copyright 2017 Alessandro Pasqualini
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@author Alessandro Pasqualini <[email protected]>
@url https://github.com/alessandro1105
*/

// Strict type hint
declare(strict_types = 1);

namespace AzzurroFramework\Core;

use \InvalidArgumentException;
use \AzzurroFramework\Core\Exceptions\App\AppModuleNotRegisteredException;
use \AzzurroFramework\Core\Exceptions\Module\ModuleAlreadyRegisteredException;
use \AzzurroFramework\Core\Exceptions\Module\ModuleNotFoundException;

use \AzzurroFramework\Core\Injector\Injector;
use \AzzurroFramework\Core\Module\Module;

use \AzzurroFramework\Core\Modules\Auto\Injector\InjectorService;
use \AzzurroFramework\Core\Modules\Auto\Filter\FilterService;
use \AzzurroFramework\Core\Modules\Auto\Controller\ControllerService;


//--- AzzurroFramework class ----
final class AzzurroFramework {

// Events generated by the framework when all the framework is ready
const EVENT_READY = "AF:ready";
// Events generated by the framework at the shutdown
const EVENT_SHUTDOWN = "AF:shutdown";
// Events generated by the framework to execute all the callbacks
const EVENT_CALLBACK = "AF:callback";


// Singleton instance
private static $self = null;

// Application modules
private $modules;
// App module
private $app;
// Injector
private $injector;


//--- SINGLETON COSTRUCTOR ----
// Singleton object
public static function getInstance() {
// If there isn't an instance, then create it
if (self::$self == null) {
self::$self = new self();
}

// Return the instance
return self::$self;
}

// Private contructor because is singleton
private function __construct() {
// Prepare the variables
$this->modules = array();
$this->app = null;
$this->injector = new Injector($this->modules);

// Reister af module components
$this->registerAutoModuleComponent();
}

//--- CERATING AND GETTING THE MAIN MODULE ---
// Method to create and get the main module of the application
public function app(string $name, array $dependencies = null) {
// Check the correctness of the the arguments
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name)) {
throw new InvalidArgumentException("\$name argument must be a valid module name!");
}
if (!is_null($this->app) and $app != $name) {
throw new ModuleAlreadyRegisteredException("App module has been already registered!");
}

// Use module method to retrive or create the module
$module = $this->module($name, $dependencies);

if (!is_null($dependencies)) {
$this->app = $name;
}

// Return the Module instance
return $module;
}

//--- CREATING AND GETTING MODULES ---
// Method to create and get a module
public function module(string $name, array $dependencies = null) {
// Check the correctness of the the arguments
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name)) {
throw new InvalidArgumentException("\$name argument must be a valid module name!");
}
if (!is_null($dependencies)) {
foreach ($dependencies as $dependency) {
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $dependency)) {
throw new InvalidArgumentException("\$dependencies argument must be a valid array of module names!");
}
}
}
// Check if the module requested exists
if (!array_key_exists($name, $this->modules) and is_null($dependencies)) {
throw new ModuleNotFoundException("Module '$name' has not been registered!");
}

// If the module doesn't exists, create a new one
if (!array_key_exists($name, $this->modules) and !is_null($dependencies)) {
// Create the new module
$this->modules[$name] = [
'dependencies' => $dependencies
];
}

// Check if the module is the app one
if ($this->app == $name) {
return $this->app($name, $dependencies);
}

// Return the Module instance
return new Module($this->modules[$name]);
}

//--- EXECUTING THE FRAMEWORK ---
// Boostrap the framework
public function boostrap() {
if (is_null($this->app)) {
throw new AppModuleNotRegisteredException("App module has not been defined!");
}

// Resolve the dependencies of the app module
$this->injector->resolveApplicationDependencies($this->app);

// Getting $event service
$event = $this->injector->getService("event");
$azzurro = $this->injector->getService("azzurro");

// Generate event indicating the framework is ready
$event->emit(self::EVENT_READY);

// Generate event to start the routing process
$event->emit($azzurro->getRouteEvent());

// Generate event to start all the callbacks
$event->emit(self::EVENT_CALLBACK);

// generate event indicating the framework is shutting down
$event->emit(self::EVENT_SHUTDOWN);

}

//--- VERSION INFO ---
// Return the version of the framework
public function version() {
return __AF_VERSION__;
}

//--- REGISTER COMPONENTS OF MODULE af ---
public function registerAutoModuleComponent() {
// Create the module
$auto = $this->module("auto", []);

// Prepare the injector to pass to services
$injector = $this->injector;

// Registering components to the "auto" module
// $azzurro service
$auto->provider("azzurro", "\AzzurroFramework\Core\Modules\Auto\Azzurro\AzzurroServiceProvider");

// $callback service
$auto->service("callback", "\AzzurroFramework\Core\Modules\Auto\Callback\CallbackService");

// $controller service
$auto->factory("controller", function () use ($injector) {
return new ControllerService($injector);
});

// $events service
$auto->service("event", "\AzzurroFramework\Core\Modules\Auto\Event\EventService");

// $filters service
$auto->factory("filter", function () use ($injector) {
return new FilterService($injector);
});

// $injector service
$auto->factory("injector", function () use ($injector) {
return new InjectorService($injector);
});

}

}
Loading

0 comments on commit 552be4f

Please sign in to comment.