mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 22:52:35 +03:00
Implementation of core engine components.
This commit is contained in:
parent
7faa4bf974
commit
ec07dddb4c
8 changed files with 582 additions and 0 deletions
23
src/engine/Core/Controller.php
Normal file
23
src/engine/Core/Controller.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Controller
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Controller extends \CI_Controller {
|
||||
|
||||
}
|
43
src/engine/Core/Framework.php
Normal file
43
src/engine/Core/Framework.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Framework
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Framework {
|
||||
/**
|
||||
* Get the framework instance.
|
||||
*
|
||||
* @return \CI_Controller
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
return get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magit get method that gives access to the internal members of the framework intance.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return self::getInstance()->$key;
|
||||
}
|
||||
}
|
145
src/engine/Core/Input.php
Normal file
145
src/engine/Core/Input.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Input
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Input {
|
||||
/**
|
||||
* @var \EA\Engine\Core\Framework
|
||||
*/
|
||||
private $framework;
|
||||
|
||||
/**
|
||||
* Input constructor.
|
||||
*
|
||||
* @param Framework $framework
|
||||
*/
|
||||
public function __construct(Framework $framework)
|
||||
{
|
||||
$this->framework = $framework;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get request (either GET or POST) parameter (not filtered/escaped).
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function request($key)
|
||||
{
|
||||
return isset($_REQUEST[$key]) ? $_REQUEST[$key] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GET parameter value.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$this->framework->input->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get POST parameter value.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function post($key)
|
||||
{
|
||||
$this->framework->input->post($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get COOKIE parameter value.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function cookie($key)
|
||||
{
|
||||
return $this->framework->input->cookie($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SERVER parameter value.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function server($key)
|
||||
{
|
||||
return $this->framework->input->server($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw request input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function raw()
|
||||
{
|
||||
return $this->framework->input->raw_input_stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get json decoded raw request input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function json()
|
||||
{
|
||||
return json_decode($this->framework->input->raw_input_stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request headers as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function headers()
|
||||
{
|
||||
return $this->framework->input->request_headers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request header value.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function header($key)
|
||||
{
|
||||
return $this->framework->input->get_request_header($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this is a CLI request or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCliRequest()
|
||||
{
|
||||
return $this->framework->is_cli_request();
|
||||
}
|
||||
}
|
23
src/engine/Core/Migration.php
Normal file
23
src/engine/Core/Migration.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Migration
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Migration extends \CI_Migration {
|
||||
|
||||
}
|
23
src/engine/Core/Model.php
Normal file
23
src/engine/Core/Model.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Model
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Model extends \CI_Model {
|
||||
|
||||
}
|
82
src/engine/Core/Output.php
Normal file
82
src/engine/Core/Output.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Output
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Output {
|
||||
/**
|
||||
* @var \EA\Engine\Core\Framework
|
||||
*/
|
||||
private $framework;
|
||||
|
||||
/**
|
||||
* Output constructor.
|
||||
*
|
||||
* @param Framework $framework
|
||||
*/
|
||||
public function __construct(Framework $framework)
|
||||
{
|
||||
$this->framework = $framework;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output HTML markup content.
|
||||
*
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param array $headers
|
||||
*/
|
||||
public function html($content, $statusCode = 200, array $headers = [])
|
||||
{
|
||||
$headers[] = 'Content-Type: text/html';
|
||||
$this->write($content, $statusCode, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output JSON encoded content.
|
||||
*
|
||||
* @param mixed $content
|
||||
* @param int $statusCode
|
||||
* @param array $headers
|
||||
*/
|
||||
public function json($content, $statusCode = 200, array $headers = [])
|
||||
{
|
||||
$headers[] = 'Content-Type: application/json; charset=utf-8';
|
||||
$content = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$this->write($content, $statusCode, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output arbitrary content with custom status and headers.
|
||||
*
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param array $headers
|
||||
*/
|
||||
public function write($content, $statusCode = 200, array $headers = [])
|
||||
{
|
||||
$this->framework->output->set_status_header($statusCode);
|
||||
|
||||
foreach ($headers as $header)
|
||||
{
|
||||
$this->framework->output->set_header($header);
|
||||
}
|
||||
|
||||
$this->framework->output->set_output($content);
|
||||
}
|
||||
}
|
166
src/engine/Core/QueryBuilder.php
Normal file
166
src/engine/Core/QueryBuilder.php
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class QueryBuilder
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class QueryBuilder {
|
||||
/**
|
||||
* @var \EA\Engine\Core\Framework
|
||||
*/
|
||||
private $framework;
|
||||
|
||||
/**
|
||||
* QueryBuilder constructor.
|
||||
*
|
||||
* @param \EA\Engine\Core\Framework $framework
|
||||
*/
|
||||
public function __construct(Framework $framework)
|
||||
{
|
||||
$this->framework = $framework;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count matching query rows.
|
||||
*
|
||||
* @param string $table
|
||||
* @param mixed $conditions
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count($table, $conditions)
|
||||
{
|
||||
return $this->framework->db->get_where($table, $conditions)->num_rows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an arbitrary query to the databbase.
|
||||
*
|
||||
* @param $query
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
return $this->framework->db->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single database row, based on the provided conditions.
|
||||
*
|
||||
* @param string $table
|
||||
* @param mixed $conditions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function row($table, $conditions)
|
||||
{
|
||||
return $this->framework->db->get_where($table, $conditions)->row_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of rows, based on the provided parameters.
|
||||
*
|
||||
* @param string $table
|
||||
* @param mixed|null $conditions
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @param mixed|null $order
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function collection($table, $conditions = NULL, $limit = NULL, $offset = NULL, $order = NULL)
|
||||
{
|
||||
if ($limit)
|
||||
{
|
||||
$this->framework->db->limit($limit);
|
||||
}
|
||||
|
||||
if ($limit && $offset)
|
||||
{
|
||||
$this->framework->db->limit($limit, $offset);
|
||||
}
|
||||
|
||||
if ($order)
|
||||
{
|
||||
$this->framework->db->order_by($order);
|
||||
}
|
||||
|
||||
if ($conditions)
|
||||
{
|
||||
$this->framework->db->where($conditions);
|
||||
}
|
||||
|
||||
return $this->framework->db->get($table)->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new database row.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $row
|
||||
*
|
||||
* @return int Returns the inserted ID.
|
||||
*/
|
||||
public function insert($table, $row)
|
||||
{
|
||||
$this->framework->db->insert($table, $row);
|
||||
|
||||
return $this->framework->db->insert_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing database row.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $row
|
||||
* @param mixed $conditions
|
||||
*
|
||||
* @return mixed Returns the operation result.
|
||||
*/
|
||||
public function update($table, $row, $conditions)
|
||||
{
|
||||
return $this->framework->db->update($table, $row, $conditions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing database row.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $row
|
||||
* @param mixed $conditions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete($table, $row, $conditions)
|
||||
{
|
||||
return $this->framework->db->delete($table, $row, $conditions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a raw value before using it in a query.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function escape($value)
|
||||
{
|
||||
return $this->framework->db->escape($value);
|
||||
}
|
||||
}
|
77
src/engine/Core/Session.php
Normal file
77
src/engine/Core/Session.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
namespace EA\Engine\Core;
|
||||
|
||||
/**
|
||||
* Class Session
|
||||
*
|
||||
* @package EA\Engine\Core
|
||||
*/
|
||||
class Session {
|
||||
/**
|
||||
* @var \EA\Engine\Core\Framework
|
||||
*/
|
||||
private $framework;
|
||||
|
||||
/**
|
||||
* Session constructor.
|
||||
*
|
||||
* @param Framework $framework
|
||||
*/
|
||||
public function __construct(Framework $framework)
|
||||
{
|
||||
$this->framework = $framework;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new session for the current user.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->framework->load->library('session');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the session of the current user.
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$this->framework->session->sess_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a session value.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return $this->framework->session->userdata($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a session value.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->framework->session->userdata($key, $value);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue