Returns a Joomla application with a root user logged in

@param string $base Base path for the Joomla installation
@param int    $client_id Application client id to spoof. Defaults to admin.

@return Application
433795
public static function getApplication($base, $client_id = self::ADMIN)
    {
        $_SERVER['SERVER_PORT'] = 80;

        if (!self::$_application)
        {
            self::bootstrap($base);

            $options = array(
                'root_user' => 'root',
                'client_id' => $client_id
            );

            self::$_application = new Application($options);

            $credentials = array(
                'name'      => 'root',
                'username'  => 'root',
                'groups'    => array(8),
                'email'     => 'root@localhost.home'
            );

            self::$_application->authenticate($credentials);

            // If there are no marks in JProfiler debug plugin performs a division by zero using count($marks)
            \JProfiler::getInstance('Application')->mark('Hello world');
        }

        return self::$_application;
    }
362306
protected function createWebClient()
    {
        $userId = array_get($this->config, 'user_id', false);
        $licenseKey = array_get($this->config, 'license_key', false);

        // check and make sure they are set
        if (! $userId || ! $licenseKey) {
            throw new InvalidCredentialsException();
        }

        return new Client($userId, $licenseKey);
    }
715400
public function get($id, $rootId=NULL, array $columns=[])
    {
        $columns = $this->pickColumns($columns);
        $columnsId = $this->getColumnsCacheId($columns);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        // If we have a root id, fill the cache by fetching the whole tree
        if ($rootId) {
            $this->tree($rootId, $columns);
        }

        // After retrieving the tree, look if it is now in cache
        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        $result = $this->queryTreeById($id)
                       ->get($this->toSelectColumns($columns));

        $this->fillNodeCache($columnsId, $result);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

    }
617110
public function setupEnvironment($basePath, $application = 'site')
	{
		if ($application != 'site')
		{
			$basePath .= '/' . $application;
		}

		$server  = array(
			'HTTP_HOST'       => 'undefined',
			'HTTP_USER_AGENT' => 'undefined',
			'REQUEST_METHOD'  => 'GET',
		);
		$_SERVER = array_merge($_SERVER, $server);

		define('JPATH_BASE', $basePath);
		define('DS', DIRECTORY_SEPARATOR);

		require_once JPATH_BASE . '/includes/defines.php';
		require_once JPATH_LIBRARIES . '/loader.php';

		spl_autoload_register('__autoload');

		require_once JPATH_BASE . '/includes/framework.php';

		if ($application == 'administrator')
		{
			require_once JPATH_BASE . '/includes/helper.php';
			require_once JPATH_BASE . '/includes/toolbar.php';

			// JUri uses $_SERVER['HTTP_HOST'] without check
			$_SERVER['HTTP_HOST'] = 'CLI';
		}

		jimport('joomla.installer.installer');
		jimport('joomla.installer.helper');

		$mainframe = \JFactory::getApplication($application);
		$mainframe->initialise();
	}
34231
public function getClientDetails($client_id)
	{
		$client = $this->repo->find($client_id);

		if(!$client) {
			return false;
		}

		$clientDetails = array(
			'client_id' => $client->getId(),
			'redirect_uri' => $client->getRedirectUri(),
		);


		if ($client instanceof ScopeInterface) {
			if (is_array($scopes = $client->getScopes())) {
				$clientDetails['scope'] = implode(' ', $scopes);
			}
		}

		return $clientDetails;
	}
1271096
public static function fromSha($sha, $baseUrl, ClientInterface $client)
    {
        $url = Project::getProjectBaseFromUrl($baseUrl) . '/git/trees';

        return static::get($sha, $url, $client);
    }
979965
public function get(int $id, CustomerRequest $customerRequest = null): Customer
    {
        $customerResource = $this->restClient->getResource(
            Customer::class,
            sprintf('/v2/customers/%d', $id)
        );

        return $this->hydrateCustomerWithSubEntities(
            $customerResource,
            $customerRequest ?: new CustomerRequest()
        );
    }
1051845
private function getReferredParentId($customerId)
    {
        /* use customer ID as parent ID if parent ID cannot be defined */
        $result = $customerId;
        $area = $this->state->getAreaCode();
        if ($area == \Magento\Framework\App\Area::AREA_ADMINHTML) {
            /* use default MLM ID from config */
            $defRootMlmId = $this->hlpConfig->getReferralsRootAnonymous();
            $parent = $this->daoDwnlCust->getByMlmId($defRootMlmId);
            if ($parent) {
                $result = $parent->getCustomerRef();
                $this->logger->info("Default root parent #$result is used for customer #$customerId (admin mode).");
            }
        } else {
            /* try to extract referral code from Mage registry */
            $code = $this->hlpReferral->getReferralCode();
            if ($code) {
                /* this is a referral customer, use parent from referral code */
                $parent = $this->daoDwnlCust->getByReferralCode($code);
                if ($parent) {
                    $result = $parent->getCustomerRef();
                    $this->logger->info("Referral parent #$result is used for customer #$customerId.");
                }
            } else {
                /* this is anonymous customer, use parent from config */
                $anonRootMlmId = $this->hlpConfig->getReferralsRootAnonymous();
                $parent = $this->daoDwnlCust->getByMlmId($anonRootMlmId);
                if ($parent) {
                    $result = $parent->getCustomerRef();
                    $this->logger->info("Anonymous root parent #$result is used for customer #$customerId.");
                }
            }
        }
        return $result;
    }
52884
public function getClientDetails($client_id)
    {
        $result = $this->collection('client_table')->findOne(array('client_id' => $client_id));
        return is_null($result) ? false : $result;
    }
1267779
protected function obtainCookies(array &$options, $base_uri = null)
    {
        $client = new Client();

        $loginOptions = [
            'debug' => isset($options['debug']) && $options['debug'] ? true : false,
            'allow_redirects' => false,
            'cookies' => $this->coockieJar
        ];

        if (!is_null($base_uri)) {
            $loginOptions['base_uri'] = $base_uri;
        }

        $method = 'GET';
        if ($this->config['method'] === 'POST') {
            $loginOptions['form_params'] = $this->config['fields'];
            $method                      = 'POST';
        } else if ($this->config['method'] === 'JSON') {
            $loginOptions['body']                    = json_encode($this->config['fields']);
            $loginOptions['headers']['Content-Type'] = 'application/json';
            $method                                  = 'POST';
        } else if ($this->config['method'] === 'GET') {
            $loginOptions['query'] = !is_array($this->config['fields']) ? (array) $this->config['fields']
                    : $this->config['fields'];
        }

        if (isset($options['auth-cookie']['onBeforeLogin'])) {
            $closer       = $options['auth-cookie']['onBeforeLogin'];
            $loginOptions = $closer($loginOptions);
            if (false === $loginOptions) {
                return;
            }
        }

        $client->request($method, $this->config['uri'], $loginOptions);

        $this->loginMade = true;
    }
36384
public static function queryByBaseId( $baseId, $config = [] ) {

		$type	= isset( $config[ 'type' ] ) ? $config[ 'type' ] : self::TYPE_COMMENT;
		$status	= isset( $config[ 'status' ] ) ? $config[ 'status' ] : self::STATUS_APPROVED;

		return self::find()->where( [ 'baseId' => $baseId, 'type' => $type, 'status' => $status ] );
	}
851862
public function getClient()
    {
        if ( $this->client ) {
            return $this->client;
        }

        $this->client = new Client(self::BASE_URL);

        return $this->client;
    }
788649
public function getClient($id)
    {
        $response = $this->get('/en/client/edit/id/' . $id);

        $content = trim($this->getBetween((string)$response->getBody(), '<table class="wide">', "</table>"));

        $client = new Client(array(
            'id' => $id,
            'email' => $this->getBetween($content, '<input type="text" name="email" id="email" value="', '">'),
            'first_name' => $this->getBetween($content, '<input type="text" name="first_name" id="first_name" value="', '">'),
            'last_name' => $this->getBetween($content, '<input type="text" name="last_name" id="last_name" value="', '">'),
            'company' => $this->getBetween($content, '<input type="text" name="company" id="company" value="', '">'),
            'address_1' => $this->getBetween($content, '<input type="text" name="address_1" id="address_1" value="', '">'),
            'address_2' => $this->getBetween($content, '<input type="text" name="address_2" id="address_2" value="', '">'),
            'country' => $this->getBetweenReverse($content, '<option value="', '" selected="selected">'),
            'city' => $this->getBetween($content, '<input type="text" name="city" id="city" value="', '">'),
            'state' => $this->getBetween($content, '<input type="text" name="state" id="state" value="', '">'),
            'zip' => $this->getBetween($content, '<input type="text" name="zip" id="zip" value="', '">'),
            'phone_cc' => $this->getBetween($content, '<input type="text" name="phone_cc" id="phone_cc" value="', '">'),
            'phone' => $this->getBetween($content, '<input type="text" name="phone" id="phone" value="', '">'),
        ));

        return $client;
    }
952431
public function get($user_id, $params = [])
    {
        return User::make($this->client, $user_id)
            ->setParams($params);
    }
1146799
public function getUserEntityByUserCredentials(
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    ): ?UserEntityInterface {
        $builder = $this->connection->createQueryBuilder();
        $user = $builder->select(['user.id', 'user.password'])
            ->from('user')
            ->where('username = :username')
            ->setParameter('username', $username)
            ->execute()
            ->fetch();

        if (!$user) {
            return null;
        }

        if (!password_verify($password, $user['password'])) {
            return null;
        }

        return new User(Uuid::fromBytesToHex($user['id']));
    }
225228
public function getPublicKey($client_id = null)
    {
        if (isset($this->keys[$client_id])) {
            return $this->keys[$client_id]['public_key'];
        }

        // use a global encryption pair
        if (isset($this->keys['public_key'])) {
            return $this->keys['public_key'];
        }

        return false;
    }
341901
public static function base()
    {
        if (! isset(self::$_base)) {
            // Get the base request path
            if (strpos(PHP_SAPI, 'cgi') !== false && !ini_get('cgi.fix_pathinfo')  && !empty($_SERVER['REQUEST_URI'])) {
                // PHP-CGI on Apache with "cgi.fix_pathinfo = 0"
                // We don't have user-supplied PATH_INFO in PHP_SELF
                $path = $_SERVER['PHP_SELF'];
            } else {
                $path = $_SERVER['SCRIPT_NAME'];
            }

            $path = rtrim(dirname($path), '/\\');

            // Sanitize the url since we can't trust the server var
            $path = AnService::get('anahita:filter.url')->sanitize($path);

            self::$_base = AnService::get('anahita:http.url', array('url' => $path));
        }

        return self::$_base;
    }