protected function getSkeleton($name) { $skeleton = new Skeleton($this->getSkeletonPath('controller')); $name = S::UpperCamelize($name) . 'Controller'; $skeleton->controller_name = $name; return $skeleton; }
/** * Parses the stored remote data * * @return void */ protected function parse() { // only perform actions when we have a file if (Storage::exists('postal/data.txt')) { // get the contents from storage $data = Storage::get('postal/data.txt'); // add a header $data = "Code1\tPlace1\tCode2\tPlace2\tType\n" . $data; // convert to utf-8 $data = iconv('ISO-8859-1', "UTF-8", $data); // set parser settings $this->parser->encoding('UTF-8'); $this->parser->delimiter = "\t"; // parse the data $this->parser->parse($data); // get the parsed csv $parsed = $this->parser->data; // empty arrays $codes = array(); // loop items foreach ($parsed as $parse) { $codes[] = array('code' => $parse['Code1'], 'place' => S::toTitleCase($parse['Place1'])); $codes[] = array('code' => $parse['Code2'], 'place' => S::toTitleCase($parse['Place2'])); } $this->data = $codes; } }
protected function execute(InputInterface $input, OutputInterface $output) { $arr = array(); $names = array(); $collections = false; if (is_dir(DIR_REPOSITORY)) { $it = new \FilesystemIterator(DIR_REPOSITORY, \FilesystemIterator::SKIP_DOTS); while ($it->valid()) { if (!$it->isDot() && !$it->isDir()) { $nm = $it->getBasename('.php'); $cl = '\\Repository\\' . $nm; if (class_exists($cl)) { $names[] = $nm; $arr[] = " /** @return {$cl} */\n" . " public function " . StaticStringy::camelize($nm) . "()\n" . " {\n" . " return \$this->getRepository('{$nm}');\n" . " }"; $collections .= " \$this->setRepositoryClass('{$nm}', '{$cl}');\n"; } } $it->next(); } } $code = "<?php\n\nnamespace Base;\n\n" . "/** Этот файл сгенерирован автоматически командой db:manager */\n" . "class Manager extends \\SQRT\\DB\\Manager\n{\n" . " function __construct()\n" . " {\n" . " \$this->addConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n" . " \$this->setPrefix(PREFIX);\n" . ($collections ? "\n" . $collections : '') . " }\n\n" . join("\n\n", $arr) . "\n" . "}"; $file = DIR_APP . '/Base/Manager.php'; file_put_contents($file, $code); if (!empty($names)) { $output->writeln(sprintf('<info>Менеджер БД обновлен, список коллекций: %s</info>', join(', ', $names))); } else { $output->writeln('<info>Первичная инициализация менеджера БД</info>'); } }
/** * Constructor. * * @param string $filename Filename of migration. */ public function __construct($filename) { $items = explode('_', $filename); $this->version = $items[0]; $this->name = ltrim($filename, $this->version . '_'); $this->name = basename($this->name, '.php'); $this->className = S::upperCamelize($this->name) . 'Migration'; }
/** * Logic that will be executed when command is visited * * @param AbstractCommand $command * @param int $depth * * @return mixed */ function process(AbstractCommand $command, $depth = 0) { if (is_null($this->argumentsContainer->getArgumentAt($this->currentIndex + 2))) { echo $command->getArgument() . ' '; } elseif (StaticStringy::startsWith($command->getArgument(), $this->argumentsContainer->getArgumentAt($this->currentIndex + 2))) { echo $command->getArgument() . ' '; } }
protected function getSkeleton($name) { $skeleton = new Skeleton($this->getSkeletonPath('entity')); $name = S::upperCamelize($name); $skeleton->entity_name = $name; $skeleton->table = Inflector::pluralize(S::replace(S::dasherize($name), '-', '_')); return $skeleton; }
public function actionIndex() { // --------------------------- TITLE ----------------------------------- $this->getView()->title .= ' :: ' . S::upperCamelize($this->action->id); // log ----------------------------------------------------------------- AppLogger::log(['method' => __METHOD__, 'line' => __LINE__, 'requestParams' => Yii::$app->request->getQueryParams()], AppLogger::WARNING, AppLogger::CATEGORY_TEST); // --------------------------------------------------------------------- return $this->render('/index/index'); }
/** * Build migration file name. * * @param datatype $timestamp Timestamp of migration. * * @return string */ public function build($timestamp = null) { if (null === $timestamp) { $timestamp = new \DateTime(); $timestamp = $timestamp->format('YmdHis'); } $fileName = sprintf('%s_%s.php', $timestamp, S::underscored($this->migrationName)); return $fileName; }
public function __construct($className, array $values = array(), array $map = array(), $tableName = null) { $this->className = S::upperCamelize($className); if (empty($tableName)) { $this->tableName = S::underscored($className); } $this->values = $values; $this->map = $map; }
public function actionUrl() { // --------------------------- TITLE ----------------------------------- $this->getView()->title .= ' :: ' . S::upperCamelize($this->action->id); // debug info ---------------------------------------------------------- AppDebug::dump(['method' => __METHOD__, 'line' => __LINE__, 'module' => $this->getModuleName(), 'controller' => $this->getControllerName(), 'action' => $this->getActionName(), '/profile/login' => Url::toRoute('/profile/login'), '/profile/logout' => Url::toRoute('/profile/logout'), '/profile/signup' => Url::toRoute('/profile/signup'), '/request-password-reset' => Url::toRoute('request-password-reset'), 'site/captcha' => Url::toRoute('site/captcha')]); // --------------------------------------------------------------------- // TODO return $this->render('index'); }
/** * {@inheritdoc} */ public function dispatch($controller, array $vars) { if (is_string($controller) && strpos($controller, '::')) { $controller = explode('::', $controller); } if (is_array($controller)) { $controller = [$this->container->get('Controller\\' . $controller[0]), StaticStringy::camelize($controller[1] . ' action')]; } $response = $this->container->call($controller, $vars); return $this->determineResponse($response); }
/** * Sets a migration name. * * @param string $migrationName A migration name. * * @return void */ public function setMigrationName($migrationName) { $this->migrationName = $migrationName; $migrationNameAsUnderscoreSrtring = S::underscored($migrationName); $items = explode('_', $migrationNameAsUnderscoreSrtring); if (count($items) >= 3) { $this->action = in_array($items[0], $this->validActions) ? $items[0] : null; $this->actionObject = in_array($items[1], $this->validActionObjects) ? $items[1] : null; $this->model = str_replace($items[0] . '_' . $items[1] . '_', '', $migrationNameAsUnderscoreSrtring); } }
/** * @param string $rawName * @param \stdClass $boundary */ public function importFilter($rawName, $boundary) { $name = S::camelize($rawName); $boundary = (array) $boundary; $isRanged = false; $title = S::humanize($rawName); if (isset($boundary['max']) || isset($boundary['min'])) { $isRanged = true; } $filterData = ['name' => $name, 'isRanged' => $isRanged, 'title' => $title, 'values' => $boundary]; $this->filters[] = $filterData; }
/** * Generate a hashid based on random data. * * @param null $salt * * @return string */ function generate_hashid($salt = null) { if (empty($salt)) { $salt = config('key'); } $hashids = new Hashids($salt); $min = rand(1, 1000) * rand(1, 1000); $max = rand(1, 1000) * rand(1, 1000); $quantity = rand(1, 64); $numbers = unique_random_numbers_within_range($min, $max, $quantity); return StaticStringy::truncate(StaticStringy::shuffle($hashids->encode($numbers)), 8); }
/** * @param $name * @param array $arguments * * @throws \ThinFrame\Foundation\Exceptions\InvalidArgumentException * @throws \BadMethodCallException */ public function __call($name, array $arguments) { if (StaticStringy::startsWith($name, 'on')) { $eventId = StaticStringy::camelize(substr($name, 2)); if (!isset($arguments[0]) || !is_callable($arguments[0])) { throw new InvalidArgumentException('Invalid or missing callback for event'); } $priority = isset($arguments[1]) ? intval($arguments[1]) : Priority::LOW; $this->attachTo($eventId, $arguments[0], $priority); } else { throw new \BadMethodCallException('Method ' . $name . ' is not defined under ' . get_called_class()); } }
/** * @inheritdoc */ public function dirtyAttributeValues() { $params = []; foreach ($this->dirtyAttributes() as $attribute) { $key = (string) StaticStringy::underscored($attribute); if ($this->{$attribute} instanceof Model) { $params[$key . "_id"] = $this->{$attribute}->id; } else { $params[$key] = $this->{$attribute}; } } return $params; }
/** * Require all php files from provided directory * * @param $path * @param bool $recursive */ public static function doRequire($path, $recursive = true) { if (is_dir($path) && $recursive) { $children = scandir($path); foreach ($children as $child) { if ($child == '.' || $child == '..') { continue; } self::doRequire($path . DIRECTORY_SEPARATOR . $child); } } elseif (is_file($path) && StaticStringy::endsWith($path, '.php')) { require_once $path; } }
/** * Disable the styleci webhook for the given repo. * * @param \StyleCI\StyleCI\Models\Repo $repo * * @return void */ public function disable(Repo $repo) { $url = route('home'); $args = explode('/', $repo->name); $client = $this->factory->make($repo); $hooks = $client->repo()->hooks(); $paginator = new ResultPager($client); foreach ($paginator->fetchAll($hooks, 'all', $args) as $hook) { if ($hook['name'] !== 'web' || StaticStringy::contains($hook['config']['url'], $url, false) !== true) { continue; } $hooks->remove($args[0], $args[1], $hook['id']); } }
private function detectTemplateType($template) { if (is_dir($template)) { if (is_dir($this->join($template, '.git'))) { return self::TEMPLATE_TYPE_LOCAL_GIT; } else { return self::TEMPLATE_TYPE_DIR; } } if (Stringy::startsWith($template, 'https') || Stringy::startsWith($template, 'git')) { return self::TEMPLATE_TYPE_REMOTE_GIT; } return self::TEMPLATE_TYPE_UNKNOWN; }
/** * Parse version string * * @throws \ThinFrame\Foundation\Exception\InvalidArgumentException */ private function parseVersion() { if (StaticStringy::startsWith($this->versionString, 'v')) { $this->versionString = StaticStringy::substr($this->versionString, 1); } if (strstr($this->versionString, '-')) { if (sscanf($this->versionString, '%d.%d.%d-%s', $this->major, $this->minor, $this->release, $this->suffix) != 4) { throw new InvalidArgumentException('Invalid version format ' . $this->versionString); } } else { if (sscanf($this->versionString, '%d.%d.%d', $this->major, $this->minor, $this->release) != 3) { throw new InvalidArgumentException('Invalid version format ' . $this->versionString); } } }
public function __call($name, $arguments) { if (substr($name, 0, 3) === 'get' && sizeof($arguments) === 0) { $name = Str::camelize(substr($name, 3)); if (isset($this->props[$name])) { return $this->props[$name]; } return; } if (substr($name, 0, 3) === 'set' && sizeof($arguments) === 1) { $name = Str::camelize(substr($name, 3)); $this->props[$name] = $arguments[0]; return true; } }
/** * Caches all twig files * * @param $dir * @param string $baseDir * @param $applicationName */ public function cacheTwigFilesFrom($dir, $baseDir = '', $applicationName) { foreach (scandir($dir) as $element) { if ($element == '.' || $element == '..') { continue; } if (is_dir($dir . DIRECTORY_SEPARATOR . $element)) { $this->cacheTwigFilesFrom($dir . DIRECTORY_SEPARATOR . $element, $baseDir . $element . DIRECTORY_SEPARATOR, $applicationName); } else { if (StaticStringy::endsWith($element, '.html.twig')) { $this->twig->loadTemplate($applicationName . ":" . $baseDir . $element); } } } }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelper('dialog'); $name = $input->getArgument('name'); if (!$name) { $name = $dialog->ask($output, 'Name of module: '); } $name = strtolower($name); $namespace = $input->getArgument('namespace'); if (!$namespace) { $namespace = $dialog->ask($output, 'Namespace for this module: ', S::upperCamelize($name)); } $this->createDirectories($output, $this->createModuleDirectory($namespace)); $file = $this->createModuleDirectory($namespace) . 'config.php'; $config = new Config($name); $config->save($file); $output->writeln("Created <info>{$file}</info>"); //create module class }
public function getSlugAttribute($value) { if (!$value) { $value = S::slugify($this->name); $nodes = Node::where('slug', $value); if ($nodes->count() > 0) { $value = $this->id . '-' . $value; $this->slug = $value; $this->save(); return $value; } else { $this->slug = $value; $this->save(); return $value; } } else { return $value; } }
public function addMenu($name, $item) { $label = $item['label']; $link = null; if (isset($item['link'])) { $link = $this->prefix . $item['link']; } $childs = null; if (isset($item['childs'])) { $childs = new self($item['childs']); unset($item['childs']); } $this->items[$name] = new Item($label, $link); $this->items[$name]->setChilds($childs); foreach ($item as $key => $val) { $func = Str::camelize('set_' . $key); $this->items[$name]->{$func}($val); } }
public static function bootHasSlug() { static::saving(function ($model) { $model->{static::$slugColumn} = StaticStringy::slugify($model->{static::$slugField}); }); }
} else { return $data['timestamp']; } }, 'headerOptions' => ['class' => 'sort-numerical text-align-center'], 'footerOptions' => ['class' => 'sort-numerical text-align-center font-weight-bold th'], 'contentOptions' => ['class' => 'nowrap font-size-10px text-align-center']], ['attribute' => 'level', 'value' => function ($data) { switch ($data['level']) { case Logger::LEVEL_ERROR: $class = 'label label-danger'; break; case Logger::LEVEL_WARNING: $class = 'label label-warning'; break; case Logger::LEVEL_INFO: $class = 'label label-primary'; break; default: $class = 'label label-default'; break; } return Html::tag('span', Logger::getLevelName($data['level']), ['class' => $class]); }, 'format' => 'html', 'filter' => [Logger::LEVEL_TRACE => ' Trace ', Logger::LEVEL_INFO => ' Info ', Logger::LEVEL_WARNING => ' Warning ', Logger::LEVEL_ERROR => ' Error '], 'filterInputOptions' => ['class' => 'form-control chosen-select', 'id' => null, 'prompt' => ' All '], 'headerOptions' => ['class' => 'text-align-center'], 'footerOptions' => ['class' => 'text-align-center font-weight-bold th'], 'contentOptions' => ['class' => 'text-align-center']], ['attribute' => 'category', 'headerOptions' => ['class' => 'text-align-center'], 'footerOptions' => ['class' => 'text-align-center font-weight-bold th'], 'contentOptions' => ['class' => 'font-size-10px']], ['attribute' => 'message', 'value' => function ($data) { $description = Html::encode(is_string($data['message']) ? $data['message'] : VarDumper::export($data['message'])); $message = '<a href="javascript:;" class="spoiler-title" data-title="" data-content="' . $description . '">' . Stringy::substr(Stringy::collapseWhitespace($description), 0, 60, 'UTF-8') . '...' . '</a>'; $trace = ''; if (!empty($data['trace'])) { $trace .= Html::ul($data['trace'], ['class' => 'trace', 'item' => function ($trace) { return "<li>{$trace['file']} ({$trace['line']})</li>"; }]); } $message .= '<div class="spoiler-content"><strong>Message: </strong><br /><pre>' . $description . '</pre>' . (!empty($trace) ? '<br /><p><strong>Trace: </strong>' . $trace . '</p>' : '') . '</div>'; return $message; }, 'format' => 'html', 'options' => ['width' => '50%'], 'contentOptions' => ['class' => 'spoiler']]]]);
/** * Transliterate a UTF-8 value to ASCII. * * @param string $value * @return string */ public static function ascii($value) { return StaticStringy::toAscii($value); }
?> </div> <?php if (isset($bootstrapTime)) { ?> <div>Application Bootstrap Time: <?php echo $bootstrapTime; ?> </div> <?php } ?> <?php if (!empty($timers)) { foreach ($timers as $name => $value) { ?> <div><?php echo \Stringy\StaticStringy::humanize($name); ?> : <?php echo $value; ?> </div> <?php } } ?> </small>
private function parseMethodColumnDescriptors(\ReflectionClass $reflClass, &$columnDescriptors, AutoTablesConfiguration $config) { foreach ($reflClass->getMethods() as $method) { $column = null; $annot = $this->reader->getMethodAnnotation($method, '\\twentysteps\\Bundle\\AutoTablesBundle\\Annotations\\Column'); if ($annot) { $column = new MethodColumnDescriptor($method); Ensure::isTrue(count($method->getParameters()) == 0, 'Failed to use [%s] as getter method, only parameterless methods supported for @Column', $method->getName()); Ensure::isTrue(StaticStringy::startsWith($method->getName(), 'get'), 'Illegal method name [%s], getter methods must start with a get prefix', $method->getName()); $column->addAutoTablesAnnotation($annot); $column->addAutoTablesConfig($config, $method->getName()); } if ($column && $column->isUsable()) { $methodName = 'set' . substr($method->getName(), 3); if ($reflClass->hasMethod($methodName)) { $setterMethod = $reflClass->getMethod($methodName); Ensure::isEqual(1, count($setterMethod->getParameters()), 'setter method [%s] needs to have exactly one parameter', $setterMethod->getName()); $column->setSetterMethod($setterMethod); } $column->validate(); $this->columnDescriptorMap[$column->getId()] = $column; $columnDescriptors[] = $column; } } }