-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathcomposer-json-data.h
More file actions
79 lines (60 loc) · 2.8 KB
/
composer-json-data.h
File metadata and controls
79 lines (60 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Compiler for PHP (aka KPHP)
// Copyright (c) 2022 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt
#pragma once
#include <vector>
#include <string>
#include "compiler/data/data_ptr.h"
#include "compiler/debug.h"
// represents composer.json structure (the parts we care about)
// they are used for autoloading (in the same manner as Composer does)
// and as implicit modulites
class ComposerJsonData {
DEBUG_STRING_METHOD { return package_name; }
ComposerJsonPtr get_self_ptr() { return ComposerJsonPtr(this); }
public:
struct RequireItem {
std::string package_name;
std::string version;
bool is_dev; // whether it's in "require-dev"
};
struct AutoloadPsr0Item {
std::string prefix;
std::vector<std::string> dirs;
bool prefix_is_classname; // if true, psr-0 key is "ns\\class" not "ns\\"; dirs.size = 1, dirs[0] is a .php file
bool is_dev; // whether it's in "autoload-dev"
};
struct AutoloadPsr4Item {
std::string prefix;
std::vector<std::string> dirs;
bool is_dev; // whether it's in "autoload-dev"
};
struct AutoloadFileItem {
std::string file_name;
bool is_dev; // whether it's in "autoload-dev"
};
// "autoload/classmap" entry: a directory or .php file listed under composer.json "classmap"
// composer.json format: "autoload": { "classmap": ["src/", "lib/Foo.php"] }
// Each entry is a raw path from composer.json (absolute after resolving against the package root).
// The actual class→file scanning is performed by ComposerAutoloader when loading the file.
struct AutoloadClassmapEntry {
std::string path; // absolute path: a directory to scan or a single .php file
bool is_dev; // whether it's in "autoload-dev"
};
explicit ComposerJsonData(const std::string &json_filename);
// full absolute path to composer.json, it's registered in G, it has ->dir, kphp_error can point to it
SrcFilePtr json_file;
// "name", e.g. "vk/common"
std::string package_name;
// "require" and "require-dev", e.g. [ {"vkcom/kphp-polyfills", "^1.0", false}, ... ]
std::vector<RequireItem> require;
// "autoload/psr-0" and "autoload-dev/psr-0", e.g. [ { "foo\\my_c", ["src/foo/my/c.php"], true, false}, ... ]
std::vector<AutoloadPsr0Item> autoload_psr0;
// "autoload/psr-4" and "autoload-dev/psr-4", e.g. [ { "prefix1", ["dir"], false}, ... ]
std::vector<AutoloadPsr4Item> autoload_psr4;
// "autoload/files" and "autoload-dev/files", e.g. [ {"file.php", true}, ... ]
std::vector<AutoloadFileItem> autoload_files;
// "autoload/classmap" and "autoload-dev/classmap" (see #49)
// Each entry is a raw path (directory or .php file) to be scanned by ComposerAutoloader.
std::vector<AutoloadClassmapEntry> autoload_classmap;
};