/home
/deploy
/EHungry-4-boyan
/Web
/classes
/Cache.class.php
- }
-
- public static function SetObject($key, $var, $expire = 86400) {
- return static::Set($key, serialize($var), $expire);
- }
-
- public static function SetArray($key, $var, $expire = 86400) {
- return static::Set($key, serialize($var), $expire);
- }
-
- public static function SetBoolean($key, $var, $expire = 86400) {
- return static::Set($key, serialize($var), $expire);
- }
-
- public static function Set($key, $var, $expire = 86400) {
- App::debugbarLog('debug', "Cache set: $key");
- if ($i = static::getInstance()) {
- $var = static::beforeSet($var);
- return $expire > 0?
- $i->setEx($key, $expire, $var) :
- $i->set($key, $var);
- }
- return null;
- }
-
- public static function Exists(...$key):?bool {
- if ($i = static::getInstance()) {
- return $i->exists($key);
- }
- return null;
- }
-
- public static function Expire($key, $ttl) {
- if ($i = static::getInstance()) {
- return $i->expire($key, $ttl);
- }
- return false;
- }
-
- /**
Arguments
"MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error. ◀MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because ▶"
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/Cache.class.php
}
public static function SetObject($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function SetArray($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function SetBoolean($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function Set($key, $var, $expire = 86400) {
App::debugbarLog('debug', "Cache set: $key");
if ($i = static::getInstance()) {
$var = static::beforeSet($var);
return $expire > 0?
$i->setEx($key, $expire, $var) :
$i->set($key, $var);
}
return null;
}
public static function Exists(...$key):?bool {
if ($i = static::getInstance()) {
return $i->exists($key);
}
return null;
}
public static function Expire($key, $ttl) {
if ($i = static::getInstance()) {
return $i->expire($key, $ttl);
}
return false;
}
/**
Arguments
"describe_hn_host_1"
86400
"a:14:{s:2:"id";s:1:"N";s:11:"hn_insecure";s:1:"S";s:9:"hn_secure";s:1:"S";s:6:"active";s:1:"B";s:16:"redirect_enabled";s:1:"B";s:13:"redirect_host";s:1:"S";s:12:"redirect_uri";s:1:"S";s:11:"ssl_expires";s:1:"D";s:15:"ssl_common_name";s:1:"S";s:7:"ssl_key";s:1:"S";s:15:"ssl_certificate";s:1:"S";s:6:"ssl_ip";s:1:"S";s:11:"dns_pointed";s:1:"B";s:14:"ssl_debug_note";s:1:"S";} ◀a:14:{s:2:"id";s:1:"N";s:11:"hn_insecure";s:1:"S";s:9:"hn_secure";s:1:"S";s:6:"active";s:1:"B";s:16:"redirect_enabled";s:1:"B";s:13:"redirect_host";s:1:"S";s:12 ▶"
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/Cache.class.php
if (!@static::$redisObj->connect(static::$host, (int)static::$port)) {
static::$redisObj = false;
Splunk::log(Splunk::LOG_REDIS_CONN, ['error' => 'Error connecting']);
} else {
static::$redisObj->select(static::$db);
}
} catch (RedisException $e) {
static::$redisObj = false;
Splunk::log(Splunk::LOG_REDIS_CONN, ['error' => 'Error connecting: '.$e->getMessage()]);
}
}
return static::$redisObj;
}
public static function SetObject($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function SetArray($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function SetBoolean($key, $var, $expire = 86400) {
return static::Set($key, serialize($var), $expire);
}
public static function Set($key, $var, $expire = 86400) {
App::debugbarLog('debug', "Cache set: $key");
if ($i = static::getInstance()) {
$var = static::beforeSet($var);
return $expire > 0?
$i->setEx($key, $expire, $var) :
$i->set($key, $var);
}
return null;
}
public static function Exists(...$key):?bool {
if ($i = static::getInstance()) {
return $i->exists($key);
Arguments
"describe_hn_host_1"
"a:14:{s:2:"id";s:1:"N";s:11:"hn_insecure";s:1:"S";s:9:"hn_secure";s:1:"S";s:6:"active";s:1:"B";s:16:"redirect_enabled";s:1:"B";s:13:"redirect_host";s:1:"S";s:12:"redirect_uri";s:1:"S";s:11:"ssl_expires";s:1:"D";s:15:"ssl_common_name";s:1:"S";s:7:"ssl_key";s:1:"S";s:15:"ssl_certificate";s:1:"S";s:6:"ssl_ip";s:1:"S";s:11:"dns_pointed";s:1:"B";s:14:"ssl_debug_note";s:1:"S";} ◀a:14:{s:2:"id";s:1:"N";s:11:"hn_insecure";s:1:"S";s:9:"hn_secure";s:1:"S";s:6:"active";s:1:"B";s:16:"redirect_enabled";s:1:"B";s:13:"redirect_host";s:1:"S";s:12 ▶"
86400
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/DbFields.php
$this->table = $table;
}
public function getFields($withTypes = false):array {
//FIXME: workaround for BaseClass objects that are not present in the database. check BaseClass::NO_TABLE
if (!$this->table) {
return [];
}
if (!$this->typesCache) { //not in the local cache, let's fetch it
$cacheKey = "describe_{$this->table}_1"; //this "1" meant "include ID" in the old code
//TODO: replace with Cache::Remember
$this->typesCache = Cache::GetArray($cacheKey);
if (!$this->typesCache || self::SKIP_CACHE) { //not in the cache either, let's generate it
$this->typesCache = collect(DB::select("DESCRIBE $this->table"))
->pluck('Type', 'Field')
->transform(['DbFields','simplifyType'])
->all();
Cache::SetArray($cacheKey, $this->typesCache);
}
}
if (!$this->fieldsCache && !$withTypes) {
$this->fieldsCache = array_keys($this->typesCache);
}
return $withTypes? $this->typesCache : $this->fieldsCache;
}
/**
* Separates all attributes into custom and pure fields (those present on the database table).
* @param array $values
* @return array 0 => custom fields, 1 => pure fields
*/
public function splitCustom(array $values) {
$tableFields = array_flip($this->getFields());
$customFields = array_diff_key($values, $tableFields);
$pureFields = array_intersect_key($values, $tableFields);
Arguments
"describe_hn_host_1"
array:14 [▶
"id" => "N"
"hn_insecure" => "S"
"hn_secure" => "S"
"active" => "B"
"redirect_enabled" => "B"
"redirect_host" => "S"
"redirect_uri" => "S"
"ssl_expires" => "D"
"ssl_common_name" => "S"
"ssl_key" => "S"
"ssl_certificate" => "S"
"ssl_ip" => "S"
"dns_pointed" => "B"
"ssl_debug_note" => "S"
]
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/BaseClass.class.php
* Checks for either legacy or Laravel-style getters (getField() or getFieldAttribute()).
* @param string $key
* @return string
*/
private function findAnyGetMutator($key):string {
return $this->findAnyMutator('get', $key);
}
public function setAttribute($key, $value) {
if ($key == 'key_name' && in_array($key, $this->fields()->getFields())) {
//TODO: another special case, there's a field with the same name as the setter for the Eloquent PK at TemplateAccountSettings
return parent::setAttribute($key, $value);
}
//first we check for the mutated setters
if ($setter = $this->findAnySetMutator($key)) {
return $this->$setter($value);
}
if (in_array($key, $this->fields()->getFields()) || array_key_exists($key, $this->attributes)) {
//this is an existing database field, so let's set it as an attribute
return parent::setAttribute($key, $value);
} elseif (property_exists($this, $key)) {
//support for legacy setter of custom props
return $this->$key = $value;
} else {
//probably a custom prop (sometimes used in legacy code), so let's set it directly on the object as usual
if (DevLevel > 0) {
trigger_error('Custom property set at '.static::class.": $key", E_USER_NOTICE);
}
return $this->$key = $value;
}
}
/**
* Sets the "created_at" field, similarly to {@link HasTimestamps::setCreatedAt()}.
*
* We had to override this method because of the legacy setters, as follows: Eloquent is based on setXyzAttribute()
* setters, but we also allow setXyz() for legacy reasons, and this happens at {@link setAttribute()}. When
* {@link updateTimestamps()} is called, it calls setUpdateAt() (which works fine because our configured field is
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/BaseClass.class.php
*/
protected static $restaurantDates = [];
/**
* @param int|array|ParameterHandler $idOrAttr An ID, so the entry is loaded from the database, or a list of attributes to be pre-filled into a new entry.
*/
public function __construct($idOrAttr = null) {
if (is_numeric($idOrAttr)) {
//legacy behavior
if ($entry = static::find($idOrAttr)) {
//TODO: find a way to have default attributes respected in the same way Eloquent does - probably a mix of array_merge() and array_filter() (so we clear empty values from the found entry), or maybe we'll need a custom merger so the final attribute array doesn't miss any field
$this->setRawAttributes($entry->attributes, true);
$this->exists = true;
}
$this->setAttribute('id', $idOrAttr);
parent::__construct();
} elseif (is_array($idOrAttr) || $idOrAttr instanceof ParameterHandler) {
parent::__construct($idOrAttr); //default Eloquent behavior + our custom fill()
} else {
$this->setAttribute('id', -1); //FIXME: legacy behavior as well... can we ditch this someday please????
parent::__construct();
}
}
/**
* We've overwritten the original query builder to include extra methods :)
* @param \Illuminate\Database\Query\Builder $query
* @return Builder|EloquentModel|eHungry\Illuminate\Database\Eloquent\Builder
*/
public function newEloquentBuilder($query) {
return new eHungry\Illuminate\Database\Eloquent\Builder($query);
}
protected static function boot() {
parent::boot();
//Registering events in a better way - https://laravel.com/docs/5.7/eloquent#events
//Based on the Ardent implementation (https://goo.gl/ieFB59), taken from Yii/Rails models
$eventTypes = ['sav', 'creat', 'updat', 'delet', 'restor', 'retriev'];
$tenses = ['ing', 'ed']; //There's NO retrieving event! a check was not placed here for performance
Arguments
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/BaseClass.class.php
/** @var static $result */
$result = $this->directFind($id, $columns);
if ($result && $columns == ['*']) {
$result->cacheSet();
}
return $result;
}
/**
* Finds one or more entries in the database. In case of single-finds, checks the cache layer first.
* @see BaseClass::SHOULD_BE_CACHED
* @see Cache
* @param int|int[] $id
* @param array $columns
* @return Collection|static|static[]|null
*/
public static function find($id, $columns = ['*']) {
return (new static)->findNew($id, $columns);
}
//FIXME: we're missing cached versions for findOrFail and findOrNew, at the very least
/** @deprecated use {@link save()} instead */
public function store() {
return $this->save();
}
/**
* Overrides the original save to return the generated ID.
* After saving, caching ({@link SHOULD_BE_CACHED}) and logging ({@link willLogChanges()}/{@link loggingChanges()})
* are done, if enabled.
* @param array $options The only option available is "touch" (which is true by default); setting it to false will
* disable "touching" parent relationships (aka belongsTo/belongsToMany) listed in
* {@link $touches}, which updates their timestamps upon a successful save.
* See https://laravel.com/docs/5.4/eloquent-relationships#touching-parent-timestamps
* @return bool|int Returns the ID in case of a successful operation, or false instead.
*/
public function save(array $options = []) {
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/BaseClass.class.php
* Stores which classes had their logging behavior overwritten during runtime.
* @var array
* @see willLogChanges()
*/
private static $overwrittenLogChanges = [];
/**
* @var array Indicates the fields which should be placed in the restaurant's timezone when casting to JSON
* @see addDateAttributesToArray()
* @see https://github.com/ehungry/EHungry/wiki/Data-standards#timezone-less-restaurant-times
*/
protected static $restaurantDates = [];
/**
* @param int|array|ParameterHandler $idOrAttr An ID, so the entry is loaded from the database, or a list of attributes to be pre-filled into a new entry.
*/
public function __construct($idOrAttr = null) {
if (is_numeric($idOrAttr)) {
//legacy behavior
if ($entry = static::find($idOrAttr)) {
//TODO: find a way to have default attributes respected in the same way Eloquent does - probably a mix of array_merge() and array_filter() (so we clear empty values from the found entry), or maybe we'll need a custom merger so the final attribute array doesn't miss any field
$this->setRawAttributes($entry->attributes, true);
$this->exists = true;
}
$this->setAttribute('id', $idOrAttr);
parent::__construct();
} elseif (is_array($idOrAttr) || $idOrAttr instanceof ParameterHandler) {
parent::__construct($idOrAttr); //default Eloquent behavior + our custom fill()
} else {
$this->setAttribute('id', -1); //FIXME: legacy behavior as well... can we ditch this someday please????
parent::__construct();
}
}
/**
* We've overwritten the original query builder to include extra methods :)
* @param \Illuminate\Database\Query\Builder $query
* @return Builder|EloquentModel|eHungry\Illuminate\Database\Eloquent\Builder
*/
public function newEloquentBuilder($query) {
Arguments
/home
/deploy
/EHungry-4-boyan
/Web
/classes
/HnHost.class.php
public static function getFromSecure($secure, $activeOnly = true) {
if ($activeOnly) {
$cacheKey = HnHost::getDomainCacheKey($secure);
$aObj = Cache::GetObject($cacheKey, true);
if ($aObj || is_null($aObj)) {
return $aObj;
}
}
$hn = null;
$db_conn = DB::conn();
$sql = "SELECT id FROM ".HnHost::getTableName()." WHERE hn_secure = ?";
if ($activeOnly) {
$sql .= ' AND active = 1';
}
$db_conn->bindParameter($sql, 1, $secure, 'string');
$result = $db_conn->query($sql);
if ($result && $result->rowCount() > 0) {
$row = $result->fetch();
$hn = new HnHost($row['id']);
}
if ($activeOnly) {
Cache::SetObject($cacheKey, $hn);
}
return $hn;
}
}
Arguments
/home
/deploy
/EHungry-4-boyan
/PHP
/Global.php
if (!function_exists('HN_DevToLive')) {
die('Function HN_DevToLive must be defined in AutoConf/Local.php');
}
try {
define('HN_Current', strtolower(HN_DevToLive($_SERVER['HTTP_HOST']))); //phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase
define('HN_SSL', ($_SERVER['HTTP_SCHEME'] == 'https'));
} catch (DomainException $e) {
$status = new AccessStatus();
/** @noinspection PhpUndefinedFieldInspection */
$status->close_message = <<<HTML
This subdomain probably has no SSL configured for it.<br/>
Check if there's no typo on the URL; otherwise, go to the <a href="https://order.ehungry.com.$e->baseSuffix/rcs/?form=devtools" target="_blank">Super Admin</a> and generate an SSL Cert for <tt>{$e->baseDomain}</tt>
HTML;
include(App_Path.'/Web/closed.php');
exit(0);
}
}
$hnHost = !TEST_ENV?
HnHost::getFromSecure(HN_Current) :
HnHost::unguarded(function () {
return new HnHost(TEST_HOST);
});
if (!$hnHost) {
$status = new AccessStatus();
$status->close_message = 'The URL you were trying to access is not valid on this server. If you feel this is in error, please contact your restaurant or online ordering provider. Sorry for any inconvenience!';
//if HN_DevToLive() didn't throw up, but still we end up here, this might be just a 404 error, or an actual missing
// SSL cert when accessing DevLevel 2 intentionally. Thus, let's include a helper message as well.
if (DevLevel >= 2) {
preg_match('/^(.*)\.(\d+)\.(.*)$/', $_SERVER['HTTP_HOST'], $domainPieces);
if (sizeof($domainPieces) == 4) {
$status->close_message .= "<br/><br/>Psst... developer! This may also be a missing SSL Cert.<br/>If there's no typo on the URL, <a href='https://order.ehungry.com.$domainPieces[2].$domainPieces[3]/rcs/?form=devtools'>generate a certificate</a> for <tt>$domainPieces[1]</tt>";
}
}
include(App_Path.'/Web/closed.php');
exit(0);
}
Arguments
"us.chinesemenuonline.com"
/home
/deploy
/EHungry-4-boyan
/Web
/index.php
<? /** @noinspection PhpIncludeInspection - to avoid marking dynamic includes */
//TODO create a «root»/_bootstrap.php which can be used by .psysh.php, tests/bootstrap.php and Web/index.php
require(dirname(__DIR__).'/PHP/base_consts.php');
require(dirname(__DIR__).'/PHP/autoloader.php');
initializeAutoLoader();
//disabled for now since we already have our own Alerts infrastructure, and it's not worth it to append another cloud provider to the startup of every freaking request; it's also not possible to catch errors this early if we depend on database checks, but we'll leave it here in case we change our mind?
//ErrorHandlers::sentryInit(); //early catch of errors and failsafe for smaller controllers, not in Sentry
App::startTime();
ErrorHandlers::register();
// Global.php is the core setup file for the application
App::debugbarTime('Global.php');
require(dirname(__DIR__) . '/PHP/Global.php');
App::debugbarTime('Global.php');
/** @var string $controller The main controller - defined at /PHP/Global.php */
App::debugbarTime('Sentry - controller');
ErrorHandlers::sentryInit($controller); //doesn't always do much - not every controller has a Sentry project
App::debugbarTime('Sentry - controller');
App::debugbarTime("controller: $controller");
apache_note('AppController', $controller);
if (file_exists(CORE_PATH."lib/helpers/$controller.php")) {
require CORE_PATH."lib/helpers/$controller.php";
}
require CORE_PATH."controllers/$controller.php";
App::debugbarTime("controller: $controller");
Arguments
"/home/deploy/EHungry-4-boyan/PHP/Global.php"