Exemplo n.º 1
0
 public function setUp()
 {
     $this->stream = vfsStream::setup('root', 0777, self::$structure);
     Application::register('FileSystem', \Core\FileSystem\FileSystem::class);
     Application::register('Cache', \Core\Cache\FileCache::class)->setArguments(['FileSystem', vfsStream::url('root/cache')]);
     parent::setUp();
 }
Exemplo n.º 2
0
 public function sign_out()
 {
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     $auth::getInstance()->unsetUserSession();
     Go::to();
 }
Exemplo n.º 3
0
 /**
  * @covers \Core\Contracts\Database\LanguageContract::create
  * @covers \Core\Database\Language\MySqlLanguage::create
  */
 public function setUp()
 {
     MockPaths::createMockPaths();
     $this->app = new Application(MockPaths::$basePath);
     $this->app->setEnvironment('test');
     $language = $this->getMapping();
     $table = $this->getTableSchema();
     $table2 = $this->getTable2Schema();
     $phoneTable = $this->getPhoneTableSchema();
     $postsTable = $this->getPostsTableSchema();
     $commentsTable = $this->getCommentsTableSchema();
     $employeeTable = $this->getEmployeeSchema();
     $educationTable = $this->getEducationSchema();
     $education_employeeTable = $this->getEmployee_Education_Schema();
     $language->create($table);
     $language->create($table2);
     $language->create($phoneTable);
     $language->create($postsTable);
     $language->create($commentsTable);
     $language->create($employeeTable);
     $language->create($educationTable);
     $language->create($education_employeeTable);
     $language->insert($table, $this->data);
     $language->insert($table2, $this->data);
     $language->insert($phoneTable, $this->phoneData);
     $language->insert($postsTable, $this->postData);
     $language->insert($commentsTable, $this->commentsData);
     $language->insert($employeeTable, $this->employeeData);
     $language->insert($educationTable, $this->educationData);
     $language->insert($education_employeeTable, $this->employee_education_data);
     parent::setUp();
 }
Exemplo n.º 4
0
 public function __construct()
 {
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     $auth::getInstance();
     $this->addContent('user_data', AuthenticationHandler::$data);
     $m = new ModelCategory();
     $this->addContent('categories', $m->all(Query::condition()->order('name_category', 'ASC')));
 }
Exemplo n.º 5
0
 public function share()
 {
     Autoload::addComponent("Achilles.share");
     $this->setTitle("Submit a link");
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     if (!$auth::is(AuthenticationHandler::USER)) {
         Go::to404();
     }
     $m = new ModelPost();
     $form = new Form("post_share");
     if ($form->isValid()) {
         $v = $form->getValues();
         $insertedPermalink = $m->share($v);
         Header::location('post/' . $insertedPermalink);
     } else {
         $this->addContent("error", $form->getError());
     }
     $this->addForm("share", $form);
 }
Exemplo n.º 6
0
 /**
  * @runInSeparateProcess
  *
  * Running in a separate process ensures that the controller classes don't exist
  * thus causing the 604 "Controller not Found" error
  * Note: Controller is not passed/defined in getRouterMock
  */
 public function testRouterAlwaysReturnsResponse()
 {
     $router = $this->getRouterMock();
     $this->application->updateInstance('Router', $router);
     $request = $this->getRequestMock('/test/2');
     $this->setRoutes();
     /*
      * Following matches route '/test/{id:default=1}' but since controller
      * is not defined we get a "Controller not found" (604) error
      */
     $response = $router->handle($request);
     $this->assertInstanceOf('\\Core\\Response\\Response', $response);
     $this->assertEquals(604, $response->getStatusCode());
     /*
      * Following does not match any route (hence response is a 404)
      */
     $response = $router->handle($request = $this->getRequestMock('/asdasd/2'));
     $this->assertInstanceOf('\\Core\\Response\\Response', $response);
     $this->assertEquals(404, $response->getStatusCode());
 }
Exemplo n.º 7
0
 public function setUp()
 {
     $this->stream = vfsStream::setup('root', 0777, self::$structure);
     Application::register('FileSystem', \Core\FileSystem\FileSystem::class);
     parent::setUp();
 }
Exemplo n.º 8
0
 public function __construct()
 {
     parent::__construct(Application::getInstance() . "_upload", "id_upload");
 }
 /**
  * Constructor
  * Se doit d'être appeler dans la classe fille
  * Vérifie si l'utilisateur est identifié
  * Définie le nom du controller (de la classe courante)
  */
 public function __construct()
 {
     $authHandler = Application::getInstance()->authenticationHandler;
     if (!call_user_func_array(array($authHandler, 'is'), array($authHandler::ADMIN))) {
         Go::to();
     }
     $class = explode("\\", get_class($this));
     $this->className = end($class);
     $this->formName = $this->className;
     Autoload::addScript("Backoffice");
     $this->h1 = new BOLabelList("h1", ucfirst($this->className));
     $this->titles = new BOLabelList("titles", ucfirst($this->className));
     $this->actions = new BOActionList();
     $this->actions->enable('view', 'view', true);
     $this->actions->enable('edit', 'edit', true);
     $this->actions->enable('delete', 'delete', true);
     $this->actions->enable('listing', 'listing', false);
     $this->actions->enable('add', 'add', false);
     $this->menu = new Menu(Core::$path_to_application . '/modules/back/menu.json');
 }
Exemplo n.º 10
0
 /**
  * @static
  * @param  $pURL
  * @return bool|string
  */
 public static function extractLanguage(&$pURL)
 {
     if (Application::getInstance()->multiLanguage && !preg_match("/^statique/", $pURL, $matches)) {
         $language = self::shift($pURL, self::REGEXP_LANGUAGE);
         if (!$language) {
             Go::to("", "", array(), Application::getInstance()->defaultLanguage);
         }
         return $language;
     }
     return Application::getInstance()->defaultLanguage;
 }
Exemplo n.º 11
0
 /**
  * ATTENTION AU NAME DE L'INPUT
  * ==> FORM[INPUTNAME] <==
  *
  * ATTENTION A LA TECHNIQUE DE RENVOIE D'INFORMATION !M&eacute;thode priv&eacute;e
  *
  * @return void
  */
 public function upload_async()
 {
     $datas = null;
     $response = array("error" => "");
     if (!isset($_POST["form_name"]) || empty($_POST["form_name"])) {
         $response["error"] = '$_POST["form_name"] require';
         $this->response($response);
     }
     if (!isset($_POST["input_name"]) || empty($_POST["input_name"])) {
         $response["error"] = '$_POST["input_name"] require';
         $this->response($response);
     }
     $file = $_FILES[$_POST["input_name"]];
     if (!isset($file) || empty($file)) {
         $response["error"] = "Aucun fichier n'a été transmis";
     }
     if (empty($response["error"])) {
         $app = $_POST["application"];
         $path_to_form = "includes/applications/" . $app . "/modules/";
         if (isset($_POST["module"]) && !empty($_POST['module'])) {
             $path_to_form .= $_POST["module"] . "/";
         } else {
             $path_to_form .= "front/";
         }
         $form_name = $_POST["form_name"];
         $path_to_form .= "forms/form." . $form_name . ".json";
         if (!file_exists($path_to_form)) {
             $path_to_form = preg_replace("/_[0-9]+\\.json\$/", ".json", $path_to_form);
         }
         try {
             $datas = SimpleJSON::import($path_to_form);
         } catch (Exception $e) {
             $response["error"] = "Formulaire introuvable " . $path_to_form;
             $this->response($response);
         }
         if (!is_array($datas[$_POST["input_name"]])) {
             $response["error"] = "Champs cibl&eacute; introuvable";
             $this->response($response);
         }
         $input = $datas[$_POST["input_name"]];
         if ($input["tag"] != Form::TAG_UPLOAD && ($input["tag"] != "input" && $input["attributes"]["type"] != "file")) {
             $response["error"] = "Le champ ciblé n'est pas un input type 'file'";
             $this->response($response);
         }
         $fileName = "";
         if (isset($input["fileName"])) {
             $fileName = "file" . rand(0, 999999);
         }
         $folderName = Form::PATH_TO_UPLOAD_FOLDER;
         if (isset($input["folder"])) {
             $folderName .= $input["folder"];
         }
         $upload = new Upload($file, $folderName, $fileName);
         if (isset($input["resize"]) && is_array($input["resize"])) {
             $upload->resizeImage($input["resize"][0], $input["resize"][1]);
         }
         if (!$upload->isMimeType($input["fileType"])) {
             $response["error"] = "Type de fichier non-autorisé (" . $input["fileType"] . ")";
             $this->response($response);
         }
         try {
             $upload->send();
         } catch (Exception $e) {
             $response["error"] = "Upload impossible";
             $this->response($response);
         }
         if (isset($input["fileName"]) && !empty($input["fileName"])) {
             $fileName = preg_replace("/(\\{id\\})/", $upload->id_upload, $input["fileName"]);
             $upload->renameFile($fileName);
         }
         $response["path_upload"] = Application::getInstance()->getPathPart() . $upload->pathFile;
         $response["id_upload"] = $upload->id_upload;
     }
     $this->response($response);
 }
Exemplo n.º 12
0
 /**
  * Makes a View
  *
  * @param $template
  * @param array $parameters
  * @return View
  */
 public static function make($template, array $parameters = [])
 {
     $instance = Application::get('View');
     $instance->setTemplate($template);
     $engine = $instance->getEngine();
     if (!empty($parameters)) {
         foreach ($parameters as $key => $val) {
             $engine->assign($key, $val);
         }
     }
     return $instance;
 }
Exemplo n.º 13
0
 /**
  * @param Application $application
  * @return false|mixed
  * @throws \ErrorException
  */
 public function preHandle(Application $application)
 {
     $request = $application->getRequest();
     $application->setCacheKeys($request);
     $cache = $application->getCache();
     if ($cache->exists($application->getCacheKey('response')) && !$request->isAjax()) {
         return $cache->get($application->getCacheKey('response'));
     } elseif ($cache->exists($application->getCacheKey('route')) && $application->getConfig()->get('app.cacheRoutes', true)) {
         $route = $cache->get($application->getCacheKey('route'));
         if ($route instanceof Route) {
             return $this->getRouter()->run($route);
         }
     }
     return false;
 }
Exemplo n.º 14
0
 /**
  * @covers \Core\Application\BaseApplication::run
  * @covers \Core\Application\BaseApplication::setRequest
  * @covers \Core\Request\Request::create
  * @covers \Core\Facade\Router::get
  */
 public function testIfControllersCanReturnView()
 {
     MockPaths::createMockPaths();
     $app = new Application(MockPaths::$basePath);
     Router::get('/user/{name}', '\\Core\\Tests\\Stubs\\Controllers\\StubController@testReturnView');
     $app->setRequest(Request::create('http://example.com/user/sam'));
     $app->run();
     $this->assertTrue(headers_sent());
     $this->expectOutputString("Hello sam");
 }
Exemplo n.º 15
0
<?php

require ROOT_DIRECTORY . '/autoload.php';
/**
 * @var core\contracts\resolution\ContainerInterface $container
 */
$container = (require __DIR__ . '/config/resolutions.php');
$configurations = (require __DIR__ . '/config/configurations.php');
$errors = (require __DIR__ . '/config/handlers/exceptions.php');
use core\application\Errors;
use core\application\Application;
use core\application\Configurator;
$configurator = new Configurator($configurations);
$application = new Application($configurator->require('middleware', 'array'));
$errors = new Errors($errors);
use core\events\EventEmitter;
use core\application\Dispatcher;
$events = new EventEmitter();
$dispatcher = new Dispatcher();
$container->bind($events, \core\contracts\events\EventEmitterInterface::class);
$container->bind($errors, \core\contracts\errors\ErrorHandlerInterface::class);
$container->bind($configurator, \core\contracts\configurations\ConfiguratorInterface::class);
$request = core\http\request\Factory::build();
$response = core\http\response\Factory::build();
/**
 * @var \core\contracts\routing\Resolver $resolver
 */
$resolver = $container->create(core\contracts\routing\Resolver::class);
try {
    $application->bootstrap($container, $errors, $events, [$container, 'create']);
    $context = new \core\resources\ResourceContext($resolver->lookup($request->method(), $request->uri()->path()));
Exemplo n.º 16
0
 /**
  * Méthode de correction des urls des assets utilisés dans les CSS
  * @param array $pMatches
  * @return string
  */
 private static function correctUrls($pMatches)
 {
     if (strpos($pMatches[2], 'data:image') > -1) {
         return $pMatches[0];
     }
     return $pMatches[1] . Application::getInstance()->getPathPart() . '../../' . self::$current_folder . '/' . $pMatches[2];
 }
Exemplo n.º 17
0
 /**
  * Méthode de désactivation systématique du mode de debug
  * @return void
  */
 public static function deactivateDebug()
 {
     Configuration::$global_debug = false;
     $authHandler = Application::getInstance()->authenticationHandler;
     $authHandler::$permissions = array();
 }
Exemplo n.º 18
0
 /**
  * @return array
  */
 public function getGlobalVars()
 {
     $is = array();
     /** @var AuthenticationHandler $authHandler */
     $authHandler = Application::getInstance()->authenticationHandler;
     foreach ($authHandler::$permissions as $name => $value) {
         $is[$name] = $authHandler::$data && $authHandler::is($name);
     }
     return array("path_to_theme" => Core::$path_to_theme, "path_to_components" => Core::$path_to_components, "scripts" => Autoload::scripts(), "styles" => Autoload::styles(), "head" => $this->head, "forms" => $this->forms, "content" => $this->content, "user_is" => $is, "controller" => preg_replace("/\\_/", "-", Core::$controller), "action" => preg_replace("/\\_/", "-", Core::$action));
 }
Exemplo n.º 19
0
 private static function upload($pName, $pId, $pData, $pRequire = "")
 {
     self::$ct_upload++;
     $file = $style = $value = "";
     $server_url = Configuration::$server_url;
     /**
      * @todo concaténer la valeur du relative path de l'application en cours à $server_url ?
      */
     $disabled = isset($pData["attributes"]["disabled"]) && $pData["attributes"]["disabled"] == "disabled" ? "disabled" : "";
     if (isset($pData["attributes"]["value"]) && !empty($pData["attributes"]["value"])) {
         $value = $pData["attributes"]["value"];
         $file = $server_url;
         /** @var ModelUpload $m */
         $m = isset($pData["model"]) && !empty($pData["model"]) ? $pData["model"] : "core\\models\\ModelUpload";
         if (Form::isNumeric($value)) {
             $file .= Application::getInstance()->getPathPart() . $m::getPathById($value);
         } else {
             $file .= $value;
         }
     }
     $deleteFileAction = "";
     if (isset($pData['deleteFileAction']) && !empty($pData['deleteFileAction'])) {
         if ($value && Form::isNumeric($value)) {
             $action = preg_replace('/\\{id\\}/', $value, $pData['deleteFileAction']);
         } else {
             $action = $pData['deleteFileAction'];
         }
         $deleteFileAction = 'data-delete_file_action="' . $action . '"';
     }
     $comp = "<input " . $disabled . " type='file' name='" . $pName . "_input' data-form_name='" . $pData["form_name"] . "' data-input_name='" . $pData["field_name"] . "' data-application='" . Core::$application . "' data-value='" . $value . "' data-file='" . $file . "' data-module='" . Core::$module . "'" . $deleteFileAction . ">";
     $input = self::getLabel($pData["label"] . $pRequire, $pId);
     $input .= self::getComponent($comp, 'upload');
     return $input;
 }
Exemplo n.º 20
0
 public function setUp()
 {
     $service = Application::register('Config', \Core\Config\Config::class, true);
     $service->setArguments([static::$config]);
     parent::setUp();
 }
Exemplo n.º 21
0
 /**
  * @return object
  * @throws \ErrorException
  */
 public static function kernel()
 {
     return Application::get(static::getName());
 }
Exemplo n.º 22
0
<?php

/**
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This file is part of the Core Framework package.
 *
 * (c) Shalom Sam <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Core\Application\Application;
require __DIR__ . '/../vendor/autoload.php';
$app = new Application(realpath(__DIR__ . '/../'));
$app->run();