DI model generator
This commit is contained in:
48
core/lib/Thelia/Model/Base.php
Normal file
48
core/lib/Thelia/Model/Base.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \NotORM
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param \NotORM $NotORM
|
||||
*/
|
||||
public function __construct(\NotORM $NotORM) {
|
||||
$this->db = $NotORM;
|
||||
$this->table = $this->getTableName();
|
||||
}
|
||||
|
||||
protected function getTableName()
|
||||
{
|
||||
return $this->underscore(__CLASS__);
|
||||
}
|
||||
|
||||
protected function underscore($camel_cased_word)
|
||||
{
|
||||
$tmp = $camel_cased_word;
|
||||
$tmp = str_replace('::', '/', $tmp);
|
||||
$tmp = self::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2',
|
||||
'/([a-z\d])([A-Z])/' => '\\1_\\2'));
|
||||
return strtolower($tmp);
|
||||
}
|
||||
|
||||
public static function pregtr($search, $replacePairs)
|
||||
{
|
||||
return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,9 @@ use Thelia\Model\Base;
|
||||
|
||||
class Config extends Base
|
||||
{
|
||||
|
||||
public function read($search, $default)
|
||||
{
|
||||
return $this->db->config()->where("name",$search)->fetch()?:$default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user