当前位置: 首页>>代码示例>>PHP>>正文


PHP Str::singular方法代码示例

本文整理汇总了PHP中Str::singular方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::singular方法的具体用法?PHP Str::singular怎么用?PHP Str::singular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Str的用法示例。


在下文中一共展示了Str::singular方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDiff

 public static function getDiff($from, $to)
 {
     $dStart = new DateTime(date('Y-m-d H:i', $from));
     $dEnd = new DateTime(date('Y-m-d H:i', $to));
     $dDiff = $dStart->diff($dEnd);
     if ($dDiff->days > 0) {
         $time = $dDiff->days;
         $word = "days";
     } else {
         if ($dDiff->h > 0) {
             $time = $dDiff->h;
             $word = "hours";
         } else {
             if ($dDiff->i > 0) {
                 $time = $dDiff->i;
                 $word = "minutes";
             } else {
                 return "Less than a minute ago";
             }
         }
     }
     if ($time == 1) {
         $word = Str::singular($word);
     }
     return $time . " " . $word . " ago";
 }
开发者ID:kreezxil,项目名称:TechnicSolder,代码行数:26,代码来源:TimeUtils.php

示例2: form

 /**
  * Creates a typical form heading "Edit project X", "Add a client"
  *
  * @param  string $verb   The verb
  * @param  string $noun   The noun
  * @param  string $object The model's representation (ex. $model->name)
  * @return string         A form heading
  */
 public static function form($verb, $noun, $object = null)
 {
     $article = $object ? 'the' : 'a';
     $noun = \Str::singular($noun);
     $message = Babel::create();
     $message->verb($verb)->article($article)->noun($noun);
     if ($object) {
         $message->object($object);
     }
     return $message->speak();
 }
开发者ID:SerdarSanri,项目名称:babel,代码行数:19,代码来源:Babel.php

示例3: _model_generation

 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _model_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     // set up the markers for replacement within source
     $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#TIMESTAMPS#' => $this->_timestamps);
     // loud our model template
     $template = Common::load_template('model/model.tpl');
     // holder for relationships source
     $relationships_source = '';
     // loop through our relationships
     foreach ($this->arguments as $relation) {
         // if we have a valid relation
         if (!strstr($relation, ':')) {
             continue;
         }
         // split
         $relation_parts = explode(':', Str::lower($relation));
         // we need two parts
         if (!count($relation_parts) == 2) {
             continue;
         }
         // markers for relationships
         $rel_markers = array('#SINGULAR#' => Str::lower(Str::singular($relation_parts[1])), '#PLURAL#' => Str::lower(Str::plural($relation_parts[1])), '#WORD#' => Str::classify(Str::singular($relation_parts[1])), '#WORDS#' => Str::classify(Str::plural($relation_parts[1])));
         // start with blank
         $relationship_template = '';
         // use switch to decide which template
         switch ($relation_parts[0]) {
             case "has_many":
             case "hm":
                 $relationship_template = Common::load_template('model/has_many.tpl');
                 break;
             case "belongs_to":
             case "bt":
                 $relationship_template = Common::load_template('model/belongs_to.tpl');
                 break;
             case "has_one":
             case "ho":
                 $relationship_template = Common::load_template('model/has_one.tpl');
                 break;
             case "has_and_belongs_to_many":
             case "hbm":
                 $relationship_template = Common::load_template('model/has_and_belongs_to_many.tpl');
                 break;
         }
         // add it to the source
         $relationships_source .= Common::replace_markers($rel_markers, $relationship_template);
     }
     // add a marker to replace the relationships stub
     // in the model template
     $markers['#RELATIONS#'] = $relationships_source;
     // add the generated model to the writer
     $this->writer->create_file('Model', $prefix . $this->class_prefix . $this->class, $this->bundle_path . 'models/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
 }
开发者ID:downleave,项目名称:blog,代码行数:60,代码来源:model.php

示例4: getEdit

 public function getEdit($pic_id)
 {
     $pic_dir = $this->pic_dir . '/' . $pic_id;
     $pic_dir_temp = $pic_dir . '/tmp';
     $formdata = array('_id' => $pic_id);
     $ps = Config::get('picture.sizes');
     $prefixes = array();
     foreach ($ps as $px) {
         $prefixes[] = $px['prefix'];
     }
     if (is_array($prefixes)) {
         $regex = implode('|^', $prefixes);
         $regex = '^tmp|^' . $regex;
     } else {
         $regex = '^tmp';
     }
     if (file_exists($pic_dir)) {
         if (file_exists($pic_dir . '/tmp')) {
         } else {
             mkdir($pic_dir . '/tmp');
         }
     }
     $pictures = glob($pic_dir . '/*');
     if (is_array($pictures)) {
         $raw = '';
         foreach ($pictures as $pic) {
             $pic = str_replace(array($pic_dir . '/', $pic_dir_temp), '', $pic);
             if (!preg_match('/' . $regex . '/', $pic)) {
                 $raw = $pic;
             }
         }
     }
     copy($pic_dir . '/' . $raw, $pic_dir_temp . '/' . $raw);
     $image = Image::make($pic_dir_temp . '/' . $raw);
     $info = array();
     $info['filename'] = $raw;
     $info['width'] = $image->width();
     $info['height'] = $image->height();
     $info['ratio'] = $image->width() / $image->height();
     $src_url = URL::to('storage/media/' . $pic_id . '/tmp/' . $raw);
     $this->backlink = URL::to('property');
     return View::make('picture.edit')->with('title', 'Edit ' . Str::singular($this->controller_name))->with('formdata', $formdata)->with('submit', URL::to('picture/edit'))->with('src_url', $src_url)->with('pic_info', $info)->with('pic_dir', $this->pic_dir)->with('pic_temp_dir', $this->pic_temp_dir)->with('back', $this->backlink)->with('pic_id', $pic_id);
 }
开发者ID:awidarto,项目名称:tmadminflat,代码行数:43,代码来源:PictureController.php

示例5: store

 public function store()
 {
     //make plural, title case
     $title = mb_convert_case(Str::plural(Input::get('title')), MB_CASE_TITLE, 'UTF-8');
     //determine table name, todo check if unique
     $name = Str::slug($title, '_');
     //model name
     $model = Str::singular(Str::studly($title));
     //enforce predence always ascending
     $order_by = Input::get('order_by');
     $direction = Input::get('direction');
     if ($order_by == 'precedence') {
         $direction = 'asc';
     }
     //create entry in objects table for new object
     $object_id = DB::table(DB_OBJECTS)->insertGetId(['title' => $title, 'name' => $name, 'model' => $model, 'order_by' => $order_by, 'direction' => $direction, 'list_grouping' => Input::get('list_grouping'), 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id]);
     //create title field for table by default
     DB::table(DB_FIELDS)->insert(['title' => 'Title', 'name' => 'title', 'type' => 'string', 'visibility' => 'list', 'required' => 1, 'object_id' => $object_id, 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id, 'precedence' => 1]);
     self::addTable($name, true);
     self::saveSchema();
     return Redirect::action('InstanceController@index', $name);
 }
开发者ID:joshreisner,项目名称:avalon,代码行数:22,代码来源:ObjectController.php

示例6: resource

 /**
  * Generate resource (model, controller, and views)
  *
  * @param $args array  
  * @return void
  */
 public function resource($args)
 {
     // Pluralize controller name
     if (!preg_match('/admin|config/', $args[0])) {
         $args[0] = Str::plural($args[0]);
     }
     $this->controller($args);
     // Singular for everything else
     $resource_name = Str::singular(array_shift($args));
     // Let's take any supplied view names, and set them
     // in the resource name's directory.
     $views = array_map(function ($val) use($resource_name) {
         return "{$resource_name}.{$val}";
     }, $args);
     $this->view($views);
     $this->model($resource_name);
 }
开发者ID:Thuraya039,项目名称:Laravel-Generator,代码行数:23,代码来源:generate.php

示例7: attrContains

 /**
  * Check if the $attr is a plural form of $field, case insensitive,
  * or if the $field contains the $attr
  * 
  * @param  string $field
  * @param  string $attr  
  * @return boolean
  */
 protected function attrContains($field, $attr)
 {
     return $field == \Str::singular(strtoupper($attr)) || $field == \Str::singular($attr) || $field == strtoupper($attr) || \Str::contains($field, $attr);
 }
开发者ID:albertgrala,项目名称:notes,代码行数:12,代码来源:NotesShowCommand.php

示例8: addJoiningTable

 public static function addJoiningTable($object_name, $related_object_id)
 {
     //use field_name to store joining table
     $columns = [Str::singular(DB::table(DB_OBJECTS)->where('id', $related_object_id)->pluck('name')), Str::singular($object_name)];
     sort($columns);
     $field_name = implode('_', $columns);
     //create joining table
     Schema::create($field_name, function ($table) use($columns) {
         foreach ($columns as $column) {
             $table->integer($column . '_id');
         }
     });
 }
开发者ID:joshreisner,项目名称:avalon,代码行数:13,代码来源:FieldController.php

示例9: postEdit

 public function postEdit($_id, $data = null)
 {
     $controller_name = strtolower($this->controller_name);
     //print_r(Session::get('permission'));
     $this->backlink = $this->backlink == '' ? $controller_name : $this->backlink;
     $validation = Validator::make($input = Input::all(), $this->validator);
     $actor = isset(Auth::user()->email) ? Auth::user()->fullname . ' - ' . Auth::user()->email : 'guest';
     if ($validation->fails()) {
         Event::fire('log.a', array($controller_name, 'update', $actor, 'validation failed'));
         return Redirect::to($controller_name . '/edit/' . $_id)->withInput(Input::all())->withErrors($validation);
     } else {
         if (is_null($data)) {
             $data = Input::get();
         }
         $id = new MongoId($_id);
         $data['lastUpdate'] = new MongoDate();
         unset($data['csrf_token']);
         unset($data['_id']);
         // process tags by default
         if (isset($data['tags'])) {
             $tags = $this->tagToArray($data['tags']);
             $data['tagArray'] = $tags;
             $this->saveTags($tags);
         }
         $model = $this->model;
         $data = $this->beforeUpdate($id, $data);
         if ($obj = $model->where('_id', $id)->update($data)) {
             $obj = $this->afterUpdate($id, $data);
             if ($obj != false) {
                 Event::fire('log.a', array($controller_name, 'update', $actor, json_encode($obj)));
                 return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saved successfully');
             }
         } else {
             Event::fire('log.a', array($controller_name, 'update', $actor, 'saving failed'));
             return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saving failed');
         }
     }
 }
开发者ID:awidarto,项目名称:bilnatracker,代码行数:38,代码来源:AdminController.php

示例10: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $this->init();
     $data = $this->model->find($id);
     $this->model->whereId($id)->delete();
     Event::fire('activity', array('message' => 'deleted ' . Str::singular($this->subject) . ' ' . $id . '.'));
     return json_encode(array('success' => true, 'data' => $data));
 }
开发者ID:carriercomm,项目名称:saaspanel,代码行数:14,代码来源:RestController.php

示例11: postEdit

 public function postEdit($_id, $data = null)
 {
     $is_mongo = false;
     if ($this->model instanceof Jenssegers\Mongodb\Model) {
         $is_mongo = true;
     }
     $controller_name = strtolower($this->controller_name);
     //print_r(Session::get('permission'));
     $this->backlink = $this->backlink == '' ? $controller_name : $this->backlink;
     $validation = Validator::make($input = Input::all(), $this->validator);
     $actor = isset(Auth::user()->email) ? Auth::user()->fullname . ' - ' . Auth::user()->email : 'guest';
     if ($validation->fails()) {
         Event::fire('log.a', array($controller_name, 'update', $actor, 'validation failed'));
         return Redirect::to($controller_name . '/edit/' . $_id)->withInput(Input::all())->withErrors($validation);
     } else {
         if (is_null($data)) {
             $data = Input::get();
         }
         if ($is_mongo) {
             $id = new MongoId($_id);
             $data['lastUpdate'] = new MongoDate();
         } else {
             $id = $_id;
             $data['lastUpdate'] = date('Y-m-d H:i:s', time());
         }
         //`_token` = 6UZKgUN9JxzDN5MDQcgDMJmN5l2kHoCyIggGfsT0, `lastUpdate` = 2015-10-31 16:41:19, `updated_at` = 2015-10-31 16:41:19
         unset($data['csrf_token']);
         unset($data['_id']);
         // process tags by default
         if (isset($data['tags'])) {
             $tags = $this->tagToArray($data['tags']);
             $data['tagArray'] = $tags;
             $this->saveTags($tags);
         }
         $model = $this->model;
         $data = $this->beforeUpdate($id, $data);
         if ($is_mongo) {
             $obj = $model->where('_id', $id)->update($data);
         } else {
             $obj = $model->where('id', $id)->update($data);
         }
         if ($obj) {
             $obj = $this->afterUpdate($id, $data);
             if ($obj != false) {
                 Event::fire('log.a', array($controller_name, 'update', $actor, json_encode($obj)));
                 return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saved successfully');
             }
         } else {
             Event::fire('log.a', array($controller_name, 'update', $actor, 'saving failed'));
             return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saving failed');
         }
     }
 }
开发者ID:awidarto,项目名称:jexadmin,代码行数:53,代码来源:__AdminController.php

示例12: post_image_list_delete

 public function post_image_list_delete()
 {
     if (Input::has('rel') and Input::has('lid') and Input::has('fid')) {
         $where = Input::get('rel');
         $list_id = Input::get('lid');
         $file_id = Input::get('fid');
         $singular = Str::singular($where);
         DB::table('files_' . $where)->where_cmsfile_id($file_id)->where('cms' . $singular . '_id', '=', $list_id)->delete();
         return true;
     }
     return false;
 }
开发者ID:SerdarSanri,项目名称:PongoCMS-Laravel-cms-bundle,代码行数:12,代码来源:ajax_file.php

示例13: resource

 /**
  * Generate resource (model, controller, and views)
  *
  * @param $args array  
  * @return void
  */
 public function resource($args)
 {
     // Pluralize controller name
     if (!preg_match('/admin|config/', $args[0])) {
         $args[0] = Str::plural($args[0]);
     }
     $this->controller($args);
     // Singular for everything else
     $resource_name = Str::singular(array_shift($args));
     if ($this->is_restful($args)) {
         // Remove that restful item from the array. No longer needed.
         $args = array_diff($args, array('restful'));
         $args = $this->determine_views($args);
     }
     // Let's take any supplied view names, and set them
     // in the resource name's directory.
     $views = array_map(function ($val) use($resource_name) {
         return "{$resource_name}.{$val}";
     }, $args);
     $this->view($views);
     $this->model($resource_name);
 }
开发者ID:rajakhoury,项目名称:laravel-skeleton,代码行数:28,代码来源:generate.php

示例14: resource

 /**
  * Generate resource (model, controller, and views)
  *
  * @param $args array  
  * @return void
  */
 public function resource($args)
 {
     if ($this->should_include_tests($args)) {
         $args = array_diff($args, array('with_tests'));
     }
     // Pluralize controller name
     if (!preg_match('/admin|config/', $args[0])) {
         $args[0] = Str::plural($args[0]);
     }
     // If only the resource name was provided, let's build out the full resource map.
     if (count($args) === 1) {
         $args = array($args[0], 'index', 'index:post', 'show', 'edit', 'new', 'update:put', 'destroy:delete', 'restful');
     }
     $this->controller($args);
     // Singular for everything else
     $resource_name = Str::singular(array_shift($args));
     // Should we include tests?
     if (isset($this->should_include_tests)) {
         $this->test(array_merge(array(Str::plural($resource_name)), $args));
     }
     if ($this->is_restful($args)) {
         // Remove that restful item from the array. No longer needed.
         $args = array_diff($args, array('restful'));
     }
     $args = $this->determine_views($args);
     // Let's take any supplied view names, and set them
     // in the resource name's directory.
     $views = array_map(function ($val) use($resource_name) {
         return "{$resource_name}.{$val}";
     }, $args);
     $this->view($views);
     $this->model($resource_name);
 }
开发者ID:marmaray,项目名称:OLD-laravel-France-website,代码行数:39,代码来源:generate.php

示例15: postEdit

 public function postEdit($id, $data = null)
 {
     $controller_name = strtolower($this->controller_name);
     //print_r(Session::get('permission'));
     $this->backlink = $this->backlink == '' ? $controller_name : $this->backlink;
     $validation = Validator::make($input = Input::all(), $this->validator);
     if ($validation->fails()) {
         return Redirect::to($controller_name . '/edit/' . $id)->withInput(Input::all())->withErrors($validation);
         //->with_input(Input::all());
     } else {
         if (is_null($data)) {
             $data = Input::get();
         }
         $id = new MongoId($data['id']);
         $data['lastUpdate'] = new MongoDate();
         unset($data['csrf_token']);
         unset($data['id']);
         //print_r($data);
         //exit();
         $model = $this->model;
         $data = $this->beforeUpdate($id, $data);
         if ($obj = $model->where('_id', $id)->update($data)) {
             $obj = $this->afterUpdate($id, $data);
             if ($obj != false) {
                 return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saved successfully');
             }
         } else {
             return Redirect::to($this->backlink)->with('notify_success', ucfirst(Str::singular($controller_name)) . ' saving failed');
         }
     }
 }
开发者ID:awidarto,项目名称:tmadminflat,代码行数:31,代码来源:AdminController.php


注:本文中的Str::singular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。