Skip to content

Instantly share code, notes, and snippets.

@crossmaya
Last active December 29, 2019 10:40
Show Gist options
  • Save crossmaya/2860ebe152359a5b07df2272b57b917c to your computer and use it in GitHub Desktop.
Save crossmaya/2860ebe152359a5b07df2272b57b917c to your computer and use it in GitHub Desktop.

Revisions

  1. crossmaya revised this gist Dec 29, 2019. No changes.
  2. crossmaya revised this gist Dec 29, 2019. 2 changed files with 21 additions and 0 deletions.
    File renamed without changes.
    21 changes: 21 additions & 0 deletions gits02.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php
    cdate >= 2016-11-8 00:00 AND cdate <= 2016-11-8 23:59
    //php获取今日开始时间戳和结束时间戳
    $today_start=mktime(0,0,0,date('m'),date('d'),date('Y'));
    $today_end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

    //php获取昨日起始时间戳和结束时间戳
    $yesterday_start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
    $yesterday_end=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

    //php获取上周起始时间戳和结束时间戳
    $lastweek_start=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
    $lastweek_end=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

    //php获取本周周起始时间戳和结束时间戳
    $thisweek_start=mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y'));
    $thisweek_end=mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y'));

    //php获取本月起始时间戳和结束时间戳
    $thismonth_start=mktime(0,0,0,date('m'),1,date('Y'));
    $thismonth_end=mktime(23,59,59,date('m'),date('t'),date('Y'));
  3. crossmaya revised this gist Dec 27, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions skill.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    //动态修改env文件
    $path = base_path('.env');
    if (file_exists($path)) {
  4. crossmaya revised this gist Dec 27, 2019. 1 changed file with 33 additions and 1 deletion.
    34 changes: 33 additions & 1 deletion skill.php
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,36 @@
    }
    file_put_contents($path, $current);
    }
    $this->info('Successfully generated new key for XChaCha');
    $this->info('Successfully generated new key for XChaCha');

    public function updateEnv($data = array())
    {
    if (!count($data)) {
    return;
    }

    $pattern = '/([^\=]*)\=[^\n]*/';

    $envFile = base_path() . '/.env';
    $lines = file($envFile);
    $newLines = [];
    foreach ($lines as $line) {
    preg_match($pattern, $line, $matches);

    if (!count($matches)) {
    $newLines[] = $line;
    continue;
    }

    if (!key_exists(trim($matches[1]), $data)) {
    $newLines[] = $line;
    continue;
    }

    $line = trim($matches[1]) . "={$data[trim($matches[1])]}\n";
    $newLines[] = $line;
    }

    $newContent = implode('', $newLines);
    file_put_contents($envFile, $newContent);
    }
  5. crossmaya created this gist Dec 27, 2019.
    22 changes: 22 additions & 0 deletions skill.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    //动态修改env文件
    $path = base_path('.env');
    if (file_exists($path)) {
    //Try to read the current content of .env
    $current = file_get_contents($path);

    //Store the key
    $original = [];
    if (preg_match('/^XCHACHA_KEY=(.+)$/m', $current, $original)) {
    //Write the original key to console
    $this->info("Original XChaCha key: $original[0]");

    //Overwrite with new key
    $current = preg_replace('/^XCHACHA_KEY=.+$/m', "XCHACHA_KEY=$b64", $current);

    } else {
    //Append the key to the end of file
    $current .= PHP_EOL."XCHACHA_KEY=$b64";
    }
    file_put_contents($path, $current);
    }
    $this->info('Successfully generated new key for XChaCha');