/** * @param string $content_type * @return self */ public function prepareContentType($content_type) { $_cls = '\\HttpFundamental\\ContentType\\' . TextHelper::toCamelCase($content_type); if (class_exists($_cls)) { return $this->setContentTypeObject(new $_cls()); } else { return $this->setContentType($content_type); } }
/** * Build a new route URL * * The class will pass arguments values to any `$this->toUrlParam($value)` method for the * parameter named `param`. * * @param mixed $route_infos The information about the route to analyze, can be a string route or an array * of arguments like `param => value` * @param string $base_uri The URI to add the new route to * @param string $hash A hash tag to add to the generated URL * @param string $separator The argument/value separator (default is escaped ampersand : '&') * * @return string The application valid URL for the route * * @todo manage the case of $route_infos = route */ public function generateUrl($route_infos, $base_uri = null, $hash = null, $separator = '&') { $url_args = $this->getArgumentsMap()->getCollection(); $url = $base_uri; if (is_array($route_infos)) { $final_params = array(); foreach ($route_infos as $_var => $_val) { if (!empty($_val)) { $arg = in_array($_var, $url_args) ? array_search($_var, $url_args) : $_var; $_meth = 'toUrl' . TextHelper::toCamelCase($_var); if (method_exists($this, $_meth)) { $_val = call_user_func_array(array($this, $_meth), array($_val)); } if (is_string($_val)) { $final_params[$this->urlEncode($arg)] = $this->urlEncode($_val); } elseif (is_array($_val)) { foreach ($_val as $_j => $_value) { $final_params[$this->urlEncode($arg) . '[' . (is_string($_j) ? $_j : '') . ']'] = $this->urlEncode($_val); } } } } $url .= '?' . http_build_query($final_params, '', $separator); } if (!empty($hash)) { $url .= '#' . $hash; } return $url; }
/** * @param mixed $name * @return void * @throws \Exception eventually caught */ public function __unset($name) { $name = strtolower($name); if (array_key_exists($name, $this::$_magic_setters_mapping)) { $meth = $this::$_magic_setters_mapping[$name]; } elseif (in_array($name, $this::$_magic_points_mapping)) { $meth = TextHelper::toCamelCase('set_point_' . $name); } else { $meth = TextHelper::toCamelCase('set_' . $name); } if (method_exists($this, $meth)) { try { call_user_func(array($this, $meth), null); } catch (\Exception $e) { throw $e; } } }
/** * Test if a classes names set is in a set of namespaces * * @param string|array $names * @param array $namespaces * @param array $logs Passed by reference * @return string|bool */ protected function _classesInNamespaces($names, array $namespaces, array &$logs = array()) { if (!is_array($names)) { $names = array($names); } foreach ($names as $_name) { foreach ($namespaces as $_namespace) { if (CodeHelper::namespaceExists($_namespace)) { $tmp_namespace = rtrim(TextHelper::toCamelCase($_namespace), '\\') . '\\'; if (substr_count(TextHelper::toCamelCase($_name), $tmp_namespace) > 0) { return $_name; } } else { $logs[] = $this->_getErrorMessage('Namespace "%s" not found!', $_namespace); } } } return false; }
/** * @covers ../../../src/Library/Helper/Text::toCamelCase() * @covers ../../../src/Library/Helper/Text::fromCamelCase() */ public function testCamelCase() { $this->checkNoArg('toCamelCase'); $this->assertEquals('MyCamelCasePhrase', \Library\Helper\Text::toCamelCase('my_camel_case_phrase')); $this->checkNoArg('fromCamelCase'); $this->assertEquals('my_camel_case_phrase', \Library\Helper\Text::fromCamelCase('MyCamelCasePhrase')); }
/** * Get a safe class property name in camel case * @param string $name * @param string $replace * @param bool $capitalize_first_char * @return string */ public static function getPropertyName($name = '', $replace = '_', $capitalize_first_char = true) { return TextHelper::toCamelCase($name, $replace, $capitalize_first_char); }
/** * @param mixed $name * @return void * @throws \Exception eventually caught */ public function __unset($name) { $_name = strtolower($name); $meth = array_key_exists($_name, $this::$_magic_setters_mapping) ? $this::$_magic_setters_mapping[$_name] : TextHelper::toCamelCase('set_' . $_name); if (method_exists($this, $meth)) { try { call_user_func(array($this, $meth), null); } catch (\Exception $e) { throw $e; } } elseif (property_exists($this, $name)) { $this->{$name} = null; } }