Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 25a30e8

Browse files
committed
✨ add is() method to handle codeigniter interanl is_* helper functions
Signed-off-by: otengkwame <[email protected]>
1 parent f201ef0 commit 25a30e8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

framework/core/Common.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,60 @@ function is_really_writable($file)
124124

125125
// ------------------------------------------------------------------------
126126

127+
if ( ! function_exists('is'))
128+
{
129+
/**
130+
* 'Is' function
131+
*
132+
* @param string $key
133+
* @param string $value
134+
* @return boolean
135+
*/
136+
function is($key, $value = null)
137+
{
138+
$common = ['https', 'cli', 'php', 'writable'];
139+
$useragent = ['browser', 'mobile', 'referral', 'robot'];
140+
141+
if (in_array($key, $useragent))
142+
{
143+
return get_instance()->user_agent->{'is_'.$key}($value);
144+
}
145+
146+
if (in_array($key, $common))
147+
{
148+
$function = ($key == 'writable')
149+
? 'is_really_writable'
150+
: 'is_'.$key;
151+
152+
return $function($value);
153+
}
154+
155+
if ($key == 'ajax')
156+
{
157+
return get_instance()->input->is_ajax_request();
158+
}
159+
160+
if ($key == 'post')
161+
{
162+
return (get_instance()->input->server('REQUEST_METHOD') === 'POST');
163+
}
164+
165+
if ($key == 'get')
166+
{
167+
return (get_instance()->input->server('REQUEST_METHOD') === 'GET');
168+
}
169+
170+
if ($key == 'loaded' OR $key == 'load')
171+
{
172+
return (bool) get_instance()->load->is_loaded($value);
173+
}
174+
175+
return false;
176+
}
177+
}
178+
179+
// ------------------------------------------------------------------------
180+
127181
if ( ! function_exists('load_class'))
128182
{
129183
/**

0 commit comments

Comments
 (0)