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 +----------------------------------------------------------------------+
21 #include <folly/Optional.h>
23 #include "hphp/runtime/base/array-init.h"
24 #include "hphp/runtime/base/autoload-map.h"
25 #include "hphp/runtime/base/type-string.h"
26 #include "hphp/runtime/base/type-variant.h"
30 //////////////////////////////////////////////////////////////////////
33 * AutoloadMap mostly implemented in userspace Hack code.
35 struct UserAutoloadMap
: AutoloadMap
{
41 Array m_typeAliasFile
;
44 UserAutoloadMap(String root
,
50 : m_root
{std::move(root
)},
51 m_typeFile
{std::move(typeFile
)},
52 m_functionFile
{std::move(functionFile
)},
53 m_constantFile
{std::move(constantFile
)},
54 m_typeAliasFile
{std::move(typeAliasFile
)},
55 m_failFunc(std::move(failFunc
)) {}
57 ~UserAutoloadMap() override
{
60 m_functionFile
.detach();
61 m_constantFile
.detach();
62 m_typeAliasFile
.detach();
66 static UserAutoloadMap
fromFullMap(const Array
& fullMap
,
70 * This map is not native because it gets data when userspace calls the
71 * builtin function `autoload_set_paths()`.
73 virtual bool isNative() const noexcept override
{
77 virtual Array
getAllFiles() const override
;
79 virtual folly::Optional
<String
> getTypeFile(
80 const String
& typeName
) override
;
81 virtual folly::Optional
<String
> getFunctionFile(
82 const String
& functionName
) override
;
83 virtual folly::Optional
<String
> getConstantFile(
84 const String
& constantName
) override
;
85 virtual folly::Optional
<String
> getTypeAliasFile(
86 const String
& typeAliasName
) override
;
88 virtual Array
getFileTypes(const String
& path
) override
;
89 virtual Array
getFileFunctions(const String
& path
) override
;
90 virtual Array
getFileConstants(const String
& path
) override
;
91 virtual Array
getFileTypeAliases(const String
& path
) override
;
93 virtual bool canHandleFailure() const override
{
94 return !m_failFunc
.isNull();
96 virtual AutoloadMap::Result
handleFailure(KindOf kind
,
97 const String
& className
,
98 const Variant
& err
) const override
;
101 folly::Optional
<String
> getFileFromMap(const Array
& map
,
102 const String
& key
) const;
105 //////////////////////////////////////////////////////////////////////