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


PHP Slugify::create方法代码示例

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


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

示例1: boot

 public static function boot()
 {
     static::creating(function (Tag $tag) {
         $slugify = Slugify::create();
         $tag->slug = $slugify->slugify($tag->name);
     });
 }
开发者ID:wasgeht-berlin,项目名称:website,代码行数:7,代码来源:Tag.php

示例2: extendTwig

 /**
  * Adds the WP-specific filters and functions to the twig environment
  * @param \Twig_Environment $twig_Environment
  */
 private static function extendTwig(\Twig_Environment $twig_Environment)
 {
     $twig_Environment->addFilter(new \Twig_SimpleFilter('__', function ($text, $domain = 'default') {
         return __($text, $domain);
     }));
     $twig_Environment->addExtension(new SlugifyExtension(Slugify::create()));
 }
开发者ID:jmversteeg,项目名称:jvwp,代码行数:11,代码来源:Templates.php

示例3: slug

 /**
  * Generate slug.
  *
  * @param string $string Input string.
  * @param string $replacement Replacement string.
  * @return string Sluggified string.
  */
 public function slug($string, $replacement = '-')
 {
     $options = $this->config;
     $regex = $options['regex'];
     unset($options['regex']);
     return Slugify::create($regex, $options)->slugify($string, $replacement);
 }
开发者ID:kwadwo,项目名称:Slug,代码行数:14,代码来源:CocurSlugger.php

示例4: createMenuNodeForPage

 /**
  * @param $label
  * @param $page
  * @param ObjectManager $manager
  * @return MenuNode
  */
 private function createMenuNodeForPage($label, $page, ObjectManager $manager)
 {
     $slugify = Slugify::create();
     $menuNode = new MenuNode();
     $menuNode->setName($slugify->slugify($label));
     $menuNode->setLabel($label);
     $menuNode->setContent($page);
     $menuNode->setParentDocument($manager->find(null, '/cms/menu/main'));
     return $menuNode;
 }
开发者ID:kea,项目名称:PUGXCmfPageBundle,代码行数:16,代码来源:TwoPagesWithMenuNodesFixture.php

示例5: appendInsertQueries

 /**
  * Append record inserts to the query.
  *
  * @param QuerySet $queries
  * @param mixed    $entity
  * @param array    $toInsert
  */
 protected function appendInsertQueries(QuerySet $queries, $entity, array $toInsert)
 {
     foreach ($toInsert as $item) {
         $item = (string) $item;
         $ins = $this->em->createQueryBuilder()->insert($this->mapping['target'])->values(['content_id' => ':content_id', 'contenttype' => ':contenttype', 'taxonomytype' => ':taxonomytype', 'slug' => ':slug', 'name' => ':name'])->setParameters(['content_id' => $entity->id, 'contenttype' => $entity->getContenttype(), 'taxonomytype' => $this->mapping['fieldname'], 'slug' => Slugify::create()->slugify($item), 'name' => isset($this->mapping['data']['options'][$item]) ? $this->mapping['data']['options'][$item] : $item]);
         $queries->onResult(function ($query, $result, $id) use($ins) {
             if ($query === $ins && $result === 1 && $id) {
                 $query->setParameter('content_id', $id);
             }
         });
         $queries->append($ins);
     }
 }
开发者ID:nuffer,项目名称:bolt,代码行数:20,代码来源:TaxonomyTypeTrait.php

示例6: makeApp

 protected function makeApp()
 {
     $config = new Standard(TEST_ROOT);
     $this->setAppPaths($config);
     $bolt = new Application(['resources' => $config]);
     $bolt['session.test'] = true;
     $bolt['debug'] = false;
     $bolt['config']->set('general/database', ['driver' => 'pdo_sqlite', 'prefix' => 'bolt_', 'user' => 'test', 'path' => PHPUNIT_WEBROOT . '/app/database/bolt.db', 'wrapperClass' => '\\Bolt\\Storage\\Database\\Connection']);
     $bolt['config']->set('general/canonical', 'bolt.dev');
     $bolt['slugify'] = Slugify::create();
     $this->setAppPaths($bolt['resources']);
     return $bolt;
 }
开发者ID:nbehier,项目名称:bolt,代码行数:13,代码来源:BoltUnitTest.php

示例7: makeApp

 protected function makeApp()
 {
     $config = new Standard(TEST_ROOT);
     $config->verify();
     $bolt = new Application(['resources' => $config]);
     $bolt['session.test'] = true;
     $bolt['debug'] = false;
     $bolt['config']->set('general/database', ['driver' => 'pdo_sqlite', 'prefix' => 'bolt_', 'user' => 'test', 'path' => TEST_ROOT . '/bolt.db']);
     $bolt['config']->set('general/canonical', 'bolt.dev');
     $bolt['resources']->setPath('files', PHPUNIT_ROOT . '/resources/files');
     $bolt['slugify'] = Slugify::create();
     return $bolt;
 }
开发者ID:peteryu1,项目名称:bolt,代码行数:13,代码来源:BoltUnitTest.php

示例8: __construct

 /**
  * @param string $title
  * @param string $description
  * @param array  $config
  */
 public function __construct($title, $description = '', $config = array())
 {
     $this->unitList = new UnitList();
     $this->title = $title;
     $this->description = $description;
     $this->config = array_replace_recursive($this->defaultConfig, $config);
     $this->config['output_dir'] = Path::join($this->config['output_dir']);
     $this->config['template_dir'] = Path::join($this->config['template_dir']);
     $loader = new \Twig_Loader_Filesystem($this->config['template_dir']);
     $this->twig = new \Twig_Environment($loader, $this->config['twig']);
     $this->twig->addExtension(new SlugifyExtension(Slugify::create()));
     $this->twig->addExtension(new ReportExtension());
     $this->twig->addExtension(new \Jralph\Twig\Markdown\Extension(new GithubMarkdownExtension()));
     $this->twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
 }
开发者ID:nochso,项目名称:benchmark,代码行数:20,代码来源:Report.php

示例9: updateStartup

 public static function updateStartup(Startup $startup, array $attributes)
 {
     $slugify = Slugify::create();
     $startup->name = $attributes['name'];
     $startup->description = $attributes['description'];
     $startup->url = $slugify->slugify($attributes['name']);
     $startup->stage_id = $attributes['stage_id'];
     $startup->video = $attributes['video'];
     $startup->twitter = $attributes['twitter'];
     $startup->linked_in = $attributes['linked_in'];
     $startup->facebook = $attributes['facebook'];
     $startup->website = $attributes['website'];
     $startup->published = array_key_exists('published', $attributes) ? true : false;
     return $startup;
 }
开发者ID:katzumi,项目名称:talent4startups,代码行数:15,代码来源:Startup.php

示例10: handle

 /**
  * Execute the command.
  *
  * @param StartupRepository $repository
  * @return static
  */
 public function handle(StartupRepository $repository)
 {
     $slugify = Slugify::create();
     $startup = Startup::create(['user_id' => $this->user->id, 'name' => $this->startup->name, 'description' => $this->startup->description, 'url' => $slugify->slugify($this->startup->name), 'stage_id' => $this->startup->stage_id, 'video' => $this->startup->video, 'published' => true]);
     $repository->save($startup);
     if (isset($this->startup->tags)) {
         $repository->updateTags($startup, $this->startup->tags);
     }
     if (isset($this->startup->needs)) {
         $repository->updateNeeds($startup, $this->startup->needs);
     }
     if (isset($this->startup->image)) {
         $repository->updateImage($startup, $this->startup->image);
     }
     return $startup;
 }
开发者ID:katzumi,项目名称:talent4startups,代码行数:22,代码来源:CreateStartup.php

示例11: makeApp

 protected function makeApp()
 {
     $sessionMock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Session')->setMethods(array('clear'))->setConstructorArgs(array(new MockFileSessionStorage()))->getMock();
     $config = new Standard(TEST_ROOT);
     $this->setAppPaths($config);
     $config->verify();
     $bolt = new Application(array('resources' => $config));
     $bolt['deprecated.php'] = version_compare(PHP_VERSION, '5.4.0', '<');
     $bolt['config']->set('general/database', array('driver' => 'pdo_sqlite', 'prefix' => 'bolt_', 'user' => 'test', 'path' => PHPUNIT_WEBROOT . '/app/database/bolt.db'));
     $bolt['config']->set('general/canonical', 'bolt.dev');
     $bolt['session'] = $sessionMock;
     $bolt['resources']->setPath('files', PHPUNIT_ROOT . '/resources/files');
     $bolt['slugify'] = Slugify::create();
     $this->setAppPaths($bolt['resources']);
     return $bolt;
 }
开发者ID:aaleksu,项目名称:bolt_cm,代码行数:16,代码来源:BoltUnitTest.php

示例12: makeSafe

 /**
  * Returns a "safe" version of the given string - basically only US-ASCII and
  * numbers. Needed because filenames and titles and such, can't use all characters.
  *
  * @param string  $str
  * @param boolean $strict
  * @param string  $extrachars
  *
  * @return string
  */
 public static function makeSafe($str, $strict = false, $extrachars = "")
 {
     $slugify = Slugify::create('/([^a-zA-Z0-9] |-)+/u');
     $str = $slugify->slugify($str);
     $str = str_replace("&amp;", "", $str);
     $delim = '/';
     if ($extrachars != "") {
         $extrachars = preg_quote($extrachars, $delim);
     }
     if ($strict) {
         $str = strtolower(str_replace(" ", "-", $str));
         $regex = "[^a-zA-Z0-9_" . $extrachars . "-]";
     } else {
         $regex = "[^a-zA-Z0-9 _.," . $extrachars . "-]";
     }
     $str = preg_replace($delim . $regex . $delim, '', $str);
     return $str;
 }
开发者ID:aleksabp,项目名称:bolt,代码行数:28,代码来源:Str.php

示例13: makeSafe

 /**
  * Returns a "safe" version of the given string - basically only US-ASCII and
  * numbers. Needed because filenames and titles and such, can't use all characters.
  *
  * @param string  $str
  * @param boolean $strict
  * @param string  $extrachars
  *
  * @return string
  */
 public static function makeSafe($str, $strict = false, $extrachars = '')
 {
     $str = str_replace('&amp;', '', $str);
     $delim = '/';
     if ($extrachars != '') {
         $extrachars = preg_quote($extrachars, $delim);
     }
     if ($strict) {
         $slugify = Slugify::create(['regexp' => '/[^a-z0-9_' . $extrachars . ' -]+/']);
         $str = $slugify->slugify($str, '');
         $str = str_replace(' ', '-', $str);
     } else {
         // Allow Uppercase and don't convert spaces to dashes
         $slugify = Slugify::create(['regexp' => '/[^a-zA-Z0-9_.,' . $extrachars . ' -]+/', 'lowercase' => false]);
         $str = $slugify->slugify($str, '');
     }
     return $str;
 }
开发者ID:bolt,项目名称:bolt,代码行数:28,代码来源:Str.php

示例14: getYaml

 public function getYaml()
 {
     $output = '';
     $lastsection = '';
     $slugify = Slugify::create('/[^a-z0-9_ -]+/');
     $escaper = new \Symfony\Component\Yaml\Escaper();
     foreach ($this->controls as $id => $control) {
         if ($control->section != $lastsection) {
             if (isset($this->sections[$control->section]) && !empty($this->sections[$control->section]['title'])) {
                 $section = $this->sections[$control->section]['title'];
             } else {
                 $section = $control->section;
             }
             $output .= sprintf("\n# ---- SECTION %s ---- \n", strtoupper($section));
             if (isset($this->sections[$control->section]) && !empty($this->sections[$control->section]['description'])) {
                 $output .= sprintf("# ---- %s ---- \n", $this->sections[$control->section]['description']);
             }
             $lastsection = $control->section;
         }
         $output .= "\n";
         if (!empty($control->label)) {
             $output .= sprintf("# %s \n", $control->label);
         }
         if (!empty($control->description)) {
             $output .= sprintf("# %s \n", strip_tags($control->description));
         }
         if (!empty($control->choices) && is_array($control->choices)) {
             $output .= "# Valid choices are: \n";
             foreach ($control->choices as $key => $value) {
                 $output .= sprintf("#  - %s (%s)\n", $key, $value);
             }
         }
         $default = "";
         if (isset($this->settings[$id])) {
             $default = $this->settings[$id]['default'];
             if ($escaper->requiresSingleQuoting($default)) {
                 $default = $escaper->escapeWithSingleQuotes($default);
             }
         }
         $id = $slugify->slugify($control->id);
         $output .= sprintf("%s: %s\n", $id, $default);
     }
     return $output;
 }
开发者ID:bobdenotter,项目名称:wordpress-theme,代码行数:44,代码来源:WordpressCustomize.php

示例15: testBoot

 /**
  * @dataProvider getSlug
  */
 public function testBoot($text, $expected)
 {
     $bundle = new SonataProductBundle();
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->exactly(2))->method('getParameter')->will($this->returnCallback(function ($value) {
         if ($value == 'sonata.product.product.class') {
             return 'Sonata\\Test\\ProductBundle\\Product';
         }
         if ($value == 'sonata.product.slugify_service') {
             return 'slug_service';
         }
     }));
     $container->expects($this->once())->method('get')->will($this->returnValue(Slugify::create()));
     $bundle->setContainer($container);
     $bundle->boot();
     $product = new Product();
     $product->setSlug($text);
     $this->assertEquals($product->getSlug(), $expected);
 }
开发者ID:Dicoding,项目名称:ecommerce,代码行数:22,代码来源:SonataProductBundleTest.php


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