public function run(array $args = []): string
    {
        $result = [
            'name' => $this->name,
            'status' => 'ok',
            'components' => [],
            'dependencies' => $this->dependencies
        ];

        foreach ($this->checks as $service => $check) {
            $checkArgs = isset($args[$service]) ? $args[$service] : [];

            if (is_string($check) && class_exists($check)) {
                $check = new $check($checkArgs);

                if (!($check instanceof BaseCheck)) {
                    throw new \Exception($service . ' check must be derived from Ackly\\Health\\Check\\BaseCheck');
                }

                $serviceStatus = $check->run();
            } else {
                $serviceStatus = call_user_func_array($check, $checkArgs);
            }

            if (!($serviceStatus instanceof CheckResult)) {
                throw new \Exception('Each health check must return instance of Ackly\\Health\\CheckResult');
            }

            if ($serviceStatus->status == 'warning' && $result['status'] == 'ok') {
                $result['status'] = 'warning';
            }

            if ($serviceStatus->status == 'error') {
                $result['status'] = 'error';
            }

            $result['components'][$service] = array_merge(['name' => $service], $serviceStatus->toArray());
        }

        if (empty($result['components'])) {
            unset($result['components']);
        }

        $this->result = $result;

        /** @var Formatter\IFormatter $formatter */
        $formatter = new $this->formatter();
        return $formatter->format($result);
    }
public function run(array $args = []): string
    {
        $result = [
            'name' => $this->name,
            'status' => 'ok',
            'components' => [],
            'dependencies' => $this->dependencies
        ];

        foreach ($this->checks as $service => $check) {
            $checkArgs = isset($args[$service]) ? $args[$service] : [];

            if (is_string($check) && class_exists($check)) {
                $check = new $check($checkArgs);

                if (!($check instanceof BaseCheck)) {
                    throw new \Exception($service . ' check must be derived from Ackly\\Health\\Check\\BaseCheck');
                }

                $serviceStatus = $check->run();
            } else {
                $serviceStatus = call_user_func_array($check, $checkArgs);
            }

            if (!($serviceStatus instanceof CheckResult)) {
                throw new \Exception('Each health check must return instance of Ackly\\Health\\CheckResult');
            }

            if ($serviceStatus->status == 'warning' && $result['status'] == 'ok') {
                $result['status'] = 'warning';
            }

            if ($serviceStatus->status == 'error') {
                $result['status'] = 'error';
            }

            $result['components'][$service] = array_merge(['name' => $service], $serviceStatus->toArray());
        }

        if (empty($result['components'])) {
            unset($result['components']);
        }

        $this->result = $result;

        /** @var Formatter\IFormatter $formatter */
        $formatter = new $this->formatter();
        return $formatter->format($result);
    }
public function run ( array $ args = [ ] ) : string { $ result = [ 'name' => $ this -> name , 'status' => 'ok' , 'components' => [ ] , 'dependencies' => $ this -> dependencies ] ; foreach ( $ this -> checks as $ service => $ check ) { $ checkArgs = isset ( $ args [ $ service ] ) ? $ args [ $ service ] : [ ] ; if ( is_string ( $ check ) && class_exists ( $ check ) ) { $ check = new $ check ( $ checkArgs ) ; if ( ! ( $ check instanceof BaseCheck ) ) { throw new \ Exception ( $ service . ' check must be derived from Ackly\\Health\\Check\\BaseCheck' ) ; } $ serviceStatus = $ check -> run ( ) ; } else { $ serviceStatus = call_user_func_array ( $ check , $ checkArgs ) ; } if ( ! ( $ serviceStatus instanceof CheckResult ) ) { throw new \ Exception ( 'Each health check must return instance of Ackly\\Health\\CheckResult' ) ; } if ( $ serviceStatus -> status == 'warning' && $ result [ 'status' ] == 'ok' ) { $ result [ 'status' ] = 'warning' ; } if ( $ serviceStatus -> status == 'error' ) { $ result [ 'status' ] = 'error' ; } $ result [ 'components' ] [ $ service ] = array_merge ( [ 'name' => $ service ] , $ serviceStatus -> toArray ( ) ) ; } if ( empty ( $ result [ 'components' ] ) ) { unset ( $ result [ 'components' ] ) ; } $ this -> result = $ result ; /** @var Formatter\IFormatter $formatter */ $ formatter = new $ this -> formatter ( ) ; return $ formatter -> format ( $ result ) ; }
Run health checks and get result as string.

@param array $args Mapping between service name and array of arguments
that will be supplied to check (via call_user_func_array).
If check is class then this arguments will be passed to constructor (without spread).

@throws \Exception
@return string
Run health checks and get result as string .