2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
22 #include "hphp/runtime/base/type-string.h"
23 #include "hphp/util/assertions.h"
49 virtual ~AutoloadMap() = default;
52 * Block until the AutoloadMap is up-to-date.
54 * May throw an exception if updating failed.
56 virtual void ensureUpdated() {
60 * True iff this AutoloadMap knows which files contain which symbols without
61 * needing to query userland Hack code. If we're using a native AutoloadMap,
62 * we'll be able to use any symbol when the very first line of Hack code is
65 virtual bool isNative() const noexcept
= 0;
68 * Given the name of a type and the kind of type we're looking for,
69 * return the absolute path of the file defining that type.
71 * Return None if the file is defined in zero places or more than
74 std::optional
<String
> getFile(KindOf kind
,
75 const String
& typeName
) {
77 case AutoloadMap::KindOf::Type
:
78 return getTypeFile(typeName
);
79 case AutoloadMap::KindOf::Function
:
80 return getFunctionFile(typeName
);
81 case AutoloadMap::KindOf::Constant
:
82 return getConstantFile(typeName
);
83 case AutoloadMap::KindOf::TypeAlias
:
84 return getTypeAliasFile(typeName
);
89 Array
getSymbols(KindOf kind
,
92 case AutoloadMap::KindOf::Type
:
93 return getFileTypes(path
);
94 case AutoloadMap::KindOf::Function
:
95 return getFileFunctions(path
);
96 case AutoloadMap::KindOf::Constant
:
97 return getFileConstants(path
);
98 case AutoloadMap::KindOf::TypeAlias
:
99 return getFileTypeAliases(path
);
105 * Get all filepaths known to the autoloader at this point in time.
107 * Each path must be an absolute path with all symlinks dereferenced.
109 virtual Array
getAllFiles() const = 0;
112 * Map symbols to files
114 virtual std::optional
<String
> getTypeFile(
115 const String
& typeName
) = 0;
116 virtual std::optional
<String
> getFunctionFile(
117 const String
& functionName
) = 0;
118 virtual std::optional
<String
> getConstantFile(
119 const String
& constantName
) = 0;
120 virtual std::optional
<String
> getTypeAliasFile(
121 const String
& typeAliasName
) = 0;
124 * Map path to symbols
126 virtual Array
getFileTypes(const String
& path
) = 0;
127 virtual Array
getFileFunctions(const String
& path
) = 0;
128 virtual Array
getFileConstants(const String
& path
) = 0;
129 virtual Array
getFileTypeAliases(const String
& path
) = 0;
131 virtual bool canHandleFailure() const = 0;
132 virtual Result
handleFailure(KindOf kind
, const String
& className
,
133 const Variant
& err
) const = 0;
137 * An AutoloadMap which can also return data not directly related to
140 struct FactsStore
: public AutoloadMap
{
142 virtual ~FactsStore() = default;
145 * Return the correctly-capitalized name of `type`.
147 * Return `null` if `type` is not defined, or if it is defined in more than
150 virtual Variant
getTypeName(const String
& type
) = 0;
153 * Return whether the given type is a class, enum, interface, or trait.
155 * Return `null` if given none of the above.
157 virtual Variant
getKind(const String
& type
) = 0;
160 * Return true iff the type cannot be constructed.
162 virtual bool isTypeAbstract(const String
& type
) = 0;
165 * Return true iff no other type can inherit from this type.
167 virtual bool isTypeFinal(const String
& type
) = 0;
170 * Return all types in the repo which the given type extends.
172 virtual Array
getBaseTypes(
173 const String
& derivedType
, const Variant
& filters
) = 0;
176 * Return all types in the repo which extend the given type.
178 virtual Array
getDerivedTypes(
179 const String
& baseType
, const Variant
& filters
) = 0;
182 * Return all types in the repo which transitively extend the given type.
184 virtual Array
getTransitiveDerivedTypes(
185 const String
& baseType
, const Variant
& filters
) = 0;
188 * Return all types decorated with the given attribute, as a
189 * keyset<classname<mixed>>.
191 virtual Array
getTypesWithAttribute(const String
& type
) = 0;
194 * Return all attributes decorating the given type.
196 virtual Array
getTypeAttributes(const String
& type
) = 0;
199 * Return the arguments associated with the given type and attribute, as a
202 * If the given type does not have the given attribute, return an empty vec.
204 virtual Array
getTypeAttrArgs(const String
& type
, const String
& attr
) = 0;
207 * Return all symbols defined in the repo, as a dict mapping each symbol
208 * name to the path where the symbol lives in the repo.
210 * If a symbol is defined in more than one path, one of the paths defining the
211 * symbol will be chosen in an unspecified manner.
213 virtual Array
getAllTypes() = 0;
214 virtual Array
getAllFunctions() = 0;
215 virtual Array
getAllConstants() = 0;
216 virtual Array
getAllTypeAliases() = 0;