本文整理汇总了PHP中Pagekit\Application::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::filter方法的具体用法?PHP Application::filter怎么用?PHP Application::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagekit\Application
的用法示例。
在下文中一共展示了Application::filter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEnable
/**
* Adds protected node types.
*/
public function onEnable($event, $module)
{
foreach ((array) $module->get('nodes') as $type => $route) {
if (isset($route['protected']) and $route['protected'] and !Node::where(['type = ?'], [$type])->first()) {
Node::create(['title' => $route['label'], 'slug' => App::filter($route['label'], 'slugify'), 'type' => $type, 'status' => 1, 'link' => $route['name']])->save();
}
}
}
示例2: registerType
/**
* Register a node type.
*
* @param string $type
* @param array $route
*/
public function registerType($type, array $route)
{
if (isset($route['protected']) and $route['protected'] and !array_filter(Node::findAll(true), function ($node) use($type) {
return $type === $node->type;
})) {
Node::create(['title' => $route['label'], 'slug' => App::filter($route['label'], 'slugify'), 'type' => $type, 'status' => 1, 'link' => $route['name']])->save();
}
$route['id'] = $type;
$this->types[$type] = $route;
}
示例3: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"node": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!($node = Node::find($id))) {
$node = Node::create();
unset($data['id']);
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
$node->save($data);
return ['message' => 'success', 'node' => $node];
}
示例4: formatValue
/**
* @param FieldBase $field
* @param FieldValueBase $fieldValue
* @return array
*/
public function formatValue(FieldBase $field, FieldValueBase $fieldValue)
{
$valuedata = $fieldValue->getValuedata();
if (count($valuedata)) {
return array_map(function ($file) {
if (!isset($file['url'])) {
return '';
}
return sprintf('<a href="%s" download>%s</a> <small>(%s)</small>', App::url($file['url'], [], UrlGenerator::ABSOLUTE_URL), $file['name'], App::filter($file['size'], 'filesize'));
}, $valuedata);
}
return ['-'];
}
示例5: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"project": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!$id || !($project = Project::find($id))) {
if ($id) {
App::abort(404, __('Post not found.'));
}
$project = Project::create();
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
$project->save($data);
return ['message' => 'success', 'project' => $project];
}
示例6: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"category": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!($category = Category::where(compact('id'))->related('files')->first())) {
$category = Category::create();
unset($data['id']);
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
$category->updateOrdering($data);
//unset array typed files
unset($data['files']);
$category->save($data);
return ['message' => 'success', 'category' => $category];
}
示例7: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"field": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!($field = Field::find($id))) {
$field = Field::create(['data' => ['value' => [], 'data' => [], 'classSfx' => '', 'help_text' => '', 'help_show' => '']]);
unset($data['id']);
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['label'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
try {
$field->save($data);
} catch (Exception $e) {
App::abort(400, $e->getMessage());
}
return ['message' => 'success', 'field' => $field];
}
示例8: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"file": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
/** @var File $file */
if (!$id || !($file = File::where(compact('id'))->related('categories')->first())) {
if ($id) {
App::abort(404, __('File not found.'));
}
$file = File::create();
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
$file->save($data);
$file->saveCategories($data['category_ids']);
return ['message' => 'success', 'file' => $file];
}
示例9: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"formitem": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!($form = Form::find($id))) {
$form = Form::create();
unset($data['id']);
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
try {
$form->save($data);
} catch (Exception $e) {
App::abort(400, $e->getMessage());
}
return ['message' => 'success', 'formitem' => $form];
}
示例10: saveAction
/**
* @Route("/", methods="POST")
* @Request({"menu":"array"}, csrf=true)
*/
public function saveAction($menu)
{
$oldId = isset($menu['id']) ? trim($menu['id']) : null;
$label = trim($menu['label']);
if (!($id = App::filter($label, 'slugify'))) {
App::abort(400, __('Invalid id.'));
}
if ($id != $oldId) {
if ($this->config->has('menus.' . $id)) {
throw new ConflictException(__('Duplicate Menu Id.'));
}
$this->config->remove('menus.' . $oldId);
Node::where(['menu = :old'], [':old' => $oldId])->update(['menu' => $id]);
}
$this->config->merge(['menus' => [$id => compact('id', 'label')]]);
App::menu()->assign($id, $menu['positions']);
return ['message' => 'success', 'menu' => $menu];
}
示例11: saveAction
/**
* @Route("/", methods="POST")
* @Route("/{id}", methods="POST", requirements={"id"="\d+"})
* @Request({"post": "array", "id": "int"}, csrf=true)
*/
public function saveAction($data, $id = 0)
{
if (!$id || !($post = Post::find($id))) {
if ($id) {
App::abort(404, __('Post not found.'));
}
$post = Post::create();
}
if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
App::abort(400, __('Invalid slug.'));
}
// user without universal access is not allowed to assign posts to other users
if (!App::user()->hasAccess('blog: manage all posts')) {
$data['user_id'] = App::user()->id;
}
// user without universal access can only edit their own posts
if (!App::user()->hasAccess('blog: manage all posts') && !App::user()->hasAccess('blog: manage own posts') && $post->user_id !== App::user()->id) {
App::abort(400, __('Access denied.'));
}
$post->save($data);
return ['message' => 'success', 'post' => $post];
}
示例12: addCache
protected function addCache($user)
{
$this->cacheEntries[$user->id] = ['id' => $user->id, 'username' => App::filter($user->username, 'slugify'), 'name' => App::filter($user->name, 'slugify')];
$this->cacheDirty = true;
}