Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add magic __isset to classes with __get #2231

Merged
merged 6 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ public function __get(string $key)

//--------------------------------------------------------------------

/**
* Makes it simple to check our protected properties.
*
* @param string $key
*
* @return bool
*/
public function __isset(string $key): bool
{
return isset($this->$key);
}

//--------------------------------------------------------------------

/**
* show Help include (usage,arguments,description,options)
*/
Expand Down
14 changes: 14 additions & 0 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1864,4 +1864,18 @@ public function __get(string $key)

//--------------------------------------------------------------------

/**
* Checker for properties existence.
*
* @param string $key
*
* @return bool
*/
public function __isset(string $key): bool
{
return property_exists($this, $key);
}

//--------------------------------------------------------------------

}
11 changes: 11 additions & 0 deletions system/Encryption/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,15 @@ public function __get($key)
return null;
}

/**
* __isset() magic, providing checking for some of our protected properties
*
* @param string $key Property name
* @return bool
*/
public function __isset($key): bool
{
return in_array($key, ['key', 'digest', 'driver', 'drivers'], true);
}

}
10 changes: 10 additions & 0 deletions system/Encryption/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ public function __get($key)
return null;
}

/**
* __isset() magic, providing checking for some of our properties
*
* @param string $key Property name
* @return bool
*/
public function __isset($key): bool
{
return in_array($key, ['cipher', 'key'], true);
}
}
16 changes: 16 additions & 0 deletions system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,4 +1342,20 @@ public function __get($name)
return null;
}

//--------------------------------------------------------------------

/**
* Allow for property-type checking to any getX method...
*
* @param $name
*
* @return bool
*/
public function __isset($name): bool
{
$method = 'get' . ucfirst($name);

return method_exists($this, $method);
}

}
15 changes: 15 additions & 0 deletions system/I18n/TimeDifference.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,19 @@ public function __get($name)

return null;
}

/**
* Allow property-like checking for our calculated values.
*
* @param $name
*
* @return bool
*/
public function __isset($name)
{
$name = ucfirst(strtolower($name));
$method = "get{$name}";

return method_exists($this, $method);
}
}
25 changes: 25 additions & 0 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,31 @@ public function __get(string $name)
return null;
}

/**
* Checks for the existence of properties across this model, builder, and db connection.
*
* @param string $name
*
* @return bool
*/
public function __isset(string $name): bool
{
if (in_array($name, ['primaryKey', 'table', 'returnType', 'DBGroup']))
{
return true;
}
elseif (isset($this->db->$name))
{
return true;
}
elseif (isset($this->builder()->$name))
{
return true;
}

MGatner marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

//--------------------------------------------------------------------

/**
Expand Down
16 changes: 16 additions & 0 deletions system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,22 @@ public function __get(string $key)
return null;
}

//--------------------------------------------------------------------

/**
* Magic method to check for session variables
*
* @param string $key Identifier of the session property to remove.
*
* @return bool
*/
public function __isset(string $key): bool
{
// Note: Keep this order the same, just in case somebody wants to
// use 'session_id' as a session data key, for whatever reason
return isset($_SESSION[$key]) || ($key === 'session_id');
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Flash Data Methods
Expand Down