Command handler.

@param string          $name    The command name
@param AnCommandContext $context The command context

@return bool Can return both true or false.
773886
final public function execute($command, AnCommandContext $context)
    {
        $identifier = $context->caller->getIdentifier();

        if ($context->entity instanceof AnDomainEntityAbstract) {
            $identifier = $context->entity->getIdentifier();
        }

        $type = $identifier->path;
        $type = array_pop($type);

        $parts = explode('.', $command);
        $method = '_'.($parts[0]).ucfirst($type).ucfirst($parts[1]);

        $result = null;

        if (method_exists($this, $method)) {
            $result = $this->$method($context);
        }

        if ($context->entity) {
            $result = $context->entity->execute($command, $context);
        }

        return $result;
    }
594961
public function getCommand($name)
    {
        if (!isset($this->commands[$name])) {
            throw new \InvalidArgumentException("Command '$name' does not exist");
        }
        return $this->commands[$name];
    }
476765
protected function _actionBlock(AnCommandContext $context)
    {
        $this->getResponse()->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->addBlocker($this->actor);

        return $this->getItem();
    }
709521
public function isActive($name, Context $context)
    {
        $this->setup();

        $builder = $this->getConnection()->createQueryBuilder();

        // $result contains the response from state (true / false) or false if no feature found
        $result = $builder
            ->select(
                $this->options['db_column_state']
            )
            ->from($this->options['db_table'])
            ->where(sprintf('%s = :feature', $this->options['db_column_feature']))
            ->setParameter('feature', $name)
            ->execute()
            ->fetchColumn();

        return is_bool($result) ? $result : filter_var($result, FILTER_VALIDATE_BOOLEAN);
    }
527468
public function authorizeEcho(AnCommandContext $context)
    {
        $actor = $context->actor;

        if ($actor->isAdministrable() && $actor->authorize('administration')) {
            return true;
        } else {
            return $actor->id == $context->viewer->id;
        }
    }
1061866
public function execute($name, AnCommandContext $context)
    {
        $parts = explode('.', $name);

        if ($parts[0] == 'before') {
            $this->_fetchOwner($context);
        }

        parent::execute($name, $context);
    }
118405
protected function _actionForward(AnCommandContext $context)
    {
        $response = $this->getController()->getResponse();

        if (! $response->getContent()) {
            if (in_array($response->getStatusCode(), array(201, 205))) {
                $view = $this->getController()->getIdentifier()->name;
                $response->setContent($this->getController()->view($view)->execute('display', $context));

                if ($response->getStatusCode() == 205) {
                    $response->setStatus(200);
                }
            }
        }

        return $context->result;
    }
465662
public function isCommand($name) {
        if (!$this->docoptResult)
            return false;

        if (!($len=strlen($name)) || !isset($this->docoptResult[$name]))
            return false;
        return (bool) preg_match('/^[a-z]+$/', $name);
    }
1015783
public function hasCommandHandler($command)
    {
        $class = get_class($command);

        if (isset($this->handlers[$class])) {
            return true;
        }

        $callback = $this->mapper;

        if (!$callback || method_exists($command, 'handle')) {
            return false;
        }

        $this->handlers[$class] = $callback($command);

        return true;
    }
821377
public function executeInContext($context, $service, $operation, $argv = array(), $callback = null)
	{
	    $command = new Command(
            $service,
            $operation,
            $argv,
	        $context);

	    return $this->dispatch($command, $callback);
	}
1057703
public function execute($name, AnCommandContext $context)
    {
        $parts = explode('.', $name);

        if ($parts[0] == 'before') {
            $action = $parts[1];

            //Check if the action exists
            if (!in_array($action, $context->caller->getActions())) {
                throw new LibBaseControllerExceptionNotImplemented(
                        'Action '.ucfirst($action).' Not Implemented');
            }

            if ($this->_mixer->canExecute($action) === false) {
                if ($this->viewer && !$this->viewer->guest()) {
                    throw  new LibBaseControllerExceptionForbidden('Action '.ucfirst($action).' Not Allowed');
                } else {
                    throw  new LibBaseControllerExceptionUnauthorized('Action '.ucfirst($action).' Not Allowed');
                }
            }
        }

        return true;
    }
171555
public static function resolver(&$context, &$name) {
        if ($context['partialresolver']) {
            $cnt = $context['partialresolver']($context, $name);
            return static::prePartial($context, $cnt, $name);
        }
    }
300842
public function isCommandEnabled($name)
    {
        if (!empty(self::$config['application']['disabled_commands'])
            && in_array($name, self::$config['application']['disabled_commands'])) {
            return false;
        }
        if (!empty(self::$config['application']['experimental_commands'])
            && in_array($name, self::$config['application']['experimental_commands'])) {
            return !empty(self::$config['experimental']['all_experiments'])
                || (
                    !empty(self::$config['experimental']['enable_commands'])
                    && in_array($name, self::$config['experimental']['enable_commands'])
                );
        }

        return true;
    }
130467
protected function _authorizeAccess(AnCommandContext $context)
    {
        //if entity is not privatable then it doesn't have access to allow method
        if (!$this->_entity->isPrivatable()) {
            return true;
        }

        if ($this->_viewer->admin()) {
            return true;
        }

        if ($this->_entity->isFollowable() && $this->_entity->blocking($this->_viewer)) {
            return false;
        }

        if ($this->_entity->allows($this->_viewer, 'access')) {
            return true;
        }

        return false;
    }
11619
protected function _actionDelete(AnCommandContext $context)
    {
        $this->getService('repos:components')
             ->fetchSet()
             ->registerEventDispatcher($this->getService('anahita:event.dispatcher'));

        $result = parent::_actionDelete($context);

        $this->getService('anahita:event.dispatcher')
             ->dispatchEvent('onDeleteActor', array(
                'actor_id' => $this->getItem()->id,
                ));

        return $result;
    }
911674
protected function _actionDelete(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::NO_CONTENT;
        $entity = $this->getItem()->delete();

        return $entity;
    }
338430
protected function _authorizeAction(AnCommandContext $context)
    {
        //if entity is not privatable then it doesn't have access to allow method
        if (!$this->_entity->isPrivatable()) {
            return true;
        }

        //if viewer is admin then return true on the action
        if ($this->_viewer->admin()) {
            return true;
        }

        $action = $context->action;

        //any action on the actor requires being a follower by default
        $context->append(array(
            'default' => LibBaseDomainBehaviorPrivatable::FOLLOWER,
        ));

        //not access to the entiy
        if (! $this->_entity->authorize('access')) {
            return false;
        }

        $parts = explode(':', $action);

        $component = array_shift($parts);
        //check if it's a social app then if it's enabled

        if ($component) {

            $component = $this->getService('repos:components.component')->find(array('component' => $component));

            if (
                $component &&
                $component->authorize('action', array(
                                                    'actor' => $this->_entity,
                                                    'action' => $parts[1],
                                                    'resource' => $parts[0],
                                                    )) === false
            ) {
                return false;
            }
        }

        return $this->_entity->allows($this->_viewer, $action, $context->default);
    }