<commit_before><?php

namespace Phrest\API\DI;

use League\OAuth2\Server\Authorization;
use League\OAuth2\Server\Grant\ClientCredentials;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\DI\FactoryDefault as PhalconDI;
use Phalcon\DI;
use Phalcon\DI\FactoryDefault;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Http\Request;
use Phalcon\Mvc\Dispatcher as MVCDispatcher;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Router;
use Phalcon\Registry;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Client;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Scope;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Session;
use Phrest\API\Request\PhrestRequest;
use Phrest\API\Responses\CSVResponse;
use Phrest\API\Responses\JSONResponse;
use Phrest\API\Responses\Response;

/**
 * PhrestDI
 */
class PhrestDI extends FactoryDefault
{
  /**
   * Construct all of the dependencies for the API
   */
  public function __construct()
  {
    // Set up default services
    parent::__construct();

    // Prepare the request object
    $this['request'] = function ()
    {
      return new PhrestRequest();
    };

    // Set up oAuth2 service
    $this['oauth2'] = function ()
    {
      $config = $this->get('config');
      $oauth2DB = new Mysql($config->oauth2DB->toArray());

      // Create oAuth2 server
      $server = new Authorization(
        new Client($oauth2DB),
        new Session($oauth2DB),
        new Scope($oauth2DB)
      );

      # Not required as it called directly from original code
      # $request = new \League\OAuth2\Server\Util\Request();

      # add these 2 lines code if you want to use my own Request otherwise comment it
      // todo required?
      //$request = new \Phrest\API\Oauth2\Server\Request();
      //$server->setRequest($request);

      $server->setAccessTokenTTL(86400);
      $server->addGrantType(new ClientCredentials());

      return $server;
    };

    // Default router
    $this['router'] = function ()
    {
      return new Router;
    };<commit_msg>PB-100 Removing old style di setup<commit_after><?php

namespace Phrest\API\DI;

use League\OAuth2\Server\Authorization;
use League\OAuth2\Server\Grant\ClientCredentials;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\DI\FactoryDefault as PhalconDI;
use Phalcon\DI;
use Phalcon\DI\FactoryDefault;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Http\Request;
use Phalcon\Mvc\Dispatcher as MVCDispatcher;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Router;
use Phalcon\Registry;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Client;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Scope;
use Phrest\API\Oauth2\Server\Storage\Pdo\Mysql\Session;
use Phrest\API\Request\PhrestRequest;
use Phrest\API\Responses\CSVResponse;
use Phrest\API\Responses\JSONResponse;
use Phrest\API\Responses\Response;

/**
 * PhrestDI
 */
class PhrestDI extends FactoryDefault
{
  /**
   * Construct all of the dependencies for the API
   */
  public function __construct()
  {
    parent::__construct();

    $this->setShared('request',
      function ()
      {
        return new PhrestRequest();
      }
    );

    $this->setShared('oauth2',
      function ()
      {
        return false;
      }
    );


    $this->setShared('router',
      function ()
      {
        return new Router;
      }
    );
{'fraction_non_alphanumeric': 0.12105582524271845, 'fraction_numerical': 0.009101941747572815, 'mean_word_length': 3.232349165596919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '4697124', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1105, 'n_words': 229}