public function testCreate()
 {
     $stringy = s('foo bar', 'UTF-8');
     $this->assertInstanceOf('Stringy\\Stringy', $stringy);
     $this->assertEquals('foo bar', (string) $stringy);
     $this->assertEquals('UTF-8', $stringy->getEncoding());
 }
 /**
  * {@inheritDoc}
  */
 public function sortByTermResemblance(string $term) : array
 {
     $term = (string) s($term)->toLowerCase();
     $array = $this->asArray();
     usort($array, function (string $a, string $b) use($term) : int {
         $aScore = s($a)->toLowerCase()->longestCommonPrefix($term)->length();
         $bScore = s($b)->toLowerCase()->longestCommonPrefix($term)->length();
         if ($aScore === $bScore) {
             return 0;
         }
         return $aScore > $bScore ? -1 : 1;
     });
     return $array;
 }
Exemple #3
0
 public function uploadMedia(Request $request, Response $response, $arguments)
 {
     $errors = [];
     foreach ($_FILES as $key => $file) {
         $storage = new \Upload\Storage\FileSystem('uploads');
         $file = new \Upload\File($key, $storage);
         try {
             $file->setName(s($file->getName())->slugify());
             $file->upload();
         } catch (\Exception $e) {
             array_push($errors, 'Failed to upload ' . $file->getNameWithExtension());
         }
     }
     return $response->withJson(['errors' => $errors], 200, JSON_PRETTY_PRINT);
 }
 /**
  * Given an array of mappings we will return a list of php src files.
  *
  * @param  array $mappings
  * @return array
  */
 private function getFilesFromMap($package, $version, $mappings)
 {
     $paths = [];
     $basePath = $this->vendorDir . '/' . $package . '/' . $version;
     foreach ($mappings as $ns => $mapping) {
         // Handle an exact file
         if (s($mapping)->endsWith('.php')) {
             $paths[] = $mapping;
             continue;
         }
         $files = $this->filesystem->listContents($basePath . '/' . $mapping, true);
         $query = Linq::from($files)->where(function ($v) {
             return $v['type'] == 'file';
         })->where(function ($v) {
             return isset($v['extension']);
         })->where(function ($v) {
             return $v['extension'] == 'php';
         })->select(function ($v) use($basePath) {
             return str_replace($basePath . '/', '', $v['path']);
         })->where(function ($v) {
             foreach ($this->excludes as $regex) {
                 if (preg_match($regex, $v)) {
                     return false;
                 }
             }
             return true;
         })->toArray();
         if (is_int($ns)) {
             // Handle a classmap
             $paths = array_merge($paths, $query);
         } else {
             // Handle a PSR-0/4 map
             // We save the namespace for later use.
             if (!isset($paths[$ns])) {
                 $paths[$ns] = [];
             }
             $paths[$ns] = array_merge($paths[$ns], $query);
         }
     }
     return $paths;
 }
Exemple #5
0
 public function makeCamelCase($str)
 {
     return s($str)->camelize($str);
 }
Exemple #6
0
 /**
  * Works out the PSR portion of the namespace.
  *
  * For example, this projects composer.json file
  * autoload sections looks like:
  *
  * ```json
  * "autoload":
  * 	{
  * 		"psr-4":
  * 		{
  * 			"Brads\\": "src"
  * 		}
  * 	}
  * ```
  *
  * Given the full namespace of: ```Brads\Ppm\Services```
  * this method would return just ```Brads\```
  *
  * @param  array  $composer The composer object to search in.
  * @param  string $ns       The full namespace.
  * @return string           The psr segment of the ns.
  * @throws PsrNsNotFound
  */
 private function getPsrNs(array $composer, $ns)
 {
     foreach (['psr-4', 'psr-0'] as $psrType) {
         if (isset($composer['autoload'][$psrType])) {
             foreach ($composer['autoload'][$psrType] as $psrNs => $path) {
                 if (s($ns)->startsWith($psrNs) || $ns . '\\' == $psrNs) {
                     return $psrNs;
                 }
             }
         }
     }
     throw new PsrNsNotFound($composer, $ns);
 }
 private function normalizePath($path)
 {
     return (string) s($path)->replace('\\', '/')->ensureRight('/');
 }
Exemple #8
0
 /**
  * Get real controller class name
  *
  * @param $module
  * @param $controller
  * @return string
  */
 protected function getFullControllerName($module, $controller)
 {
     return sprintf('\\App\\Module\\%s\\Controller\\%sController', s($module)->toTitleCase(), s($controller)->toTitleCase());
 }