Skip to content

Commit

Permalink
process on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Feb 24, 2024
1 parent 1df8e7c commit 70b96da
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 43 deletions.
28 changes: 0 additions & 28 deletions src/Modules/Cli/Tasks/BuildTask.php

This file was deleted.

57 changes: 51 additions & 6 deletions src/Modules/Cli/Tasks/CacheTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,63 @@

namespace Zemit\Modules\Cli\Tasks;

use Phalcon\Cache\Exception\InvalidArgumentException;
use Zemit\Modules\Cli\Task;

class CacheTask extends Task
{
public string $cliDoc = <<<DOC
Usage:
zemit cli cache <action> [<params> ...]
Options:
task: cache
action: clear
zemit cli cache clear
zemit cli cache has <key>
zemit cli cache delete <key>
zemit cli cache delete-multiple [<key>...]
DOC;

/**
* Clears all items from the cache.
*
* @return bool True if all items were successfully cleared, false otherwise.
*/
public function clearAction(): bool
{
return $this->cache->clear();
}

/**
* Checks if the given action key exists in the cache.
*
* @param string $key The key identifying the action in the cache.
* @return bool Returns true if the action key exists in the cache, false otherwise.
* @throws InvalidArgumentException
*/
public function hasAction(string $key): bool
{
return $this->cache->has($key);
}

/**
* Deletes an item from the cache.
*
* @param string $key The key of the item to be deleted.
* @return bool True if the item was successfully deleted, false otherwise.
* @throws InvalidArgumentException
*/
public function deleteAction(string $key): bool
{
return $this->cache->delete($key);
}

/**
* Deletes multiple cache entries specified by the given keys.
*
* @param mixed ...$keys A variable number of keys representing the cache entries to be deleted.
*
* @return bool Returns true if all cache entries were successfully deleted, false otherwise.
*/
public function deleteMultipleAction(string ...$keys): bool
{
return $this->cache->deleteMultiple($keys);
}
}
35 changes: 26 additions & 9 deletions src/Modules/Cli/Tasks/HelpTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,56 @@

namespace Zemit\Modules\Cli\Tasks;

use Phalcon\Exception;
use Phalcon\Dispatcher\Exception;
use Zemit\Modules\Cli\Task;

class HelpTask extends Task
{
public string $cliDoc = <<<DOC
Usage:
zemit cli <task> [<action>] [<params> ...]
Options:
task: build,cron,cache
zemit cli help cache
zemit cli help cron
zemit cli help database
zemit cli help data-life-cycle
zemit cli help scaffold
zemit cli help test
zemit cli help user
DOC;

/**
* @throws Exception
* Build Action
*
* This method executes the build action by forwarding the request to the build task's help action.
*
* @return void
* @throws Exception if there is an error during the forwarding process
*/
public function buildAction(): void
{
$this->dispatcher->forward(['task' => 'build', 'action' => 'help']);
}

/**
* @throws Exception
* Cron Action
*
* This method executes the cron action by forwarding the request to the cron task's help action.
*
* @return void
* @throws Exception if there is an error during the forwarding process
*/
public function cronAction(): void
{
$this->dispatcher->forward(['task' => 'cron', 'action' => 'help']);
}

/**
* @throws Exception
* Cache Action
*
* This method executes the cache action by forwarding the request to the cache task's help action.
*
* @return void
* @throws Exception if there is an error during the forwarding process
*/
public function cacheAction(): void
{
Expand Down

0 comments on commit 70b96da

Please sign in to comment.