<commit_before><?php

namespace Prophets\DrupalJsonApi\Repositories;

use Prophets\DrupalJsonApi\Collection;
use Prophets\DrupalJsonApi\Contracts\BaseRelation;
use Prophets\DrupalJsonApi\Contracts\BaseRepository;
use Prophets\DrupalJsonApi\Relations\HasMany;
use Prophets\DrupalJsonApi\Relations\HasManyDirty;
use Prophets\DrupalJsonApi\Request\DrupalJsonApiRequestBuilder;
use Prophets\DrupalJsonApi\Model;
use GuzzleHttp\Psr7\Request;
use Http\Adapter\Guzzle6\Client;
use Illuminate\Support\Arr;
use WoohooLabs\Yang\JsonApi\Client\JsonApiClient;
use WoohooLabs\Yang\JsonApi\Response\JsonApiResponse;
use WoohooLabs\Yang\JsonApi\Schema\Document;
use WoohooLabs\Yang\JsonApi\Schema\ResourceObject;

class JsonApiBaseRepository implements BaseRepository
{
    use Concerns\HasGlobalScopes;

    /**
     * @var Model
     */
    protected $model;

    /**
     * @var string
     */
    private $apiBaseUrl;

    /**
     * JsonApiBaseRepository constructor.
     * @param Model $model
     * @param null|string $apiBaseUrl
     */
    public function __construct(Model $model, $apiBaseUrl = null)
    {
        $this->model = $model;
        $this->apiBaseUrl = $apiBaseUrl ?: config('drupal-jsonapi.base_url');
    }

    /**
     * @inheritdoc
     */
    public function getNewModel()
    {
        return new $this->model;
    }

    /**
     * @return DrupalJsonApiRequestBuilder
     */
    protected function newRequestBuilderWithoutScopes()
    {
        $requestBuilder = new DrupalJsonApiRequestBuilder((new Request('', '')));
        $requestBuilder
            ->setProtocolVersion('1.1')
            ->setMethod('GET');

        return $requestBuilder;
    }

    /**
     * Get a request initialized with all global scopes.<commit_msg>Add boot functionalities à la Eloquent model.<commit_after><?php

namespace Prophets\DrupalJsonApi\Repositories;

use Prophets\DrupalJsonApi\Collection;
use Prophets\DrupalJsonApi\Contracts\BaseRelation;
use Prophets\DrupalJsonApi\Contracts\BaseRepository;
use Prophets\DrupalJsonApi\Relations\HasMany;
use Prophets\DrupalJsonApi\Relations\HasManyDirty;
use Prophets\DrupalJsonApi\Request\DrupalJsonApiRequestBuilder;
use Prophets\DrupalJsonApi\Model;
use GuzzleHttp\Psr7\Request;
use Http\Adapter\Guzzle6\Client;
use Illuminate\Support\Arr;
use WoohooLabs\Yang\JsonApi\Client\JsonApiClient;
use WoohooLabs\Yang\JsonApi\Response\JsonApiResponse;
use WoohooLabs\Yang\JsonApi\Schema\Document;
use WoohooLabs\Yang\JsonApi\Schema\ResourceObject;

class JsonApiBaseRepository implements BaseRepository
{
    use Concerns\HasGlobalScopes;

    /**
     * The array of booted repositories.
     *
     * @var array
     */
    protected static $booted = [];

    /**
     * @var Model
     */
    protected $model;

    /**
     * @var string
     */
    private $apiBaseUrl;

    /**
     * JsonApiBaseRepository constructor.
     * @param Model $model
     * @param null|string $apiBaseUrl
     */
    public function __construct(Model $model, $apiBaseUrl = null)
    {
        $this->model = $model;
        $this->apiBaseUrl = $apiBaseUrl ?: config('drupal-jsonapi.base_url');

        $this->bootIfNotBooted();
    }

    /**
     * Check if the repository needs to be booted and if so, do it.
     *
     * @return void
     */
    protected function bootIfNotBooted()
    {
        if (! isset(static::$booted[static::class])) {
            static::$booted[static::class] = true;
            static::boot();
        }
    }

    /**
     * The "booting" method of the repository.
     *
     * @return void
     */
    protected static function boot()
    {
        static::bootTraits();
    }

    /**
     * Boot all of the bootable traits on the repository.
     *
     * @return void
     */
    protected static function bootTraits()
    {
        $class = static::class;

        foreach (class_uses_recursive($class) as $trait) {
            if (method_exists($class, $method = 'boot'.class_basename($trait))) {
                forward_static_call([$class, $method]);
            }
        }
    }

    /**
     * @inheritdoc
     */
    public function getNewModel()
    {
        return new $this->model;
    }

    /**
     * @return DrupalJsonApiRequestBuilder
     */
    protected function newRequestBuilderWithoutScopes()
    {
        $requestBuilder = new DrupalJsonApiRequestBuilder((new Request('', '')));
        $requestBuilder
            ->setProtocolVersion('1.1')
            ->setMethod('GET');

        return $requestBuilder;
    }

    /**
     * Get a request initialized with all global scopes.
{'fraction_non_alphanumeric': 0.11261753772140827, 'fraction_numerical': 0.0017493986442160508, 'mean_word_length': 2.767710049423394, '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': '1357842', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1395, 'n_words': 265}