Source of file SeparatorToUcwords.php

Size: 1,241 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/Filter/SeparatorToUcwords.php

12345678910111213141516171819202122232425262728293031323334353637383940
Covered by 14 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
41
Covered by 14 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testSetHeaders with data set "no http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "one http headers"
  • MvcLite\RequestTest::testSetHeaders with data set "with content type"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
4243444546474849505152
Covered by 7 test(s):
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
53
Covered by 7 test(s):
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
54
Covered by 7 test(s):
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
55
Covered by 7 test(s):
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
56
Covered by 7 test(s):
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #0
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #1
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #2
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #3
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #4
  • MvcLite\FilterSeparatorToUcwordsTest::testFilter with data set #5
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
575859
<?php
/**
 * pluralize filter
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Filter
 * @since       File available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite\Filter;

use MvcLite\FilterAbstract as FilterAbstract;

/**
 * pluralize filter
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Filter
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class SeparatorToUcwords extends FilterAbstract
{
    /**
     * Placeholder for the separator.
     * @var string
     */
    protected $separator;

    /**
     * Constructor.
     *
     * @param string $separator The separator to use for separating words.
     */
    public function __construct($separator)
    {
        $this->separator = $separator;
    }

    /**
     * filters a given string
     *
     * @param string $word
     *
     * @return string
     */
    public function filter($word = '')
    {
        $parts = explode($this->separator, $word);
        $string = implode(' ', $parts);
        $string = ucwords($string);
        $parts = explode(' ', $string);
        return implode($this->separator, $parts);
    }
}