protected $shared = [ 'codex.phpdoc' => Phpdoc::class, ];
323104
public function boot()
    {
        parent::boot();

        // add scripts and styles to be used globally.
        $this->codex()->theme
            ->addStylesheet('codex.phpdoc', asset('/vendor/codex/styles/codex.phpdoc.document.css'), [ 'codex' ])
            ->addJavascript('codex.phpdoc', asset('/vendor/codex/js/codex.phpdoc.js'), [ 'codex.page.document', 'codex' ])
            ->addJavascript('codex.page.phpdoc', asset('/vendor/codex/js/codex.page.phpdoc.js'), [ 'codex.phpdoc' ]);


        // 1. Ensure both the Codex plugin and CodexPhpdoc plugin are loaded for documents. This enables all phpdoc components for use in documents.
        // 2. Then make it so that the original init script (and its depends) run AFTER loading the plugins, by adding it as a dependency
        $this->hook('controller:document', function ($controller, Document $document) {
            if ( false === $document->getProject()->config('phpdoc.enabled', false) ) {
                return;
            }
            $this->codex()->theme
                ->set('phpdoc.url', $document->getProject()->url($document->getProject()->config('phpdoc.document_slug'), $document->getRef()->getName()));
        });

        // If the current document is the PHPDoc document viewer, add the required assets and add the proper init script
        $this->hook('controller:document', function ($controller, Document $document) {
            if (
                $document->getPathName() !== $document->getProject()->config('phpdoc.document_slug')
                || false === $document->getProject()->config('phpdoc.enabled', false)
            ) {
                return;
            }
            $this->codex()->theme
                ->addJavascript('jstree', asset('/vendor/codex/vendor/jstree/jstree.js'), [ 'jquery' ])
                ->addStylesheet('codex.page.phpdoc', asset('/vendor/codex/styles/codex.page.phpdoc.css'), [ 'codex' ]);
        });
    }
551847
public function shareObject($config = array())
    {
        $config = new AnConfig($config);

        if (!$config->object) {
            throw new InvalidArgumentException('Not object specified to share');
        }

        $config->append(array(
             'sharer' => get_viewer(),
        ));

        if ($config->object->isOwnable()) {
            $config->append(array(
                'target' => $config->object->owner,
            ));
        }

        $request = new ComSharesSharerRequest($config);
        $sharers = new ArrayObject();
        dispatch_plugin('connect.onGetShareAdapters', array('adapters' => $sharers, 'request' => $request));

        if ($config->sharers) {
            $sharers = array_filter((array) $sharers, function ($sharer) use ($config) {
               return in_array($sharer->getIdentifier()->name, $config['sharers']);
            });
        }

        foreach ($sharers as $sharer) {
            $sharer->shareRequest($request);
        }
    }
597220
public function sharedLock()
    {
        // Pack query then move it to write DB from read DB for transaction
        $sql = $this->_dbr->get_compiled_select();
        $this->_dbr->reset_query();

        return $this->_db->query("{$sql} LOCK IN SHARE MODE");
    }
653820
public function getFieldTypes()
    {
        static $cached = [];

        $class = static::class;

        if (!isset($cached[$class])) {
            if (!$doc = static::sample()) {

                if (!$docs = $this->getConnection()->fetchAll($this->getSource(), [], ['limit' => 1])) {
                    throw new RuntimeException(['`:collection` collection has none record', 'collection' => $this->getSource()]);
                }
                $doc = $docs[0];
            }

            $types = [];
            foreach ($doc as $field => $value) {
                $type = gettype($value);
                if ($type === 'integer') {
                    $types[$field] = 'int';
                } elseif ($type === 'string') {
                    $types[$field] = 'string';
                } elseif ($type === 'double') {
                    $types[$field] = 'float';
                } elseif ($type === 'boolean') {
                    $types[$field] = 'bool';
                } elseif ($type === 'array') {
                    $types[$field] = 'array';
                } elseif ($value instanceof ObjectID) {
                    if ($field === '_id') {
                        continue;
                    }
                    $types[$field] = 'objectid';
                } else {
                    throw new RuntimeException(['`:field` field value type can not be infered.', 'field' => $field]);
                }
            }

            $cached[$class] = $types;
        }

        return $cached[$class];
    }
696099
private function getEditorSnippetsAndClasses()
    {
        $obj = new stdClass();
        $obj->snippets = [];
        $u = new User();
        if ($u->isRegistered()) {
            $snippets = \Concrete\Core\Editor\Snippet::getActiveList();
            foreach ($snippets as $sns) {
                $menu = new stdClass();
                $menu->scsHandle = $sns->getSystemContentEditorSnippetHandle();
                $menu->scsName = $sns->getSystemContentEditorSnippetName();
                $obj->snippets[] = $menu;
            }
        }
        $c = Page::getCurrentPage();
        $obj->classes = [];
        if (is_object($c) && !$c->isError()) {
            $cp = new Permissions($c);
            if ($cp->canViewPage()) {
                $pt = $c->getCollectionThemeObject();
                if (is_object($pt)) {
                    if ($pt->getThemeHandle()) {
                        $obj->classes = $pt->getThemeEditorClasses();
                    } else {
                        $siteTheme = $pt::getSiteTheme();
                        if (is_object($siteTheme)) {
                            $obj->classes = $siteTheme->getThemeEditorClasses();
                        }
                    }
                }
            }
        } else {
            $siteTheme = PageTheme::getSiteTheme();
            if (is_object($siteTheme)) {
                $obj->classes = $siteTheme->getThemeEditorClasses();
            }
        }

        return $obj;
    }
783180
public function listShares() {
		$command = sprintf(
			'%s %s %s -L %s',
			$this->system->getSmbclientPath(),
			$this->getAuthFileArgument(),
			$this->getAuth()->getExtraCommandLineArguments(),
			escapeshellarg('//' . $this->getHost())
		);
		$connection = new RawConnection($command);
		$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword());
		$connection->connect();
		if (!$connection->isValid()) {
			throw new ConnectionException($connection->readLine());
		}

		$parser = new Parser($this->timezoneProvider);

		$output = $connection->readAll();
		if (isset($output[0])) {
			$parser->checkConnectionError($output[0]);
		}

		// sometimes we get an empty line first
		if (count($output) < 2) {
			$output = $connection->readAll();
		}

		if (isset($output[0])) {
			$parser->checkConnectionError($output[0]);
		}

		$shareNames = $parser->parseListShares($output);

		$shares = [];
		foreach ($shareNames as $name => $description) {
			$shares[] = $this->getShare($name);
		}
		return $shares;
	}
489648
public function addSharedInstanceWithParameters($instance, $classOrAlias, array $params)
        {
            ksort($params);
            $hashKey = $this->createHashForKeys($classOrAlias, array_keys($params));
            $hashValue = $this->createHashForValues($classOrAlias, $params);

            if (!isset($this->sharedInstancesWithParams[$hashKey])
                || !is_array($this->sharedInstancesWithParams[$hashKey])) {
                $this->sharedInstancesWithParams[$hashKey] = [];
            }

            $this->sharedInstancesWithParams['hashShort'][$hashKey] = true;
            $this->sharedInstancesWithParams['hashLong'][$hashKey . '/' . $hashValue] = $instance;
        }
1301063
private function getSharedForUser(User $user, array $shared)
    {
        $userLink = null;
        foreach ($shared as $shareLink) {
            if ($shareLink->getUser() === $user) {
                $userLink = $shareLink;
                break;
            }
        }

        return $userLink;
    }
1275048
public function share( $key, $value = null )
	{
		if ( !is_array( $key ) )
			return $this->shared[$key] = $value;

		foreach ( $key as $innerKey => $innerValue )
			$this->share( $innerKey, $innerValue );

		return null;
	}
37967
protected function addUseStatement(File $phpcsFile, string $shortName, string $fullName): array
    {
        foreach ($this->allStatements as $useStatement) {
            if ($useStatement['fullName'] === $fullName) {
                return $useStatement;
            }
        }

        $alias = $this->generateUniqueAlias($phpcsFile, $shortName, $fullName);
        if (!$alias) {
            throw new RuntimeException(sprintf('Could not generate unique alias for %s (%s).', $shortName, $fullName));
        }

        $result = [
            'alias' => $alias === $shortName ? null : $alias,
            'fullName' => $fullName,
            'shortName' => $shortName,
        ];
        $this->insertUseStatement($phpcsFile, $result);

        $this->allStatements[$alias] = $result;
        $this->newStatements[$alias] = $result;

        return $result;
    }
1006735
public function buckets($shared = true)
    {
        $includeShared = "false";
        if ($shared === true) {
            $includeShared = "true";
        }
        return $this->rsGet('/buckets?shared=' . $includeShared);
    }
863555
public function bindIf($abstract, $concrete = null, $shared = false)
    {
        if (! $this->bound($abstract)) {
            $this->bind($abstract, $concrete, $shared);
        }
    }
164825
private function parsePhpDoc(string $phpDoc, string $class, string $name = null)
    {
        $phpDoc = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $phpDoc);
        $phpDoc = ltrim($phpDoc, "\r\n");

        $split = preg_split("/(\n@)/isU", $phpDoc, -1, PREG_SPLIT_DELIM_CAPTURE);

        if (!isset($split[0][0])) {
            throw new \Exception(sprintf("Empty PhpDoc for '%s::%s'", $class, $name));
        }

        if ($split[0][0] != '@') {
            $comments = explode("\n", array_shift($split));

            $this->add(new Comment(isset($comments[0]) ? array_shift($comments) : null), Definition::COMMENT);

            $commentLong = isset($comments[0]) ? trim(implode($comments, "\n"), "\n") : null;
            if ($commentLong) {
                $this->add(new CommentLong($commentLong), Definition::COMMENT_LONG);
            }
        } else {
            $split[0] = substr($split[0], 1);
        }

        foreach ($split as $content) {
            if ($content == '@') {
                continue;
            }

            // clean up variables
            $tempString = str_replace('  ', '-', $content);
            while ($content != $tempString) {
                $tempString = $content;
                $content = str_replace('  ', ' ', $content);
            }

            $explode = explode(' ', trim(str_replace("\t", '  ', $content)));

            $paramType = array_shift($explode);
            if ($paramType == '@') {
                continue;
            }

            switch ($paramType) {
                case Definition::PARAM:
                    $this->add(new Param($explode), $paramType, true);
                    break;

                case Definition::RETURNS:
                    $this->add(new ReturnType($explode), $paramType);
                    break;

                case Definition::THROWS:
                    $this->add(new Throws($explode), $paramType, true);
                    break;

                case Definition::RESPONSE:
                    $this->add(new Response($explode), $paramType, true);
                    break;

                case Definition::EXAMPLE:
                    $this->add(new Example($explode), $paramType, true);
                    break;

                case Definition::HEADER:
                    $this->add(new Header($explode), $paramType, true);
                    break;

                case Definition::AUTH:
                    $this->add(new Auth(implode(' ', $explode)), $paramType);
                    break;

                case Definition::HTTP_METHOD:
                    $this->add(new HttpMethod(implode(' ', $explode)), $paramType);
                    break;

                default:
                    throw new \InvalidArgumentException(
                        sprintf("Invalid param type '%s' on '%s::%s'", $paramType, $class, $name)
                    );
            }
        }

        if (is_null($this->getDefinition(Definition::RESPONSE)) &&
            !is_null($this->getDefinition(Definition::RETURNS))
        ) {
            $response = new Response();
            /* @noinspection PhpParamsInspection */
            $response->fromReturn($this->getDefinition(Definition::RETURNS));

            $this->add($response, Definition::RESPONSE, true);
        }
    }
245185
public function setInvokableClass($name, $invokableClass, $shared = null)
    {
        $invokableClass = strtr($invokableClass, '.', '\\');
        return parent::setInvokableClass($name, $invokableClass, $shared);
    }
99018
protected function getSharedDir()
    {
        $shared = $this->app->getSourceDir() . '/' . $this->config->get('local.shared_dir');
        if (!$this->app->isSingle()) {
            $shared .= '/' . preg_replace('/[^a-z0-9\-_]+/i', '-', $this->app->getName());
        }
        $this->fsHelper->mkdir($shared);

        return $shared;
    }
1358098
public function getRelatedPages()
    {
        $pages = ArrayList::create();

        foreach ($this->Sets() as $documentSet) {
            /** @var DocumentSet $documentSet */
            $pages->add($documentSet->Page());
        }
        $pages->removeDuplicates();

        $this->extend('updateRelatedPages', $pages);

        return $pages;
    }
407361
private function requireCachedClasses()
    {
        $classPath = $this->cachePath;
        if (is_dir($classPath)) {
            $finder = new Finder();
            $actionManagerFiles = $finder->files()->depth(1)->name('*.php')->in($classPath);
            foreach ($actionManagerFiles as $actionManagerFile) {
                $classFileName = (string)$actionManagerFile;
                $classContents = file_get_contents($classFileName);
                preg_match('/namespace ([\w\\\]+);.*?class ([\w]+).*?{/s', $classContents, $match);
                if (isset($match[1]) && isset($match[2])) {
                    $class = $match[1] . '\\' . $match[2];
                    if (!in_array($class, get_declared_classes())) @require_once $classFileName;
                }
            }
        }
    }