track total size of static array and Unit/Class/Func
[hiphop-php.git] / hphp / runtime / base / user-autoload-map.h
blob29d20380d636f45b14aaa9d5855bf173cacd8f60
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 +----------------------------------------------------------------------+
17 #pragma once
19 #include <vector>
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"
28 namespace HPHP {
30 //////////////////////////////////////////////////////////////////////
32 /**
33 * AutoloadMap mostly implemented in userspace Hack code.
35 struct UserAutoloadMap : AutoloadMap {
37 String m_root;
38 Array m_typeFile;
39 Array m_functionFile;
40 Array m_constantFile;
41 Array m_typeAliasFile;
42 Variant m_failFunc;
44 UserAutoloadMap(String root,
45 Array typeFile,
46 Array functionFile,
47 Array constantFile,
48 Array typeAliasFile,
49 Variant failFunc)
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 {
58 m_root.detach();
59 m_typeFile.detach();
60 m_functionFile.detach();
61 m_constantFile.detach();
62 m_typeAliasFile.detach();
63 m_failFunc.setNull();
66 static UserAutoloadMap fromFullMap(const Array& fullMap,
67 String root);
69 /**
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 {
74 return false;
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;
100 private:
101 folly::Optional<String> getFileFromMap(const Array& map,
102 const String& key) const;
105 //////////////////////////////////////////////////////////////////////