本文整理汇总了PHP中camelize函数的典型用法代码示例。如果您正苦于以下问题:PHP camelize函数的具体用法?PHP camelize怎么用?PHP camelize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了camelize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Generates set of code based on data.
*
* @return array
*/
public function generate()
{
$this->prepareData($this->data);
$columnFields = ['name', 'description', 'label'];
$table = $this->describe->getTable($this->data['name']);
foreach ($table as $column) {
if ($column->isAutoIncrement()) {
continue;
}
$field = strtolower($column->getField());
$method = 'set_' . $field;
$this->data['camel'][$field] = lcfirst(camelize($method));
$this->data['underscore'][$field] = underscore($method);
array_push($this->data['columns'], $field);
if ($column->isForeignKey()) {
$referencedTable = Tools::stripTableSchema($column->getReferencedTable());
$this->data['foreignKeys'][$field] = $referencedTable;
array_push($this->data['models'], $referencedTable);
$dropdown = ['list' => plural($referencedTable), 'table' => $referencedTable, 'field' => $field];
if (!in_array($field, $columnFields)) {
$field = $this->describe->getPrimaryKey($referencedTable);
$dropdown['field'] = $field;
}
array_push($this->data['dropdowns'], $dropdown);
}
}
return $this->data;
}
示例2: error_messages_for
public function error_messages_for($object)
{
if ($object instanceof WaxForm) {
if ($object->bound_to_model) {
if ($object->bound_to_model->errors) {
$html = "<ul class='user_errors'>";
}
foreach ($object->bound_to_model->errors as $err => $mess) {
$html .= "<li>" . $mess[0];
}
} else {
foreach ($object->elements as $el) {
foreach ($el->errors as $er) {
$html .= sprintf($er->error_template, $er);
}
}
}
$html .= "</ul>";
return $html;
}
if (strpos($object, "_")) {
$object = camelize($object, 1);
}
$class = new $object();
$errors = $class->get_errors();
foreach ($errors as $error) {
$html .= $this->content_tag("li", Inflections::humanize($error['field']) . " " . $error['message'], array("class" => "user_error"));
}
if (count($errors) > 0) {
return $this->content_tag("ul", $html, array("class" => "user_errors"));
}
return false;
}
示例3: __call
function __call($method, $args)
{
$sphinx_method = ucfirst(camelize($method));
if (method_exists($this->client, $sphinx_method)) {
return call_user_func_array(array($this->client, $sphinx_method), $args);
}
}
示例4: transformField
/**
* Transforms the field into the template.
*
* @param string $field
* @param string $type
* @return array
*/
protected function transformField($field, $type)
{
if ($type == 'camelize') {
return ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize('get_' . $field)), 'mutator' => lcfirst(camelize('set_' . $field))];
}
return ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore('get_' . $field)), 'mutator' => lcfirst(underscore('set_' . $field))];
}
示例5: test_camelize
public function test_camelize()
{
$strs = array('this is the string' => 'thisIsTheString', 'this is another one' => 'thisIsAnotherOne', 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'whatDoYouThink-yo?');
foreach ($strs as $str => $expect) {
$this->assertEquals($expect, camelize($str));
}
}
开发者ID:saiful1105020,项目名称:Under-Construction-Bracathon-Project-,代码行数:7,代码来源:inflector_helper_test.php
示例6: generateLink
public static function generateLink($id, $name, $folder)
{
$images = array();
foreach (array(self::IMAGE_ORIGINAL, self::IMAGE_LARGE, self::IMAGE_MEDIUM, self::IMAGE_SMALL, self::IMAGE_THUMB) as $size) {
$images[camelize(strtolower($size))] = self::createLink($id, $size, $name, $folder);
}
return $images;
}
示例7: camelize
protected function camelize($string)
{
if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
return (string) self::parameters(['string' => DT::STRING])->call(__FUNCTION__)->with($string)->returning(DT::STRING);
} else {
return (string) camelize($string);
}
}
示例8: sub
function sub($commands)
{
$name = $commands[0];
$error = new Error();
$error->command_exists($name);
$options = getopt(self::SHORTOPTS, self::LONGOPTS);
$class_name = 'Pgit\\Command\\' . camelize(strtr($name, '-', '_'));
$instance = new $class_name($commands, $options);
$instance->run();
}
示例9: command_exists
public function command_exists($name)
{
$class_name = 'Pgit\\Command\\' . camelize(strtr($name, '-', '_'));
$filename = \Pgit\Autoloader::load_class_path($class_name);
if (!file_exists($filename) or !preg_match("#^[a-z\\-]+\$#", $name)) {
$message = sprintf("pgit: '%s' is not a git command. See 'pgit --help'\n", $name);
echo $message;
exit;
}
}
示例10: getTableCols
public function getTableCols()
{
$dbCols = \Meta\Db::colInfo($this->table);
$cols = array();
foreach ($dbCols as $info) {
$name = $info->Field;
// ignore some fields
if (in_array($name, array('password'))) {
continue;
}
$cols[$info->Field] = $this->getColType($info, array('id' => $name, 'label' => camelize($info->Field)));
}
return $cols;
}
示例11: getTableFields
public function getTableFields()
{
$dbCols = \Meta\Db::colInfo($this->table);
$fields = array();
foreach ($dbCols as $info) {
$name = $info->Field;
// ignore some fields
if (in_array($name, array('password'))) {
continue;
}
$fields[$info->Field] = $this->getFieldType($info, array('name' => $name, 'label' => camelize($info->Field), 'isRequired' => $info->Null == 'NO'));
}
return $fields;
}
示例12: prepareData
/**
* Prepares the data before generation.
*
* @param array $data
* @return void
*/
public function prepareData(array &$data)
{
$bootstrap = ['button' => 'btn btn-default', 'buttonPrimary' => 'btn btn-primary', 'formControl' => 'form-control', 'formGroup' => 'form-group col-lg-12 col-md-12 col-sm-12 col-xs-12', 'label' => 'control-label', 'table' => 'table table table-striped table-hover', 'textRight' => 'text-right'];
if ($data['isBootstrap']) {
$data['bootstrap'] = $bootstrap;
}
$data['camel'] = [];
$data['underscore'] = [];
$data['foreignKeys'] = [];
$data['primaryKeys'] = [];
$data['plural'] = plural($data['name']);
$data['singular'] = singular($data['name']);
$primaryKey = 'get_' . $this->describe->getPrimaryKey($data['name']);
$data['primaryKey'] = $primaryKey;
if ($this->data['isCamel']) {
$data['primaryKey'] = camelize($data['primaryKey']);
}
$data['columns'] = $this->describe->getTable($data['name']);
}
示例13: get_adapter
/**
* Loads and returns a db adapter instance.
*/
static function get_adapter($name, $params)
{
// Adapter class name convention.
$adapter_class = camelize($name) . 'Database';
// Try to load adapter class.
if (!class_exists($adapter_class)) {
$adapter_file = APP_ROOT . "core/library/db/{$adapter_class}.php";
if (is_file($adapter_file)) {
require_once $adapter_file;
}
}
// Instantiate the adapter.
$adapter = new $adapter_class($params);
// Make sure it extends Database.
if ($adapter instanceof Database == false) {
throw new Exception("{$name} is not a valid database adapter ({$adapter_class})");
}
return $adapter;
}
示例14: _run_middlewares
protected function _run_middlewares()
{
$this->load->helper('inflector');
$middlewares = $this->middleware();
foreach ($middlewares as $middleware) {
$middlewareArray = explode('|', str_replace(' ', '', $middleware));
$middlewareName = $middlewareArray[0];
$runMiddleware = true;
if (isset($middlewareArray[1])) {
$options = explode(':', $middlewareArray[1]);
$type = $options[0];
$methods = explode(',', $options[1]);
if ($type == 'except') {
if (in_array($this->router->method, $methods)) {
$runMiddleware = false;
}
} else {
if ($type == 'only') {
if (!in_array($this->router->method, $methods)) {
$runMiddleware = false;
}
}
}
}
$filename = ucfirst(camelize($middlewareName)) . 'Middleware';
if ($runMiddleware == true) {
if (file_exists(APPPATH . 'middlewares/' . $filename . '.php')) {
require APPPATH . 'middlewares/' . $filename . '.php';
$ci =& get_instance();
$object = new $filename($this, $ci);
$object->run();
$this->middlewares[$middlewareName] = $object;
} else {
if (ENVIRONMENT == 'development') {
show_error('Unable to load middleware: ' . $filename . '.php');
} else {
show_error('Sorry something went wrong.');
}
}
}
}
}
示例15: delete_model
function delete_model($name)
{
$results = array();
$name = singularize($name);
$uploader_class_suffix = 'ImageUploader';
$image_uploader_class_suffix = 'ImageUploader';
$file_uploader_class_suffix = 'FileUploader';
$uploaders_path = FCPATH . 'application/third_party/orm_uploaders/';
$model_path = FCPATH . 'application/models/' . ucfirst(camelize($name)) . EXT;
$content = read_file($model_path);
preg_match_all('/OrmImageUploader::bind\\s*\\((?P<k>.*)\\);/', $content, $image_uploaders);
$image_uploaders = array_map(function ($image_uploader) use($name, $image_uploader_class_suffix) {
return isset($image_uploader[1]) ? $image_uploader[1] : ucfirst(camelize($name)) . $image_uploader_class_suffix;
}, array_map(function ($image_uploader) {
$pattern = '/(["\'])(?P<kv>(?>[^"\'\\\\]++|\\\\.|(?!\\1)["\'])*)\\1?/';
preg_match_all($pattern, $image_uploader, $image_uploaders);
return $image_uploaders['kv'];
}, $image_uploaders['k']));
array_map(function ($image_uploader) use($uploaders_path, &$results) {
if (delete_file($uploaders_path . $image_uploader . EXT)) {
array_push($results, $uploaders_path . $image_uploader . EXT);
}
}, $image_uploaders);
preg_match_all('/OrmFileUploader::bind\\s*\\((?P<k>.*)\\);/', $content, $file_uploaders);
$file_uploaders = array_map(function ($file_uploader) use($name, $file_uploader_class_suffix) {
return isset($file_uploader[1]) ? $file_uploader[1] : ucfirst(camelize($name)) . $file_uploader_class_suffix;
}, array_map(function ($file_uploader) {
$pattern = '/(["\'])(?P<kv>(?>[^"\'\\\\]++|\\\\.|(?!\\1)["\'])*)\\1?/';
preg_match_all($pattern, $file_uploader, $file_uploaders);
return $file_uploaders['kv'];
}, $file_uploaders['k']));
array_map(function ($file_uploader) use($uploaders_path, &$results) {
if (delete_file($uploaders_path . $file_uploader . EXT)) {
array_push($results, $uploaders_path . $file_uploader . EXT);
}
}, $file_uploaders);
if (delete_file($model_path)) {
array_push($results, $model_path);
}
return $results;
}