<commit_before><?php

namespace Nitrapi\Services;

use Nitrapi\Nitrapi;
use Nitrapi\Services\CloudServers\Apps\AppManager;
use Nitrapi\Services\CloudServers\CloudServer;
use Nitrapi\Common\NitrapiObject;
use Nitrapi\Services\TaskManager\TaskManager;

abstract class Service extends NitrapiObject
{
    protected $api;

    protected $id;
    protected $location_id;
    protected $comment;
    protected $status;
    protected $user_id;
    protected $username;
    protected $delete_date;
    protected $suspend_date;
    protected $start_date;
    protected $auto_extension;
    protected $auto_extension_duration;
    protected $details;
    protected $websocket_token;
    protected $roles;

    protected static $ensureActiveService = true;

    const SERVICE_STATUS_INSTALLING = 'installing';
    const SERVICE_STATUS_ACTIVE = 'active';
    const SERVICE_STATUS_SUSPENDED = 'suspended';
    const SERVICE_STATUS_DELETED = 'deleted';
    const SERVICE_STATUS_ADMINLOCKED = 'adminlocked';
    const SERVICE_STATUS_ADMINLOCKED_SUSPENDED = 'adminlocked_suspended';

    public function __construct(Nitrapi &$api, array &$data) {
        parent::__construct($api);
        $this->loadData($data);
    }

    /**
     * Returns the current location id
     *
     * @return int
     */
    public function getLocationId() {
        return $this->location_id;
    }

    /**
     * Returns the service status
     * 
     * @return mixed
     */
    public function getStatus() {
        return $this->status;
    }

    /**
     * Some actions do not need the check for active state, like deleting
     * the service. For this case, the active state check can be disabled.
     * If enabled, a Exception will be thrown if the service is not active
     * any more.
     *
     * Example:
     * Service::forceAction(function() use ($nitrapi, $serviceId) {
     *     $nitrapi->getService($serviceId)->doDelete();
     * });
     *
     * @see Gameserver::refresh()
     * @param $fn
     * @return null|mixed The return value from the given lambda fn
     */
    public static function forceAction($fn) {
        $res = null;

        self::$ensureActiveService = false;
        $res = $fn();
        self::$ensureActiveService = true;

        return $res;
    }

    /**
     * Returns if the service is currently installing.
     * @return bool<commit_msg>add service readonly feature to nitrapi (#57)<commit_after><?php

namespace Nitrapi\Services;

use Nitrapi\Nitrapi;
use Nitrapi\Services\CloudServers\Apps\AppManager;
use Nitrapi\Services\CloudServers\CloudServer;
use Nitrapi\Common\NitrapiObject;
use Nitrapi\Services\TaskManager\TaskManager;

abstract class Service extends NitrapiObject
{
    protected $api;

    protected $id;
    protected $location_id;
    protected $comment;
    protected $status;
    protected $user_id;
    protected $username;
    protected $delete_date;
    protected $suspend_date;
    protected $start_date;
    protected $auto_extension;
    protected $auto_extension_duration;
    protected $details;
    protected $readonly;
    protected $websocket_token;
    protected $roles;

    protected static $ensureActiveService = true;

    const SERVICE_STATUS_INSTALLING = 'installing';
    const SERVICE_STATUS_ACTIVE = 'active';
    const SERVICE_STATUS_SUSPENDED = 'suspended';
    const SERVICE_STATUS_DELETED = 'deleted';
    const SERVICE_STATUS_ADMINLOCKED = 'adminlocked';
    const SERVICE_STATUS_ADMINLOCKED_SUSPENDED = 'adminlocked_suspended';

    public function __construct(Nitrapi &$api, array &$data) {
        parent::__construct($api);
        $this->loadData($data);
    }

    /**
     * Returns the current location id
     *
     * @return int
     */
    public function getLocationId() {
        return $this->location_id;
    }

    /**
     * Returns the service status
     *
     * @return mixed
     */
    public function getStatus() {
        return $this->status;
    }

    /**
     * Returns if the webinterface is locked
     *
     * @return mixed
     */
    public function isReadonly() {
        return $this->readonly;
    }

    /**
     * Some actions do not need the check for active state, like deleting
     * the service. For this case, the active state check can be disabled.
     * If enabled, a Exception will be thrown if the service is not active
     * any more.
     *
     * Example:
     * Service::forceAction(function() use ($nitrapi, $serviceId) {
     *     $nitrapi->getService($serviceId)->doDelete();
     * });
     *
     * @see Gameserver::refresh()
     * @param $fn
     * @return null|mixed The return value from the given lambda fn
     */
    public static function forceAction($fn) {
        $res = null;

        self::$ensureActiveService = false;
        $res = $fn();
        self::$ensureActiveService = true;

        return $res;
    }

    /**
     * Returns if the service is currently installing.
     * @return bool
{'fraction_non_alphanumeric': 0.0980352440753494, 'fraction_numerical': 0.00040510431436094796, 'mean_word_length': 2.821981424148607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2468686', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1442, 'n_words': 386}