php Stringy-Stringy类(方法)实例源码

下面列出了php Stringy-Stringy 类(方法)源码代码实例,从而了解它的用法。

作者:conveni    项目:ticket-orde   
/**
  * Generate the full registry string.
  *
  * @return string
  */
 protected function generate()
 {
     $this->resultString = Stringy::create('');
     /*
      * @var Field
      */
     foreach ($this->values as $valueName => $valueClass) {
         $this->resultString = $this->resultString->append($valueClass->getValue());
     }
     return (string) $this->resultString;
 }

作者:nyp    项目:schemabuilde   
/**
  * @param string $type
  */
 protected function checkType($type = '')
 {
     if (!$type) {
         throw new \BadMethodCallException(self::EXCEPTION_SCHEMA_TYPE_REQUIRED);
     }
     if (Stringy::create(substr($type, 0, 1))->isLowerCase()) {
         throw new \InvalidArgumentException(self::EXCEPTION_SCHEMA_TYPE_INVALID . ': ' . $type);
     }
 }

作者:Festi    项目:Festi   
protected function getCommandName()
 {
     $commandName = '';
     $namespace = $this->getNamespace();
     if (isset($namespace)) {
         $namespace = preg_replace('/(?<=\\w)(?=[A-Z])/', " \$1", $this->getNamespace());
         foreach (explode('\\', $namespace) as $item) {
             $commandName .= Stringy::create($item)->slugify()->__toString() . ':';
         }
     }
     $className = preg_replace('/(?<=\\w)(?=[A-Z])/', " \$1", $this->getClassName());
     $commandName .= Stringy::create($className)->slugify()->__toString();
     return $commandName;
 }

作者:explore-larave    项目:avata   
public function getInitial()
 {
     $words = new Collection(explode(' ', $this->name));
     // if name contains single word, use first N character
     if ($words->count() === 1) {
         if ($this->name->length() >= $this->length) {
             return $this->name->substr(0, $this->length);
         }
         return (string) $words->first();
     }
     // otherwise, use initial char from each word
     $initials = new Collection();
     $words->each(function ($word) use($initials) {
         $initials->push(Stringy::create($word)->substr(0, 1));
     });
     return $initials->slice(0, $this->length)->implode('');
 }

作者:kletellie    项目:mv   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the login : ', '');
         $login = $helper->ask($input, $output, $question);
         if ($login == "") {
             throw new \Exception("you must specify login");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         // get user instance
         $user = $ss->userFromLogin($login);
         if ($user == null) {
             throw new \Exception("User {$login} doesn't exist");
         }
         $iduser = $user->id;
         // get all roles
         $roles = $ss->getRoles();
         $strRole = "[";
         foreach ($roles as $role) {
             if ($strRole != "[") {
                 $strRole .= ",";
             }
             $strRole .= $role->role;
         }
         $strRole .= "]";
         $question = new Question('Add roles for ' . $login . ' ' . $strRole . ', type role separated by comma : ', '');
         $roles = $helper->ask($input, $output, $question);
         $output->writeln('Add roles to user');
         if ($roles != "" && $iduser != null) {
             $rolea = \Stringy\Stringy::create($roles)->split(",");
             foreach ($rolea as $role) {
                 $roles = $ss->getRolesFromName(array($role));
                 $role1 = $roles->first();
                 $ss->addUserToRole($iduser, $role1->id);
             }
         }
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }

作者:entershi    项目:first_fligh   
private function isAlbum()
 {
     if (!empty($this->parsedUrl['path'])) {
         // TODO: как правильно вызывать Stringy чтобы не создавать 100 экземпляров внутри кода?
         $stringy = new Stringy();
         $result = $stringy->endsWith(Urls::ALBUM);
         if ($result === true) {
             return true;
         }
     }
     return false;
 }

作者:kletellie    项目:mv   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the login : ', '');
         $login = $helper->ask($input, $output, $question);
         if ($login == "") {
             throw new \Exception("you must specify login");
         }
         $question = new Question('Please enter the mail : ', '');
         $email = $helper->ask($input, $output, $question);
         if ($email == "") {
             throw new \Exception("you must specify a mail");
         }
         $question = new Question('Please enter the password : ', '');
         $password = $helper->ask($input, $output, $question);
         if ($password == "") {
             throw new \Exception("you must specify a password");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         if ($ss->emailExist($email)) {
             throw new \Exception("Email already exists.");
         }
         if ($ss->loginExist($login)) {
             throw new \Exception("Login already exists.");
         }
         // get all roles
         $roles = $ss->getRoles();
         $strRole = "[";
         foreach ($roles as $role) {
             if ($strRole != "[") {
                 $strRole .= ",";
             }
             $strRole .= $role->role;
         }
         $strRole .= "]";
         $question = new Question('Add roles for this user ' . $strRole . ', type role separated by comma : ', '');
         $roles = $helper->ask($input, $output, $question);
         $output->writeln('Create user');
         $ret = $ss->userCreate($login, $email, $password);
         if ($roles != "" && $ret != null) {
             $rolea = \Stringy\Stringy::create($roles)->split(",");
             foreach ($rolea as $role) {
                 $roles = $ss->getRolesFromName(array($role));
                 $role1 = $roles->first();
                 $ss->addUserToRole($ret, $role1->id);
             }
         }
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }

作者:sourcestrea    项目:highcore-ap   
public function distributeResources($resources, $componentPrefixedKey = 'LogicalResourceId')
 {
     Log::debug(__METHOD__ . ' start');
     $groupedResourceCollection = [];
     foreach ($this->items as $componentKey => $component) {
         foreach ($resources as $resourceKey => $resource) {
             if (Stringy::create($resource[$componentPrefixedKey])->startsWith(studly_case($componentKey), false)) {
                 $groupedResourceCollection[$componentKey][] = $resource;
                 unset($resources[$resourceKey]);
             }
             if ($resource[$componentPrefixedKey] == data_get($resource, 'StackName') or $resource[$componentPrefixedKey] == '') {
                 $groupedResourceCollection['_stack'][] = $resource;
                 unset($resources[$resourceKey]);
             }
         }
     }
     if (count($resources) > 0) {
         $groupedResourceCollection['_ungrouped'] = $resources;
     }
     $groupedResourceCollectionKeys = array_keys($groupedResourceCollection);
     $retval = Collection::make($groupedResourceCollection)->map(function ($resources) {
         return Collection::make($resources);
     })->replaceKeys(function ($k) use($groupedResourceCollectionKeys) {
         return $groupedResourceCollectionKeys[$k];
     });
     Log::debug(__METHOD__ . ' end');
     return $retval;
 }

作者:conveni    项目:ticket-orde   
/**
  * @param array $data
  *
  * @throws ValidatorException
  * @throws ValidatorInvalidRuleException
  */
 public function validate(array $data)
 {
     if (count($this->rules) === 0) {
         return;
     }
     foreach ($this->rules as $ruleIndex => $rules) {
         foreach ($rules as $rule) {
             if (strpos($rule, ':') !== false) {
                 list($composeRuleIndex, $composeRuleParams) = explode(':', $rule);
                 $methodName = Stringy::create($composeRuleIndex);
                 $methodName = (string) $methodName->toTitleCase();
                 $this->methodExists($methodName);
                 $valid = $this->{'validate' . $methodName}($data, $ruleIndex, $composeRuleParams);
                 $this->shouldStop($valid, $composeRuleIndex, $ruleIndex, $data);
                 continue;
             }
             $methodName = Stringy::create($rule);
             $methodName = (string) $methodName->toTitleCase();
             $this->methodExists($methodName);
             $valid = $this->{'validate' . $methodName}($data, $ruleIndex);
             $this->shouldStop($valid, $rule, $ruleIndex, $data);
         }
     }
 }

作者:elaza    项目:clim   
/**
  * Get the required packages.
  *
  * @return array
  */
 private function getPackages()
 {
     $file = getcwd() . '/composer.json';
     if (!file_exists($file)) {
         return [];
     }
     $json = json_decode(file_get_contents($file), true);
     $packages = [];
     if (isset($json['require'])) {
         $packages = array_merge($packages, $json['require']);
     }
     if (isset($json['require-dev'])) {
         $packages = array_merge($packages, $json['require-dev']);
     }
     if (count($packages) <= 0) {
         return [];
     }
     $array = [];
     foreach ($packages as $name => $version) {
         $string = new Stringy($name);
         if ($string->startsWith('php') || $string->startsWith('ext')) {
             continue;
         }
         $array[$name] = $version;
     }
     return $array;
 }

作者:kletellie    项目:mv   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the role key : ', '');
         $role = $helper->ask($input, $output, $question);
         if ($role == "") {
             throw new \Exception("you must specify role key");
         }
         $roles = \Stringy\Stringy::create($role)->slugify();
         $question = new Question('Please enter the role description : ', '');
         $description = $helper->ask($input, $output, $question);
         if ($description == "") {
             throw new \Exception("you must specify a description");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         $output->writeln('Create role');
         $ss->roleCreate($roles, $description);
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }

作者:glynnforres    项目:neptun   
protected function getResourceName(InputInterface $input, OutputInterface $output)
 {
     $description = $input->getArgument('description');
     if (!$description) {
         $dialog = $this->getHelper('dialog');
         $description = $dialog->ask($output, 'Description for this migration: ');
     }
     $this->migration_description = str_replace("'", "\\'", $description);
     return 'Migration' . date('YmdHis') . Stringy::create($description)->slugify()->upperCamelize();
 }

作者:getgra    项目:grav-plugin-filter-string   
public function stringFilter($action, $data, array $options = array())
 {
     if ($action == null) {
         return;
     }
     $customManipulators = ["cosgrove"];
     //plans for custom manipulator functions
     switch (true) {
         case in_array($action, $customManipulators):
             //Plans for custom manipulator functions
             break;
         default:
             return call_user_func_array(array(Stringy::create($data), $action), $options);
     }
 }

作者:panvagena    项目:wp-plugin-cor   
/**
  * @param Plugin $plugin
  */
 public function __construct(Plugin $plugin)
 {
     parent::__construct($plugin);
     $this->pluginBaseDir = dirname($plugin->getFilePath());
     $this->pluginBaseDirRel = preg_replace('/^' . preg_quote(ABSPATH, '/') . '/', '', $this->pluginBaseDir);
     $uploadsData = wp_upload_dir();
     $this->uploadsBaseDir = isset($uploadsData['basedir']) ? $uploadsData['basedir'] . '/' . $plugin->getSlug() : $this->pluginBaseDir . '/uploads';
     $logFileName = Stringy::create($plugin->getName());
     $this->logFilePath = $this->uploadsBaseDir . '/log/' . (string) $logFileName->camelize() . '.log';
     $templatePluginSlugDir = get_template_directory() . '/' . $plugin->getSlug();
     /* @var FcrHooks $hookFactory */
     $hookFactory = $this->plugin->getHookFactory();
     $this->whereTemplatesMayReside = array($templatePluginSlugDir, $this->pluginBaseDir . '/templates');
     $this->whereTemplatesMayResideFilter = $hookFactory->getWhereTemplatesMayResideFilter();
     $this->whereScriptsMayReside = array($templatePluginSlugDir . '/js', $this->pluginBaseDir . '/assets/js');
     $this->whereScriptsMayResideFilter = $hookFactory->getWhereScriptsMayResideFilter();
     $this->whereStylesMayReside = array($templatePluginSlugDir . '/css', $this->pluginBaseDir . '/assets/css');
     $this->whereStylesMayResideFilter = $hookFactory->getWhereStylesMayResideFilter(array());
 }

作者:kletellie    项目:mv   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     try {
         Capsule::connection("default")->setFetchMode(PDO::FETCH_NUM);
         $arr = Capsule::connection("default")->select('SHOW TABLES;');
         foreach ($arr as $ts) {
             $name = $ts[0];
             $output->writeln($name);
             // search for primary
             $sql1 = "SHOW INDEX from " . $name . " WHERE Key_name='PRIMARY';";
             $pk1 = Capsule::connection("default")->select($sql1);
             if (count($pk1) > 0) {
                 $pk = $pk1[0][4];
             } else {
                 // by first unique index
                 $sql2 = "SHOW INDEX from " . $name . " WHERE Non_unique=0;";
                 $pk2 = Capsule::connection("default")->select($sql2);
                 if (count($pk2) > 0) {
                     $pk = $pk2[0][4];
                 }
             }
             $modelname = Stringy::create($name)->upperCamelize()->__toString();
             $nmodel = $this->model;
             $nmodel = str_replace('##modelname##', $modelname, $nmodel);
             $nmodel = str_replace('##tablename##', $name, $nmodel);
             $nmodel = str_replace('##foreignkey##', $pk, $nmodel);
             $path = ROOT . DS . "app" . DS . "Application" . DS . "Models" . DS;
             $filename = $path . $modelname . ".php";
             file_put_contents($filename, $nmodel);
         }
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }

作者:conveni    项目:ticket-orde   
/**
  * Generate the alelo orders file.
  *
  * @return string
  */
 public function generate()
 {
     if ($this->productType === null) {
         throw new ProductTypeIsRequiredException();
     }
     $this->header = new HeaderRegistry(['requesterUser' => $this->orderUser, 'orderDate' => (new Carbon())->format('Ymd'), 'orderTime' => (new Carbon())->format('H.i.s')]);
     $this->generateTraillerRegistry();
     $this->fileLayout = $this->fileLayout->append($this->header->__toString());
     $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     $this->fileLayout = $this->fileLayout->append($this->headerEletronic->__toString());
     $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     $this->fileLayout = $this->fileLayout->append($this->branch->__toString());
     $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     foreach ($this->getAllEmployees() as $employeeRegistry) {
         $this->fileLayout = $this->fileLayout->append($employeeRegistry->__toString());
         $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     }
     $this->fileLayout = $this->fileLayout->append($this->traillerRegistry->__toString());
     return $this->fileLayout->__toString();
 }

作者:conveni    项目:alelo-orde   
/**
  * Generate the alelo orders file.
  *
  * @return string
  */
 public function generate()
 {
     $this->generateTraillerRegistry();
     $this->fileLayout = $this->fileLayout->append($this->header->__toString());
     $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     $this->fileLayout = $this->fileLayout->append($this->branch->__toString());
     $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     foreach ($this->getAllEmployees() as $employeeRegistry) {
         $this->fileLayout = $this->fileLayout->append($employeeRegistry->__toString());
         $this->fileLayout = $this->fileLayout->append(PHP_EOL);
     }
     $this->fileLayout = $this->fileLayout->append($this->traillerRegistry->__toString());
     return (string) $this->fileLayout;
 }

作者:enzym    项目:nam   
/**
  * Returns the shortened version of this name.
  *
  * @return string
  */
 public function short()
 {
     $shortened_parts = [];
     foreach ($this->segments as $part) {
         $string = S::create($part);
         if ($string->contains('.')) {
             $shortened_parts[] = $string;
         } else {
             $shortened_parts[] = $string->truncate(2, '.');
         }
     }
     return implode(' ', $shortened_parts);
 }

作者:blyp    项目:blyp   
public function render($str = false)
 {
     if (!$str) {
         $str = isset($this->arguments['str']) ? $this->arguments['str'] : '';
     }
     $str = isset($this->arguments['str']) ? $this->arguments['str'] : '';
     return S::create($str)->tidy();
 }

作者:enzym    项目:nam   
/**
  * Format the given name segment/part.
  *
  * @param string $part The part.
  *
  * @return S
  */
 protected function format($part)
 {
     $part = S::create($part);
     switch ($part->substr(0, 2)) {
         case 'Pr':
             return $part->replace('Prefix', $this->tryGetLongVersion($this->name->getPrefix()));
         case 'Fi':
             return $part->replace('First', $this->tryGetLongVersion($this->name->getFirst()));
         case 'Mi':
             return $part->replace('Middle', $this->tryGetLongVersion($this->name->getMiddle()));
         case 'La':
             return $part->replace('Last', $this->tryGetLongVersion($this->name->getLast()));
         case 'P.':
             return $part->replace('P.', $this->tryGetShortVersion($this->name->getPrefix()));
         case 'F.':
             return $part->replace('F.', $this->tryGetShortVersion($this->name->getFirst()));
         case 'M.':
             return $part->replace('M.', $this->tryGetShortVersion($this->name->getMiddle()));
         case 'L.':
             return $part->replace('L.', $this->tryGetShortVersion($this->name->getLast()));
         default:
             return $part;
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号