/** * Set Custom Route Method * * @param string $custom_method the custom method * @return object $instance Current Class */ public static function method($custom_method) { $instance = self::singleton(); $last_route = empty($instance->x_last_route['route']) || !isset($instance->x_last_route['name']) ? null : $instance->x_last_route; if (!$last_route || !isset($instance->x_routes[$last_route['name']][$last_route['route']]['function']) || !is_callable($instance->x_routes[$last_route['name']][$last_route['route']]['function'])) { if (isset($last_route)) { unset($instance->x_routes[$last_route['name']][$last_route['route']]); } return $instance; } if (is_string($custom_method)) { $method = strtoupper(trim($custom_method)); if (strpos($custom_method, '|') !== false) { $custom_method = explode('|', $method); $custom_method = array_map('trim', $custom_method); } } if (is_array($custom_method)) { $custom_method = Internal::strtoUpper($custom_method); if (in_array('ALL', $custom_method)) { $method = 'ALL'; } else { $method = ''; foreach ($custom_method as $value) { if (is_string($value)) { if ($value != 'ALL' || !defined("\\" . __NAMESPACE__ . "\\Http\\Request::{$value}")) { continue; } $value = trim(strtoupper($value)); $method .= "{$value}|"; if ($value == 'ALL') { $method = 'ALL'; break; } } } $method = trim($method, "|"); } } /** * Set & CHeck Method */ if (!$method || is_string($custom_method) && strpos($method, '|') === false && ($method == 'ALL' || !defined("\\" . __NAMESPACE__ . "\\Http\\Request::{$method}"))) { $method = 'ALL'; } $key = $last_route['name']; $route = $last_route['route']; // reset $x_method = null; /** * Check Method parsing array */ if (!empty($instance->x_routes[$key][$route]) && $method != 'ALL') { $x_method = strtoupper($instance->x_routes[$key][$route]['method']); $ex = $x_method == 'ALL' ? array() : explode('|', $x_method); $method = array_unique(array_merge($ex, explode('|', $method))); $method = implode('|', $method); } $instance->x_routes[$key][$route]['method'] = trim($method, '|'); if (!isset($instance->x_routes[$key][$route]['param']) || !is_array($instance->x_routes[$key][$route]['param'])) { $instance->x_routes[$key][$route]['param'] = array(); } unset($x_method, $method); // $instance->x_last_route = null; return $instance; }