예제 #1
0
 /**
  * @param int  $length
  * @param bool $bin2hex
  * @return string
  */
 public function generate($length, $bin2hex = false)
 {
     $hash = Strings::random($length);
     if (!empty($bin2hex)) {
         return bin2hex($hash);
     }
     return $hash;
 }
예제 #2
0
파일: KeyCommand.php 프로젝트: vvval/spiral
 /**
  * @param DirectoriesInterface $directories
  * @param FilesInterface       $files
  * @param EncrypterConfig      $config
  */
 public function perform(DirectoriesInterface $directories, FilesInterface $files, EncrypterConfig $config)
 {
     $envFilename = $directories->directory('root') . '.env';
     if (!$files->exists($envFilename)) {
         $this->writeln("<fg=red>'env.' file does not exists, unable to sek encryption key.</fg=red>");
     }
     $files->write($envFilename, str_replace($config->getKey(), Strings::random(32), $files->read($envFilename)));
     $this->writeln("<info>Encryption key has been successfully updated.</info>");
 }
예제 #3
0
 /**
  * Remove blank lines.
  *
  * @param string   $source
  * @param Isolator $isolator
  * @return string
  */
 protected function normalizeEndings($source, Isolator $isolator)
 {
     //Step #1, \n only
     $source = $isolator->isolatePHP(Strings::normalizeEndings($source));
     //Step #2, chunk by lines
     $sourceLines = explode("\n", $source);
     //Step #3, no blank lines and html comments (will keep conditional commends)
     $sourceLines = array_filter($sourceLines, function ($line) {
         return trim($line);
     });
     $source = $isolator->repairPHP(join("\n", $sourceLines));
     $isolator->reset();
     return $source;
 }
예제 #4
0
 /**
  * Unique wrapper.
  *
  * @return string
  */
 private static function createWrapper()
 {
     $wrapper = '(~' . Strings::random(64) . '~)';
     if (in_array($wrapper, self::$wrappers)) {
         return self::createWrapper();
     }
     return self::$wrappers[] = $wrapper;
 }
예제 #5
0
 /**
  * @param bool $format
  * @return int|string
  */
 public function filesize($format = false)
 {
     $filesize = filesize($this->filename);
     if ($format) {
         return Strings::bytes($filesize);
     }
     return $filesize;
 }
예제 #6
0
        <grid:cell label="[[Last occurred:]]">
            <?php 
echo $entity->whenLast();
?>
            <span class="grey-text">(<?php 
echo $entity->whenLast(true);
?>
)</span>
        </grid:cell>
        <grid:cell label="[[Message:]]">
            <span title="<?php 
echo e($entity->exception_teaser);
?>
">
                <?php 
echo e(\Spiral\Support\Strings::shorter($entity->exception_teaser, 100));
?>
            </span>
        </grid:cell>
        <grid:cell label="[[All:]]" value="<?php 
echo $entity->count_occurred;
?>
"/>
        <grid:cell label="[[Stored:]]" value="<?php 
echo $entity->count_stored;
?>
"/>
        <grid:cell label="[[Suppression:]]">
            <b>
                <?php 
echo $entity->isSuppressionEnabled() ? '[[YES]]' : '[[NO]]';
예제 #7
0
파일: Source.php 프로젝트: vvval/spiral
 /**
  * Converts input string into set of lines.
  *
  * @param string $string
  * @param bool   $cutIndents
  * @return array
  */
 public function fetchLines($string, $cutIndents)
 {
     if ($cutIndents) {
         $string = Strings::normalizeEndings($string, false);
     }
     $lines = explode("\n", Strings::normalizeEndings($string, false));
     //Pre-processing
     return array_map([$this, 'prepareLine'], $lines);
 }
예제 #8
0
echo number_format(1000 * $elapsed);
?>
 [[ms]]">
                <?php 
echo number_format(1000 * $full);
?>
 [[ms]]
            </div>

            <div id="dbg-prf-option-memory" class="option memory">
                <span title="[[Real usage:]] <?php 
echo \Spiral\Support\Strings::bytes(memory_get_peak_usage(true));
?>
">
                    <?php 
echo \Spiral\Support\Strings::bytes(memory_get_peak_usage());
?>
                </span>
            </div>

            <!-- Plugins. -->
            <div id="dbg-profiler-plugin-environment" class="option environment" plugin="environment">
                <a title="[[Environment]]"></a>
            </div>

            <div id="dbg-profiler-plugin-variables" class="option variables" plugin="variables">
                <a title="[[Application Variables]]"></a>
            </div>

            <div id="dbg-profiler-plugin-benchmarks" class="option benchmarks" plugin="benchmarks">
                <a title="[[Application Profiling]]"></a>
예제 #9
0
 /**
  * Fetch uri segments and query parameters.
  *
  * @param \Traversable|array $parameters
  * @param array              $query Query parameters.
  * @return array
  */
 protected function fetchSegments($parameters, &$query)
 {
     $allowed = array_keys($this->compiled['options']);
     $result = [];
     foreach ($parameters as $key => $parameter) {
         if (is_numeric($key) && isset($allowed[$key])) {
             $key = $allowed[$key];
         } elseif (!array_key_exists($key, $this->compiled['options']) && is_array($parameters)) {
             $query[$key] = $parameters;
             continue;
         }
         if (is_string($parameter) && !preg_match('/^[a-z\\-_0-9]+$/i', $parameter)) {
             $result[$key] = Strings::slug($parameters);
             continue;
         }
         $result[$key] = (string) $parameter;
     }
     return $result;
 }
예제 #10
0
    }
    $filesize = filesize($filename);
    $totalCount++;
    $totalSize += $filesize;
    ?>
                <tr>
                    <td><?php 
    echo $files->normalizePath($filename);
    ?>
</td>
                    <td align="right" class="nowrap">
                        <?php 
    echo \Spiral\Support\Strings::bytes($filesize);
    ?>
                    </td>
                </tr>
                <?php 
}
?>
            <tr>
                <td align="right">TOTAL:</td>
                <td align="right" class="nowrap">
                    <?php 
echo \Spiral\Support\Strings::bytes($totalSize) . ", " . number_format($totalCount) . " file(s)";
?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>