A super easy PHP Framework for web development! https://github.com/exacti/phacil-framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.6 KiB

6 years ago
<?php
/*
* Copyright © 2021 ExacTI Technology Solutions. All rights reserved.
* GPLv3 General License.
* https://exacti.com.br
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
*/
namespace Phacil\Framework;
use Phacil\Framework\Registry;
use Phacil\Framework\Interfaces\Model as ModelInterface;
/**
* The default model class.
*
* @example class MyModel extends \Phacil\Framework\Model
*
* @package Phacil\Framework
* @abstract
* @api
*/
abstract class Model implements ModelInterface {
/**
*
* @var Registry
*/
6 years ago
protected $registry;
/**
* @param Registry $registry
* @return void
*/
public function __construct(Registry $registry = NULL) {
if (!$registry) {
/**
* @var \Phacil\Framework\Registry
*/
$registry = \Phacil\Framework\Registry::getInstance();
}
$this->registry = &$registry;
}
/** @return void */
private function __getRegistryClass()
{
$this->registry = \Phacil\Framework\startEngineExacTI::getRegistry();
6 years ago
}
/**
*
* {@inheritdoc}
*/
static public function getInstance()
{
$class = get_called_class();
return \Phacil\Framework\Registry::getAutoInstance((new $class()));
}
6 years ago
/**
*
* @param mixed $key
* @return mixed
*/
6 years ago
public function __get($key) {
if (!$this->registry) {
$this->__getRegistryClass();
}
6 years ago
return $this->registry->get($key);
}
/**
*
* @param mixed $key
* @param mixed $value
* @return void
*/
6 years ago
public function __set($key, $value) {
if (!$this->registry) {
$this->__getRegistryClass();
}
6 years ago
$this->registry->set($key, $value);
}
}