本文整理汇总了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";
}
示例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();
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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');
}
});
}
示例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');
}
}
}
示例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));
}
示例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');
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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');
}
}
}