From 0f8250e702fb09eca57d6c25183f35444c20944d Mon Sep 17 00:00:00 2001 From: enriquo Date: Tue, 30 Sep 2025 11:14:10 +0200 Subject: [PATCH] initial commit --- .editorconfig | 12 + .gitattributes | 5 + .gitignore | 5 + LICENSE.md | 232 ++ README.md | 332 +++ bin/core | 0 composer.json | 58 + composer.lock | 2165 +++++++++++++++++ phpcs.xml.dist | 46 + phpunit.xml.dist | 25 + src/Application.php | 935 +++++++ src/Assets/Asset/Asset.php | 226 ++ src/Assets/Asset/Json_Asset.php | 45 + src/Assets/Asset/Meta_Asset.php | 66 + src/Assets/Asset/Php_Asset.php | 72 + src/Assets/Asset/Svg_Asset.php | 19 + src/Assets/Asset/Text_Asset.php | 84 + src/Assets/Asset_Factory.php | 98 + src/Assets/Bundle.php | 216 ++ src/Assets/Concerns/Conditional.php | 38 + src/Assets/Concerns/Enqueuable.php | 252 ++ src/Assets/Contracts/Asset.php | 72 + src/Assets/Contracts/Asset_Meta.php | 27 + src/Assets/Contracts/Bundle.php | 22 + src/Assets/Contracts/Manifest.php | 38 + src/Assets/Contracts/Meta.php | 21 + src/Assets/Contracts/Php.php | 21 + .../Binding_Resolution_Exception.php | 11 + .../Exceptions/Bundle_Not_Found_Exception.php | 10 + .../Manifest_Not_Found_Exception.php | 10 + .../Exceptions/Meta_Not_Found_Exception.php | 10 + .../Exceptions/Skip_Module_Exception.php | 60 + src/Assets/Manager.php | 114 + src/Assets/Manifest.php | 150 ++ src/Assets/Meta.php | 75 + src/Bootloader.php | 242 ++ src/Config/Environment.php | 109 + src/Config/Repository.php | 189 ++ src/Contracts/Application.php | 87 + src/Contracts/Deferrable_Module.php | 25 + src/Contracts/Repository.php | 64 + .../Exceptions/File_Not_Found_Exception.php | 10 + src/Filesystem/Filesystem.php | 184 ++ src/Filesystem/Loader.php | 97 + src/Filesystem/functions.php | 25 + src/Module.php | 60 + src/Modules/Contracts/Deferrable_Module.php | 25 + src/Modules/Contracts/Module.php | 33 + src/Modules/Manager.php | 104 + src/Modules/Module/Module.php | 155 ++ src/Modules/Module_Factory.php | 35 + src/Support/Arriable.php | 536 ++++ src/Support/Contracts/Arrayable.php | 29 + src/Support/Contracts/Jsonable.php | 30 + src/Support/Str.php | 393 +++ src/Support/Stringable.php | 110 + src/Support/Traits/Aliases.php | 123 + src/Support/Traits/Application.php | 7 + src/Support/Traits/Macroable.php | 127 + src/Utility/Contracts/Encrypter.php | 55 + src/Utility/Contracts/Hasher.php | 31 + src/Utility/Contracts/String_Encrypter.php | 37 + src/Utility/Encryption.php | 352 +++ src/Utility/Exceptions/Decrypt_Exception.php | 10 + src/Utility/Exceptions/Encrypt_Exception.php | 10 + src/Utility/Hash.php | 33 + src/globals.php | 156 ++ src/helpers.php | 310 +++ 68 files changed, 9365 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 bin/core create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 phpcs.xml.dist create mode 100644 phpunit.xml.dist create mode 100644 src/Application.php create mode 100644 src/Assets/Asset/Asset.php create mode 100644 src/Assets/Asset/Json_Asset.php create mode 100644 src/Assets/Asset/Meta_Asset.php create mode 100644 src/Assets/Asset/Php_Asset.php create mode 100644 src/Assets/Asset/Svg_Asset.php create mode 100644 src/Assets/Asset/Text_Asset.php create mode 100644 src/Assets/Asset_Factory.php create mode 100644 src/Assets/Bundle.php create mode 100644 src/Assets/Concerns/Conditional.php create mode 100644 src/Assets/Concerns/Enqueuable.php create mode 100644 src/Assets/Contracts/Asset.php create mode 100644 src/Assets/Contracts/Asset_Meta.php create mode 100644 src/Assets/Contracts/Bundle.php create mode 100644 src/Assets/Contracts/Manifest.php create mode 100644 src/Assets/Contracts/Meta.php create mode 100644 src/Assets/Contracts/Php.php create mode 100644 src/Assets/Exceptions/Binding_Resolution_Exception.php create mode 100644 src/Assets/Exceptions/Bundle_Not_Found_Exception.php create mode 100644 src/Assets/Exceptions/Manifest_Not_Found_Exception.php create mode 100644 src/Assets/Exceptions/Meta_Not_Found_Exception.php create mode 100644 src/Assets/Exceptions/Skip_Module_Exception.php create mode 100644 src/Assets/Manager.php create mode 100644 src/Assets/Manifest.php create mode 100644 src/Assets/Meta.php create mode 100644 src/Bootloader.php create mode 100644 src/Config/Environment.php create mode 100644 src/Config/Repository.php create mode 100644 src/Contracts/Application.php create mode 100644 src/Contracts/Deferrable_Module.php create mode 100644 src/Contracts/Repository.php create mode 100644 src/Filesystem/Exceptions/File_Not_Found_Exception.php create mode 100644 src/Filesystem/Filesystem.php create mode 100644 src/Filesystem/Loader.php create mode 100644 src/Filesystem/functions.php create mode 100644 src/Module.php create mode 100644 src/Modules/Contracts/Deferrable_Module.php create mode 100644 src/Modules/Contracts/Module.php create mode 100644 src/Modules/Manager.php create mode 100644 src/Modules/Module/Module.php create mode 100644 src/Modules/Module_Factory.php create mode 100644 src/Support/Arriable.php create mode 100644 src/Support/Contracts/Arrayable.php create mode 100644 src/Support/Contracts/Jsonable.php create mode 100644 src/Support/Str.php create mode 100644 src/Support/Stringable.php create mode 100644 src/Support/Traits/Aliases.php create mode 100644 src/Support/Traits/Application.php create mode 100644 src/Support/Traits/Macroable.php create mode 100644 src/Utility/Contracts/Encrypter.php create mode 100644 src/Utility/Contracts/Hasher.php create mode 100644 src/Utility/Contracts/String_Encrypter.php create mode 100644 src/Utility/Encryption.php create mode 100644 src/Utility/Exceptions/Decrypt_Exception.php create mode 100644 src/Utility/Exceptions/Encrypt_Exception.php create mode 100644 src/Utility/Hash.php create mode 100644 src/globals.php create mode 100644 src/helpers.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..07e19ea --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..406cf53 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# All files are checked into the repo with LF +* text=auto eol=lf + +# These files are checked out using CRLF locally +*.bat eol=crlf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b538b81 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.php_cs.cache +.phpunit.* +phpunit.xml +/coverage +/vendor \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0715ee9 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,232 @@ +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + core + Copyright (C) 2025 webshr + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + core Copyright (C) 2025 webshr + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9e43a5 --- /dev/null +++ b/README.md @@ -0,0 +1,332 @@ +# Webshr Core + +A modern, modular framework for WordPress projects built with PHP 8.1+ and inspired by Laravel's architecture. + +## Overview + +Webshr Core is a lightweight yet powerful framework designed specifically for WordPress development. It provides a clean, object-oriented approach to building WordPress themes and plugins with modern PHP features, dependency injection, and a modular architecture. + +## Features + +- **Modern PHP Architecture**: Built with PHP 8.1+ using PSR-4 autoloading +- **Modular System**: Extensible module-based architecture for clean code organization +- **Asset Management**: Comprehensive asset handling with manifest support and bundling +- **Dependency Injection**: Service container for managing dependencies and bindings +- **Encryption & Security**: Built-in encryption utilities with multiple cipher support +- **Configuration Management**: Flexible configuration system with environment support +- **Helper Functions**: Rich set of utility functions for common WordPress tasks +- **String Utilities**: Comprehensive string manipulation helpers +- **Filesystem Abstraction**: Clean filesystem operations with proper error handling + +## Installation + +```bash +composer require webshr/core +``` + +## Quick Start + +### Basic Setup + +```php +boot(); +``` + +### Using the Application Container + +```php +use Webshr\Core\app; + +// Get the application instance +$app = app(); + +// Resolve services from the container +$encryption = app('encryption'); +$assets = app('assets'); +``` + +## Core Components + +### Application Container + +The `Application` class serves as the main service container and communication hub: + +```php +use Webshr\Core\Application; + +$app = new Application(); + +// Bind services +$app->instance('my-service', new MyService()); + +// Resolve services +$service = $app->make('my-service'); + +// Register singletons +$app->singleton('database', Database::class); +``` + +### Module System + +Create modular functionality using the module system: + +```php +use Webshr\Core\Module; + +class MyModule extends Module +{ + public function register(): void + { + // Register WordPress hooks, services, etc. + add_action('init', [$this, 'init']); + } + + public function boot(): void + { + // Boot logic after registration + } + + public function can_register(): bool + { + return true; // Conditional registration + } +} +``` + +### Asset Management + +Handle assets with manifest support and bundling: + +```php +use Webshr\Core\asset; +use Webshr\Core\bundle; + +// Get individual assets +$css = asset('styles/main.css'); +$js = asset('scripts/app.js'); + +// Get asset bundles +$mainBundle = bundle('main'); + +// Enqueue CSS files +$mainBundle->css(function($handle, $src) { + wp_enqueue_style($handle, $src); +}); + +// Enqueue JS files +$mainBundle->js(function($handle, $src, $deps) { + wp_enqueue_script($handle, $src, $deps); +}); +``` + +### Encryption Utilities + +Secure data with built-in encryption: + +```php +use Webshr\Core\encrypt; +use Webshr\Core\decrypt; + +// Encrypt data +$encrypted = encrypt('sensitive data'); + +// Decrypt data +$decrypted = decrypt($encrypted); + +// String-specific encryption (no serialization) +$encrypted = encrypt_string('plain text'); +$decrypted = decrypt_string($encrypted); +``` + +### String Utilities + +Rich string manipulation helpers: + +```php +use Webshr\Core\Support\Str; + +// String operations +Str::contains('Hello World', 'World'); // true +Str::starts_with('Hello World', 'Hello'); // true +Str::ends_with('Hello World', 'World'); // true + +// String extraction +Str::before('user@example.com', '@'); // 'user' +Str::after('user@example.com', '@'); // 'example.com' +Str::between('Hello [World]', '[', ']'); // 'World' + +// Pattern matching +Str::is('admin/*', 'admin/users'); // true +``` + +## Configuration + +### Environment Configuration + +The framework supports environment-based configuration: + +```php +// config/app.php +return [ + 'paths' => [ + 'base' => get_template_directory(), + 'config' => get_template_directory() . '/config', + 'resources' => get_template_directory() . '/resources', + 'storage' => get_template_directory() . '/storage', + ], + 'modules' => [ + 'theme' => ThemeModule::class, + 'assets' => AssetModule::class, + ], + 'cipher' => 'aes-256-cbc', + 'key' => env('APP_KEY'), +]; +``` + +### Asset Configuration + +Configure asset manifests and bundles: + +```php +// config/assets.php +return [ + 'default' => 'main', + 'manifests' => [ + 'main' => [ + 'path' => get_template_directory() . '/dist', + 'url' => get_template_directory_uri() . '/dist', + 'assets' => get_template_directory() . '/dist/manifest.json', + 'bundles' => get_template_directory() . '/dist/bundles.json', + ], + ], +]; +``` + +## Helper Functions + +The framework provides numerous helper functions: + +```php +// Application helpers +app(); // Get application instance +bootloader(); // Get bootloader instance + +// Asset helpers +asset('path/to/file.css'); +bundle('main'); +meta('path/to/file.json'); + +// Module helpers +module('theme'); + +// Security helpers +encrypt($data); +decrypt($payload); +hash($data); +check($data, $hash); + +// WordPress helpers +add_actions(['init', 'wp_enqueue_scripts'], $callback); +add_filters(['the_content', 'the_title'], $callback); +require_files('/path/to/directory'); +``` + +## Architecture + +### Directory Structure + +``` +src/ +├── Application.php # Main application container +├── Bootloader.php # Application bootstrapper +├── Module.php # Base module class +├── Assets/ # Asset management system +│ ├── Manager.php # Asset manager +│ ├── Manifest.php # Asset manifest handler +│ ├── Bundle.php # Asset bundle handler +│ └── Asset/ # Asset types +├── Modules/ # Module system +│ ├── Manager.php # Module manager +│ └── Contracts/ # Module interfaces +├── Support/ # Support utilities +│ ├── Str.php # String utilities +│ └── Traits/ # Reusable traits +├── Utility/ # Utility classes +│ ├── Encryption.php # Encryption utilities +│ └── Hash.php # Hashing utilities +├── Config/ # Configuration management +├── Filesystem/ # Filesystem abstraction +└── Contracts/ # Framework interfaces +``` + +### Key Design Patterns + +- **Service Container**: Dependency injection and service resolution +- **Module Pattern**: Extensible, modular architecture +- **Manager Pattern**: Centralized management of resources +- **Factory Pattern**: Asset creation and instantiation +- **Strategy Pattern**: Pluggable encryption and hashing algorithms + +## Requirements + +- PHP 8.1 or higher +- WordPress 5.0 or higher +- Composer for dependency management + +## Dependencies + +- `psr/container`: PSR-11 container interface +- `phpunit/phpunit`: Testing framework (dev) +- `squizlabs/php_codesniffer`: Code quality (dev) +- `wp-coding-standards/wpcs`: WordPress coding standards (dev) + +## Development + +### Running Tests + +```bash +composer test +``` + +### Code Quality + +```bash +composer lint +composer lint:fix +``` + +### Coverage + +```bash +composer coverage +``` + +## Contributing + +1. Fork the repository +2. Create a feature branch +3. Make your changes +4. Add tests for new functionality +5. Ensure all tests pass +6. Submit a pull request + +## License + +This project is licensed under the GPL-3.0-or-later License - see the [LICENSE.md](LICENSE.md) file for details. + +## Credits + +- **Author**: Henrik Liebel (Webshore) +- **Inspired by**: Laravel Framework, Roots Acorn +- **Website**: [webshore.eu](https://webshore.eu/) + +## Support + +For support and questions, please visit the [project repository](https://git.webshore.io/Webshr/Core) or contact [mail@henrikliebel.com](mailto:mail@henrikliebel.com). diff --git a/bin/core b/bin/core new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fccc802 --- /dev/null +++ b/composer.json @@ -0,0 +1,58 @@ +{ + "name": "webshr/core", + "license": "GPL-3.0-or-later", + "description": "Framework for WordPress projects.", + "homepage": "https://webshore.eu/", + "authors": [ + { + "name": "Henrik Liebel", + "email": "mail@henrikliebel.com" + } + ], + "keywords": [ + "wordpress" + ], + "bin": [ + "bin/core" + ], + "support": {}, + "autoload": { + "psr-4": { + "Webshr\\Core\\": "src/" + }, + "files": [ + "src/helpers.php", + "src/globals.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Webshr\\Core\\Tests\\": "tests" + } + }, + "require": { + "php": ">=8.1", + "psr/container": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.5", + "squizlabs/php_codesniffer": "^3.12", + "wp-coding-standards/wpcs": "^3.1" + }, + "suggest": {}, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "lint": "pint --test", + "lint:fix": "pint", + "test": "pest", + "coverage": "XDEBUG_MODE=coverage pest --coverage --coverage-html=coverage" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..dbf601c --- /dev/null +++ b/composer.lock @@ -0,0 +1,2165 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d68f471812def84430cf2bc1dddb58bd", + "packages": [ + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + } + ], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.2", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "^2.2", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "opensource@frenck.dev", + "homepage": "https://frenck.dev", + "role": "Open source developer" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "security": "https://github.com/PHPCSStandards/composer-installer/security/policy", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-07-17T20:45:56+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.13.4", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.4" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2025-08-01T08:46:24+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.6.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", + "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.1" + }, + "time": "2025-08-13T20:13:15+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/882b8c947ada27eb002870fe77fee9ce0a454cdb", + "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.1.2", + "squizlabs/php_codesniffer": "^3.13.4 || ^4.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T06:54:52+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", + "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.13.3 || ^4.0" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0 || ^3.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "phpcs4", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T00:00:03+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "10.1.16", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "7e308268858ed6baedc8704a304727d20bc07c77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77", + "reference": "7e308268858ed6baedc8704a304727d20bc07c77", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.19.1 || ^5.1.0", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.1.0", + "phpunit/php-text-template": "^3.0.1", + "sebastian/code-unit-reverse-lookup": "^3.0.0", + "sebastian/complexity": "^3.2.0", + "sebastian/environment": "^6.1.0", + "sebastian/lines-of-code": "^2.0.2", + "sebastian/version": "^4.0.1", + "theseer/tokenizer": "^1.2.3" + }, + "require-dev": { + "phpunit/phpunit": "^10.1" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.16" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-08-22T04:31:57+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "4.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c", + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-31T06:24:48+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:09+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-31T14:07:24+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:57:52+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "10.5.58", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "e24fb46da450d8e6a5788670513c1af1424f16ca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e24fb46da450d8e6a5788670513c1af1424f16ca", + "reference": "e24fb46da450d8e6a5788670513c1af1424f16ca", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.13.4", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.1.16", + "phpunit/php-file-iterator": "^4.1.0", + "phpunit/php-invoker": "^4.0.0", + "phpunit/php-text-template": "^3.0.1", + "phpunit/php-timer": "^6.0.0", + "sebastian/cli-parser": "^2.0.1", + "sebastian/code-unit": "^2.0.0", + "sebastian/comparator": "^5.0.4", + "sebastian/diff": "^5.1.1", + "sebastian/environment": "^6.1.0", + "sebastian/exporter": "^5.1.4", + "sebastian/global-state": "^6.0.2", + "sebastian/object-enumerator": "^5.0.0", + "sebastian/recursion-context": "^5.0.1", + "sebastian/type": "^4.0.0", + "sebastian/version": "^4.0.1" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.5-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.58" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2025-09-28T12:04:46+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084", + "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T07:12:49+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:43+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:15+00:00" + }, + { + "name": "sebastian/comparator", + "version": "5.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e8e53097718d2b53cfb2aa859b06a41abf58c62e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e8e53097718d2b53cfb2aa859b06a41abf58c62e", + "reference": "e8e53097718d2b53cfb2aa859b06a41abf58c62e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/diff": "^5.0", + "sebastian/exporter": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/comparator", + "type": "tidelift" + } + ], + "time": "2025-09-07T05:25:07+00:00" + }, + { + "name": "sebastian/complexity", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "68ff824baeae169ec9f2137158ee529584553799" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799", + "reference": "68ff824baeae169ec9f2137158ee529584553799", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/3.2.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-21T08:37:17+00:00" + }, + { + "name": "sebastian/diff", + "version": "5.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e", + "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/process": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T07:15:17+00:00" + }, + { + "name": "sebastian/environment", + "version": "6.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984", + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.1.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-23T08:47:14+00:00" + }, + { + "name": "sebastian/exporter", + "version": "5.1.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "0735b90f4da94969541dac1da743446e276defa6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/0735b90f4da94969541dac1da743446e276defa6", + "reference": "0735b90f4da94969541dac1da743446e276defa6", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/exporter", + "type": "tidelift" + } + ], + "time": "2025-09-24T06:09:11+00:00" + }, + { + "name": "sebastian/global-state", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9", + "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "https://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T07:19:19+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0", + "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-21T08:38:20+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:32+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:18+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "47e34210757a2f37a97dcd207d032e1b01e64c7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/47e34210757a2f37a97dcd207d032e1b01e64c7a", + "reference": "47e34210757a2f37a97dcd207d032e1b01e64c7a", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "security": "https://github.com/sebastianbergmann/recursion-context/security/policy", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/recursion-context", + "type": "tidelift" + } + ], + "time": "2025-08-10T07:50:56+00:00" + }, + { + "name": "sebastian/type", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:10:45+00:00" + }, + { + "name": "sebastian/version", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-07T11:34:05+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.13.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/ad545ea9c1b7d270ce0fc9cbfb884161cd706119", + "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T05:47:09+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "d2421de7cec3274ae622c22c744de9a62c7925af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/d2421de7cec3274ae622c22c744de9a62c7925af", + "reference": "d2421de7cec3274ae622c22c744de9a62c7925af", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.4.0", + "phpcsstandards/phpcsutils": "^1.1.0", + "squizlabs/php_codesniffer": "^3.13.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/php_codesniffer", + "type": "custom" + } + ], + "time": "2025-07-24T20:08:31+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": {}, + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": ">=8.1" + }, + "platform-dev": {}, + "plugin-api-version": "2.6.0" +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..77b6e92 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,46 @@ + + + Custom coding standards for Webshr Core + + + ./vendor/* + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8552c89 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + ./tests + + + + + + + + + ./src + + + diff --git a/src/Application.php b/src/Application.php new file mode 100644 index 0000000..c3feb9c --- /dev/null +++ b/src/Application.php @@ -0,0 +1,935 @@ +use_encryption((array) $encryption); + } + + if ($base_path) { + $this->base_path = rtrim($base_path, '\/'); + } + + if ($paths) { + $this->use_paths((array) $paths); + } + + if ($default_manifest) { + $this->use_default_manifest((string) $default_manifest); + } + + if ($manifests) { + $this->use_manifests((array) $manifests); + } + + if ($modules) { + $this->use_modules((array) $modules); + } + + $this->register_core_bindings(); + $this->register_core_aliases(); + $this->register_core_encryption(); + $this->register_core_managers(); + $this->register_core_helpers(); + } + + /** + * Make a new theme instance. + * + * @codeCoverageIgnore + * @return static + */ + public function make($abstract, array $parameters = []) + { + return $this->resolve($abstract, $parameters); + } + + /** + * Set the Application instance. + * + * @param Application $instance + */ + public static function set_instance(Application $instance): void + { + static::$instance = $instance; + } + + /** + * Get the globally available instance of the theme. + * + * @return static + */ + public static function get_instance() + { + if (is_null(static::$instance)) { + static::$instance = new static(); + } + + return static::$instance; + } + + /** + * Boot the application's modules. + * + * @return void + */ + public function boot() + { + if ($this->is_booted()) { + return; + } + + // Once the application has booted we will also fire some "booted" callbacks + // for any listeners that need to do work after this initial booting gets + // finished. This is useful when ordering the boot-up processes we run. + $this->fire_app_callbacks($this->booting_callbacks); + // Register assets + $this->register_assets_config(); + $this->register_modules(); + $this->boot_modules(); + $this->fire_app_callbacks($this->booted_callbacks); + $this->booted = true; + // Set the bootstrapped flag + $this->has_been_bootstrapped = true; + } + + /** + * Set the encryption configuration. + * + * @param array $encryption + * @return $this + */ + public function use_encryption(array $encryption) + { + if (isset($encryption['cipher'])) { + $this->instance('cipher', $encryption['cipher']); + } + + if (isset($encryption['key'])) { + $this->instance('key', $encryption['key']); + } + + if (isset($encryption['previous_keys'])) { + $this->instance('previous_keys', $encryption['previous_keys']); + } + + return $this; + } + + /** + * Set paths that are configurable by the developer. + * + * Supported path types: + * - app + * - bootstrap + * - config + * - lang + * - resources + * - storage + * - env + * + * @param array $path + * @return $this + */ + public function use_paths(array $paths) + { + $supported_paths = [ + 'base', + 'app', + 'config', + 'resources', + 'storage', + 'bootstrap', + 'env', + ]; + foreach ($paths as $path_type => $path) { + $path = rtrim($path, '\\/'); + if (! in_array($path_type, $supported_paths)) { + throw new \Exception("The {$path_type} path type is not supported."); + } + + $this->paths[$path_type] = $path; + } + + $this->bind_paths(); + return $this; + } + + /** + * Bind all of the application paths. + * + * @return void + */ + protected function bind_paths() + { + foreach ($this->paths as $key => $path) { + $this->instance("path.{$key}", $path); + } + + $this->use_lang_path(is_dir($directory = $this->paths['resources'] . '/lang') + ? $directory + : $this->paths['base'] . '/lang'); + } + + /** + * Set the default manifest + * + * @param string $manifest + * @return $this + */ + public function use_default_manifest(string $manifest) + { + if (! is_string($manifest)) { + throw new \Exception("The default manifest '{$manifest}' does not exist in the manifests array."); + } + $this->default_manifest = $manifest; + return $this; + } + + /** + * Set manifests types that are configurable by the developer. + * + * Supported manifest types: + * - path + * - url + * - assets + * - bundles + * + * @param array $manifests + * @return $this + */ + public function use_manifests(array $manifests) + { + $supported_manifest_keys = [ + 'path', + 'url', + 'assets', + 'bundles', + ]; + foreach ($manifests as $key => $manifest) { + foreach ($manifest as $manifest => $value) { + if (! in_array($manifest, $supported_manifest_keys)) { + throw new \Exception("The {$manifest} path type is not supported."); + } + + $this->manifests[$key][$manifest] = rtrim($value, '\\/'); + } + } + + return $this; + } + + /** + * Register assets + * + * @return void + */ + protected function register_assets_config() + { + if (! isset($this->assets_manager)) { + throw new \Exception("Assets manager is not initialized."); + } + + $this->register_default_manifest(); + $this->register_manifests(); + } + + /** + * Register the default manifest. + * + * @return void + */ + protected function register_default_manifest() + { + if (! isset($this->default_manifest)) { + throw new \Exception("Default manifest key '{$this->default_manifest}' is not set."); + } + + $key = $this->default_manifest; + $manifest = $this->manifests[$key]; + // Check if the default manifest is already bound + if (! isset($this->bindings['assets.manifest'])) { + // Set the default manifest instance + $manifest_instace = $this->assets_manager->manifest($key, $manifest); + // Bind the Manifest instance + $this->instance('assets.manifest', $manifest_instace); + } + } + + /** + * Register all manifests. + * + * @return void + */ + protected function register_manifests() + { + foreach ($this->manifests as $key => $manifest) { + $this->assets_manager->manifest($key, $manifest); + } + + $this->instance('assets', $this->assets_manager); + } + + /** + * Set the directory for the environment file. + * + * @param string $path + * @return $this + */ + public function use_environment_path($path) + { + $this->env_path = $path; + $this->instance('path.env', $path); + return $this; + } + + /** + * Set the language file directory. + * + * @param string $path + * @return $this + */ + public function use_lang_path($path) + { + $this->lang_path = $path; + $this->instance('path.lang', $path); + return $this; + } + + /** + * @inheritDoc + */ + public function assets_path($path = '') + { + return $this->join_paths($this->config_path, $path); + } + + /** + * @inheritDoc + */ + public function base_path($path = '') + { + return $this->join_paths($this->base_path, $path); + } + + /** + * @inheritDoc + */ + public function config_path($path = '') + { + return $this->join_paths($this->config_path, $path); + } + + /** + * @inheritDoc + */ + public function lang_path($path = '') + { + return $this->join_paths($this->config_path, $path); + } + + /** + * @inheritDoc + */ + public function manifest_path($path = '') + { + return $this->join_paths($this->config_path, $path); + } + + + /** + * Join the given paths together. + * + * @param string $base_path + * @param string $path + * @return string + */ + public function join_paths($base_path, $path = '') + { + return join_paths($base_path, $path); + } + + protected function register_core_encryption() + { + $this->instance('hash', new Hash()); + $this->instance('encryption', new Encryption($this)); + } + + /** + * Load global helper functions. + * + * @return void + */ + protected function register_core_helpers() + { + require_once __DIR__ . '/globals.php'; + require_once __DIR__ . '/helpers.php'; + } + + /** + * Register core bindings. + * + * @return void + */ + protected function register_core_bindings() + { + static::set_instance($this); + $this->instance('app', $this); + } + + /** + * Register core managers. + * + * @return void + */ + protected function register_core_managers() + { + $this->assets_manager = new Assets_Manager(); + $this->module_manager = new Modules_Manager(); + } + + /** + * Set the modules that are configurable by the developer. + * + * @param array $modules + * @return $this + */ + public function use_modules(array $modules) + { + foreach ($modules as $module_name => $module_class) { + if (! class_exists($module_class)) { + throw new \Exception("The module class {$module_class} does not exist."); + } + + $this->modules[$module_name] = $module_class; + } + + return $this; + } + + /** + * Register modules + * + * @return void + */ + protected function register_modules() + { + if (! isset($this->module_manager)) { + throw new \Exception("Modules manager is not initialized."); + } + + foreach ($this->modules as $key => $module) { + $this->module_manager->register($key, new $module()); + $this->registered_modules[$key] = $module; + } + } + + /** + * Register a module with the application. + * + * @param \Webshr\Core\Module|string $module + * @param bool $force + */ + public function boot_modules() + { + foreach ($this->module_manager->modules() as $key => $module) { + // Check if the module is already loaded + if (isset($this->loaded_modules[$key])) { + continue; + // Skip already loaded modules + } + + // Boot the module + $this->boot_module($module); + $this->loaded_modules[$key] = $module; + // Register the module if it can be registered + if ($module->can_register()) { + $module->register(); + } + + // If the application has already booted, call the boot method on the module + if ($this->is_booted()) { + $this->boot_module($module); + } + } + } + + /** + * Boot the given module. + * + * @param \Webshr\Core\Module $module + * @return void + */ + protected function boot_module(Module $module) + { + $module->call_booting_callbacks(); + if (method_exists($module, 'boot')) { + $this->call([$module, 'boot']); + } + + $module->call_booted_callbacks(); + } + + /** + * Get the registered service provider instance if it exists. + * + * @param \Webshr\Core\Module|string $module + * @return \Webshr\Core\Module|null + */ + public function get_module($module) + { + return array_values($this->get_modules($module))[0] ?? null; + } + + /** + * Get the registered service provider instances if any exist. + * + * @param \Webshr\Core\Module|string $module + * @return array + */ + public function get_modules($module) + { + $name = is_string($module) ? $module : get_class($module); + return Arriable::where($this->modules, fn($value) => $value instanceof $name); + } + + /** + * Resolve a module instance from the class name. + * + * @param string $module + * @return \Webshr\Core\Modules\Contracts\Module + */ + public function resolve_module($module) + { + return $this->module_manager->module($module); + } + + /** + * Mark the given module as registered. + * + * @param \Webshr\Core\Module $module + * @return void + */ + protected function mark_as_registered($module) + { + $this->modules[] = $module; + $this->loaded_modules[get_class($module)] = true; + } + + /** + * Register the core class aliases in the application. + * + * @return void + */ + protected function register_core_aliases() + { + $this->alias('app', self::class); + } + + /** + * Register a new boot listener. + * + * @param callable $callback + * @return void + */ + public function booting($callback) + { + $this->booting_callbacks[] = $callback; + } + + /** + * Register a new "booted" listener. + * + * @param callable $callback + * @return void + */ + public function booted($callback) + { + $this->booted_callbacks[] = $callback; + if ($this->is_booted()) { + $callback($this); + } + } + + /** + * Check if the application has been booted. + * + * This method returns the status of the application's boot process. + * + * @return bool True if the application is booted, false otherwise. + */ + public function is_booted() + { + return $this->booted; + } + + /** + * Call the booting callbacks for the application. + * + * @param callable[] $callbacks + * @return void + */ + protected function fire_app_callbacks(array &$callbacks) + { + $index = 0; + while ($index < count($callbacks)) { + $callbacks[$index]($this); + $index++; + } + } + + /** + * Determine if the application has been bootstrapped before. + * + * @return bool + */ + public function has_been_bootstrapped() + { + return $this->has_been_bootstrapped; + } + + /** + * Get an object or value from the application container. + * + * @param string $key + * @return mixed + */ + public function get(string $key) + { + return $this->bindings[$key] ?? null; + } + + /** + * Get all bindings. + * + * @return array + */ + public function bindings(): array + { + return $this->bindings; + } + + /** + * @inheritDoc + */ + public function version() + { + return self::VERSION; + } + + /** + * Bind a value or object to a key in the application container. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function instance(string $key, $value) + { + $this->bindings[$key] = $value; + } + + /** + * Register a shared binding in the application. + * + * @param string $abstract + * @param \Closure|string|null $concrete + * @return void + */ + public function singleton($abstract, $concrete = null) + { + // If no concrete implementation is provided, use the abstract as the concrete + if (is_null($concrete)) { + $concrete = $abstract; + } + + // Register a closure that resolves the singleton instance + $this->bindings[$abstract] = function () use ($abstract, $concrete) { + + // Check if the instance already exists + if (! isset($this->bindings["instances"][$abstract])) { + // Resolve the instance and store it + $this->bindings["instances"][$abstract] = $this->resolve($concrete); + } + + // Return the stored instance + return $this->bindings["instances"][$abstract]; + }; + } + + /** + * Call the given Closure / class@method and inject its dependencies. + * + * @param callable|string $callback + * @param array $parameters + * @param string|null $default_method + * @return mixed + */ + public function call($callback, array $parameters = [], $default_method = null) + { + if (is_string($callback)) { + // Handle the case where the callback is a string in the format 'Class@method' + if (strpos($callback, '@') !== false) { + list($class, $method) = explode('@', $callback); + $callback = [new $class(), $method]; + } elseif ($default_method) { + $callback = [new $callback(), $default_method]; + } else { + $callback = new $callback(); + } + } + + return call_user_func_array($callback, $parameters); + } + + /** + * Resolve a value or object from the application + * + * @param string $key The key to resolve. + * @param array $args The arguments to pass to the resolved service. + * @return mixed|null The resolved service or null if not found. + */ + public function resolve($abstract, $parameters = []): mixed + { + // Get the alias + if (! is_string($abstract)) { + return null; + } + + // Check if the binding exists + if (isset($this->bindings[$abstract])) { + $binding = $this->bindings[$abstract]; + // If the module is a class name (string), instantiate it + if (is_string($binding) && class_exists($binding)) { + return new $binding(); + // or resolve via a DI container if needed + } + + // If the module is a callable or has a callback, invoke it + if (is_callable($binding)) { + return call_user_func($binding); + } + + if (is_array($binding) && isset($binding['callback']) && is_callable($binding['callback'])) { + return call_user_func($binding['callback']); + } + // Otherwise, return the module directly + return $binding; + } + + return null; + // Return null if the service is not found + } + + /** + * Magic call method. + * + * Will proxy to the theme method $method, unless it is not available, in which case an exception will be thrown. + * + * @param string $method Template tag name. + * @param array $args Template tag arguments. + * @return mixed Template tag result, or null if theme method only outputs markup. + * + * @throws BadMethodCallException Thrown if the theme method does not exist. + */ + public function __call(string $method, array $args): mixed + { + $resolved = $this->resolve($method); + if (! $resolved) { + throw new BadMethodCallException(sprintf(__('The method %s does not exist.', 'webshr'), 'app()->' . $method . '()'),); + } + + // If the resolved service is an invokable object, call it + if (is_object($resolved) && is_callable($resolved)) { + return call_user_func_array($resolved, $args); + } + + // If the resolved service is an object (but not invokable), return the object itself + if (is_object($resolved)) { + return $resolved; + } + + // Otherwise, call the resolved service as a function + return call_user_func_array($resolved, $args); + } +} diff --git a/src/Assets/Asset/Asset.php b/src/Assets/Asset/Asset.php new file mode 100644 index 0000000..20dd801 --- /dev/null +++ b/src/Assets/Asset/Asset.php @@ -0,0 +1,226 @@ +path = $path; + $this->uri = $uri; + } + + /** {@inheritdoc} */ + public function uri(): string + { + return $this->uri; + } + + /** {@inheritdoc} */ + public function path(): string + { + return $this->path; + } + + /** {@inheritdoc} */ + public function exists(): bool + { + return file_exists($this->path()); + } + + /** {@inheritdoc} */ + public function contents(): string + { + if (! $this->exists()) { + return ''; + } + + return file_get_contents($this->path()); + } + + /** + * Get the relative path to the asset. + * + * @param string $basePath Base path to use for relative path. + */ + public function relative_path(string $basePath): string + { + $basePath = rtrim($basePath, '/\\') . '/'; + return (new Filesystem())->get_relative_path($basePath, $this->path()); + } + + /** + * Get the base64-encoded contents of the asset. + * + * @return string + */ + public function base64() + { + if ($this->base64) { + return $this->base64; + } + + return $this->base64 = base64_encode($this->contents()); + } + + /** + * Get data URL of asset. + * + * @param string $mediatype MIME content type + */ + public function data_url(?string $mediatype = null): string + { + if ($this->data_url) { + return $this->data_url; + } + + if (! $mediatype) { + $mediatype = $this->content_type(); + } + + return $this->data_url = "data:{$mediatype};base64,{$this->base64()}"; + } + + /** + * Get data URL of asset. + * + * @param string $mediatype MIME content type + */ + public function data_uri(?string $mediatype = null): string + { + return $this->data_url($mediatype); + } + + /** + * Get the MIME content type. + * + * @return string|false + */ + public function content_type() + { + if ($this->type) { + return $this->type; + } + + return $this->type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->path()); + } + + /** + * Get the MIME content type. + * + * @return string|false + */ + public function mime_type() + { + return $this->content_type(); + } + + /** + * Get SplFileInfo instance of asset. + * + * @return SplFileInfo + */ + public function file() + { + return new SplFileInfo($this->path()); + } + + /** {@inheritdoc} */ + public function raw(): mixed + { + if (!$this->exists()) { + return ''; + } + + // Start output buffering + ob_start(); + // Include the PHP file + include $this->path(); + // Get the contents of the buffer and clean it + $content = ob_get_clean(); + return $content; + } + + /** + * {@inheritDoc} + */ + public function version() + { + // + } + + /** + * {@inheritDoc} + */ + public function dependencies() + { + // + } + + /** + * {@inheritDoc} + */ + public function include() + { + if (!$this->exists()) { + return ''; + } + + return include $this->path(); + } + + /** {@inheritdoc} */ + public function __toString() + { + return $this->uri(); + } +} diff --git a/src/Assets/Asset/Json_Asset.php b/src/Assets/Asset/Json_Asset.php new file mode 100644 index 0000000..e91078b --- /dev/null +++ b/src/Assets/Asset/Json_Asset.php @@ -0,0 +1,45 @@ +to_array(), $options); + } + + /** + * {@inheritdoc} + */ + public function to_array(): array + { + return (array) $this->decode(JSON_OBJECT_AS_ARRAY); + } + + /** + * Decode JSON data. + * + * @param int $options + * @param int $depth + * @return array|null + */ + public function decode($options = 0, $depth = 512) + { + return json_decode($this->contents(), null, $depth, $options); + } +} diff --git a/src/Assets/Asset/Meta_Asset.php b/src/Assets/Asset/Meta_Asset.php new file mode 100644 index 0000000..7c63200 --- /dev/null +++ b/src/Assets/Asset/Meta_Asset.php @@ -0,0 +1,66 @@ +contents = $this->include_once(); + $this->version = $this->contents['version'] ?? ''; + $this->dependencies = $this->contents['dependencies'] ?? []; + } + + /** + * Get the asset version. + * + * @return string + */ + public function version() + { + return $this->version; + } + + /** + * Get the asset dependencies. + * + * @return string + */ + public function dependencies(): string + { + return json_encode($this->dependencies); + } +} diff --git a/src/Assets/Asset/Php_Asset.php b/src/Assets/Asset/Php_Asset.php new file mode 100644 index 0000000..279c76d --- /dev/null +++ b/src/Assets/Asset/Php_Asset.php @@ -0,0 +1,72 @@ +assert_exists(); + return require_once $this->path(); + } + + /** + * Get the returned value of the asset + * + * @return mixed + */ + public function require() + { + $this->assert_exists(); + return require $this->path(); + } + + /** + * Get the returned value of the asset + * + * @return mixed + */ + public function include_once() + { + $this->assert_exists(); + return include_once $this->path(); + } + + /** + * Get the returned value of the asset + * + * @return mixed + */ + public function include() + { + $this->assert_exists(); + return include $this->path(); + } + + /** + * Assert that the asset exists. + * + * @throws \Webshr\Core\Filesystem\Exceptions\File_Not_Found_Exception + */ + protected function assert_exists() + { + if (! $this->exists()) { + throw new File_Not_Found_Exception("Asset [{$this->path()}] not found."); + } + } +} diff --git a/src/Assets/Asset/Svg_Asset.php b/src/Assets/Asset/Svg_Asset.php new file mode 100644 index 0000000..3b9ac25 --- /dev/null +++ b/src/Assets/Asset/Svg_Asset.php @@ -0,0 +1,19 @@ +charset) { + return $this->charset; + } + + if (preg_match('//u', $this->contents())) { + return $this->charset = 'UTF-8'; + } + + if (function_exists('mb_detect_encoding')) { + return $this->charset = mb_detect_encoding($this->contents()) ?: $fallback; + } + + return $this->charset = $fallback; + } + + /** + * Get data URL of asset. + * + * @param string $mediatype MIME content type + * @param string $charset Character encoding + * @param string $urlencode List of characters to be percent-encoded + */ + public function data_url(?string $mediatype = null, ?string $charset = null, string $urlencode = '%\'"'): string + { + if ($this->data_url) { + return $this->data_url; + } + + if (! $mediatype) { + $mediatype = $this->content_type(); + } + + if (! strstr($mediatype, 'charset')) { + $mediatype .= ';charset=' . ($charset ?: $this->charset()); + } + + $percents = []; + foreach (preg_split('//u', $urlencode, -1, PREG_SPLIT_NO_EMPTY) as $char) { + $percents[$char] = rawurlencode($char); + } + + $data = strtr($this->contents(), $percents); + return $this->data_url = "data:{$mediatype},{$data}"; + } + + /** + * Get data URL of asset. + * + * @param string $mediatype MIME content type + * @param string $charset Character encoding + * @param string $urlencode List of characters to be percent-encoded + */ + public function data_uri(?string $mediatype = null, ?string $charset = null, string $urlencode = '%\'"'): string + { + return $this->data_url($mediatype, $charset, $urlencode); + } +} diff --git a/src/Assets/Asset_Factory.php b/src/Assets/Asset_Factory.php new file mode 100644 index 0000000..8e15249 --- /dev/null +++ b/src/Assets/Asset_Factory.php @@ -0,0 +1,98 @@ +path(), $asset->uri(), $type); + } + + /** + * Create Asset instance. + */ + protected static function create_asset(string $path, string $uri): Asset + { + return new Asset($path, $uri); + } + + /** + * Create Json_Asset instance. + */ + protected static function create_json_asset(string $path, string $uri): Json_Asset + { + return new Json_Asset($path, $uri); + } + + /** + * Create PHP_Asset instance. + */ + protected static function create_php_asset(string $path, string $uri): PHP_Asset + { + return new PHP_Asset($path, $uri); + } + + /** + * Create Meta_Asset instance. + */ + protected static function create_meta_asset(string $path, string $uri): Meta_Asset + { + return new Meta_Asset($path, $uri); + } + + /** + * Create Svg_Asset instance. + */ + protected static function create_svg_asset(string $path, string $uri): Svg_Asset + { + return new Svg_Asset($path, $uri); + } +} diff --git a/src/Assets/Bundle.php b/src/Assets/Bundle.php new file mode 100644 index 0000000..62ccbe5 --- /dev/null +++ b/src/Assets/Bundle.php @@ -0,0 +1,216 @@ +id = $id; + $this->path = $path; + $this->uri = $uri; + $this->bundle = $bundle + ['js' => [], 'mjs' => [], 'css' => []]; + $this->set_runtime(); + } + + /** + * Get CSS files in bundle. + * + * Optionally pass a function to execute on each CSS file. + * + * @return array|$this + */ + public function css(?callable $callable = null) + { + $styles = $this->conditional ? $this->bundle['css'] : []; + if (! $callable) { + return $styles; + } + + foreach ($styles as $handle => $src) { + $callable("{$this->id}/{$handle}", $this->get_url($src)); + } + + return $this; + } + + /** + * Get JS files in bundle. + * + * Optionally pass a function to execute on each JS file. + * + * @return array|$this + */ + public function js(?callable $callable = null) + { + $scripts = $this->conditional ? array_merge($this->bundle['js'], $this->bundle['mjs']) : []; + if (! $callable) { + return $scripts; + } + + foreach ($scripts as $handle => $src) { + if ($handle === 'runtime') { + continue; + } + $callable("{$this->id}/{$handle}", $this->get_url($src), $this->dependencies()); + } + + return $this; + } + + /** + * Get the bundle dependencies. + * + * @return array + */ + public function dependencies() + { + return $this->bundle['dependencies'] ?? []; + } + + /** + * Get the bundle runtime. + * + * @return string|null + */ + public function runtime() + { + return $this->runtime; + } + + /** + * Get bundle runtime contents. + * + * @return string|null + */ + public function runtime_source() + { + if (($runtime = $this->runtime()) === null) { + return null; + } + + if ($sauce = self::$runtimes[$runtime] ?? null) { + return $sauce; + } + + return self::$runtimes[$runtime] = file_get_contents("{$this->path}/{$runtime}"); + } + + /** + * Get the bundle URL. + * + * @return string + */ + protected function get_url(string $path) + { + if (parse_url($path, PHP_URL_HOST)) { + return $path; + } + + $path = ltrim($path, '/'); + $uri = rtrim($this->uri, '/'); + return "{$uri}/{$path}"; + } + + /** + * Set the bundle runtime. + * + * @return void + */ + protected function set_runtime() + { + if (Arriable::is_assoc($this->bundle['js'])) { + $this->runtime = $this->bundle['js']['runtime'] + ?? $this->bundle['js']["runtime~{$this->id}"] + ?? null; + unset($this->bundle['js']['runtime'], $this->bundle['js']["runtime~{$this->id}"]); + return; + } + + $this->runtime = $this->get_bundle_runtime() ?? $this->get_bundle_runtime('mjs'); + } + + /** + * Retrieve the runtime in a bundle. + * + * @return string|null + */ + protected function get_bundle_runtime(string $type = 'js') + { + if (! $this->bundle[$type]) { + return null; + } + + foreach ($this->bundle[$type] as $key => $value) { + if (! str_contains($value, 'runtime')) { + continue; + } + + unset($this->bundle[$type][$key]); + return $value; + } + + return null; + } +} diff --git a/src/Assets/Concerns/Conditional.php b/src/Assets/Concerns/Conditional.php new file mode 100644 index 0000000..2d22c8a --- /dev/null +++ b/src/Assets/Concerns/Conditional.php @@ -0,0 +1,38 @@ +conditional = is_callable($conditional) + ? call_user_func($conditional, $args) + : $conditional; + return $this; + } +} diff --git a/src/Assets/Concerns/Enqueuable.php b/src/Assets/Concerns/Enqueuable.php new file mode 100644 index 0000000..103231b --- /dev/null +++ b/src/Assets/Concerns/Enqueuable.php @@ -0,0 +1,252 @@ +css(function ($handle, $src) use (&$dependencies, $media) { + + wp_enqueue_style($handle, $src, $dependencies, null, $media); + $this->merge_dependencies($dependencies, [$handle]); + }); + return $this; + } + + /** + * Enqueue JS files in WordPress. + * + * @return $this + */ + public function enqueue_js(bool|array $args = true, array $dependencies = []) + { + $this->js(function ($handle, $src, $bundleDependencies) use (&$dependencies, $args) { + + $this->merge_dependencies($dependencies, $bundleDependencies); + wp_enqueue_script($handle, $src, $dependencies, null, $args); + $this->inline_runtime(); + $this->merge_dependencies($dependencies, [$handle]); + }); + return $this; + } + + /** + * Enqueue JS and CSS files in WordPress. + * + * @return $this + */ + public function enqueue() + { + return $this->enqueue_css()->enqueue_js(); + } + + /** + * Add CSS files as editor styles in WordPress. + * + * @return $this + */ + public function editor_styles() + { + $relative_path = (new Filesystem())->get_relative_path(Str::finish(get_theme_file_path(), '/'), $this->path); + $this->css(function ($handle, $src) use ($relative_path) { + + if (! Str::starts_with($src, $this->uri)) { + return add_editor_style($src); + } + + $style = Str::of($src) + ->after($this->uri) + ->ltrim('/') + ->start("{$relative_path}/") + ->to_string(); + add_editor_style($style); + }); + return $this; + } + + /** + * Dequeue CSS files in WordPress. + * + * @return $this + */ + public function dequeue_css() + { + $this->css(function ($handle) { + + wp_dequeue_style($handle); + }); + return $this; + } + + /** + * Dequeue JS files in WordPress. + * + * @return $this + */ + public function dequeue_js() + { + $this->js(function ($handle) { + + wp_dequeue_script($handle); + }); + return $this; + } + + /** + * Dequeue JS and CSS files in WordPress. + * + * @return $this + */ + public function dequeue() + { + return $this->dequeue_css()->dequeue_js(); + } + + /** + * Inline runtime.js in WordPress. + * + * @return $this + */ + public function inline_runtime() + { + if (! $runtime = $this->runtime()) { + return $this; + } + + if (isset(self::$inlined[$runtime])) { + return $this; + } + + if ($contents = $this->runtime_source()) { + $this->inline($contents, 'before'); + } + + self::$inlined[$runtime] = $contents; + return $this; + } + + /** + * Add an inline script before or after the bundle loads + * + * @param string $contents + * @param string $position + * @return $this + */ + public function inline($contents, $position = 'after') + { + if (! $handles = array_keys($this->js()->keys()->toArray())) { + return $this; + } + + $handle = "{$this->id}/" . ( + $position === 'after' + ? array_pop($handles) + : array_shift($handles) + ); + wp_add_inline_script($handle, $contents, $position); + return $this; + } + + /** + * Add localization data to be used by the bundle + * + * @param string $name + * @param array $object + * @return $this + */ + public function localize($name, $object) + { + if (! $handles = $this->js()->keys()->toArray()) { + return $this; + } + + $handle = "{$this->id}/{$handles[0]}"; + wp_localize_script($handle, $name, $object); + return $this; + } + + /** + * Add script translations to be used by the bundle + * + * @param string $domain + * @param string $path + * @return $this + */ + public function translate($domain = null, $path = null) + { + $domain ??= wp_get_theme()->get('TextDomain'); + $path ??= lang_path(); + $this->js()->keys()->each(function ($handle) use ($domain, $path) { + + wp_set_script_translations("{$this->id}/{$handle}", $domain, $path); + }); + return $this; + } + + /** + * Merge two or more arrays. + * + * @return void + */ + protected function merge_dependencies(array &$dependencies, array ...$moreDependencies) + { + $dependencies = array_unique(array_merge($dependencies, ...$moreDependencies)); + } + + /** + * Reset inlined sources. + * + * @internal + * + * @return void + */ + public static function reset_inlined_sources() + { + self::$inlined = []; + } +} diff --git a/src/Assets/Contracts/Asset.php b/src/Assets/Contracts/Asset.php new file mode 100644 index 0000000..82d530f --- /dev/null +++ b/src/Assets/Contracts/Asset.php @@ -0,0 +1,72 @@ +package = $package; + } + + /** + * Name of the module's package. + * + * @var string + */ + protected $package; + + /** + * Set the name of the module's package. + * + * @return void + */ + public function set_package(string $package) + { + $this->package = $package; + } + + /** + * Get the module's package. + * + * @return string + */ + public function package() + { + return $this->package; + } + + /** + * Report the exception. + * + * @return array + */ + public function context() + { + return [ + 'package' => $this->package(), + ]; + } +} diff --git a/src/Assets/Manager.php b/src/Assets/Manager.php new file mode 100644 index 0000000..85aa05e --- /dev/null +++ b/src/Assets/Manager.php @@ -0,0 +1,114 @@ +config = $config; + } + + /** + * Register the given manifest + * + * @param Manifest $manifest + * @return static + */ + public function register(string $name, Manifest_Interface $manifest): self + { + $this->manifests[$name] = $manifest; + return $this; + } + + /** + * Get a Manifest + */ + public function manifest(string $name, ?array $config = null): Manifest_Interface + { + $manifest = $this->manifests[$name] ?? $this->resolve($name, $config); + return $this->manifests[$name] = $manifest; + } + + /** + * Resolve the given manifest. + * + * + * @throws InvalidArgumentException + */ + protected function resolve(string $name, ?array $config): Manifest_Interface + { + $config = $config ?? $this->get_config($name); + if (isset($config['handler'])) { + return new $config['handler']($config); + } + + $path = $config['path']; + $url = $config['url']; + $assets = isset($config['assets']) ? $this->get_json_manifest($config['assets']) : []; + $bundles = isset($config['bundles']) ? $this->get_json_manifest($config['bundles']) : []; + return new Manifest($path, $url, $assets, $bundles); + } + + + /** + * Opens a JSON manifest file from the local file system + * + * @param string $json_manifest Path to .json file + */ + protected function get_json_manifest(string $json_manifest): array + { + if (! file_exists($json_manifest)) { + throw new Manifest_Not_Found_Exception("The asset manifest [{$json_manifest}] cannot be found."); + } + + return json_decode(file_get_contents($json_manifest), true) ?? []; + } + + /** + * Get the assets manifest configuration. + */ + protected function get_config(string $name): array + { + return $this->config['manifests'][$name]; + } +} diff --git a/src/Assets/Manifest.php b/src/Assets/Manifest.php new file mode 100644 index 0000000..2552f5f --- /dev/null +++ b/src/Assets/Manifest.php @@ -0,0 +1,150 @@ +path = $path; + $this->uri = $uri; + $this->bundles = $bundles; + $this->metas = $metas; + foreach ($assets as $original => $revved) { + $this->assets[$this->normalize_relative_path($original)] = $this->normalize_relative_path($revved); + } + } + + /** + * Get specified asset. + * + * @param string $key + */ + public function asset($key): Asset_Interface + { + $key = $this->normalize_relative_path($key); + $relativePath = $this->assets[$key] ?? $key; + $path = Str::before("{$this->path}/{$relativePath}", '?'); + $uri = "{$this->uri}/{$relativePath}"; + return Asset_Factory::create($path, $uri); + } + + /** + * Get specified asset. + * + * @param string $key + */ + public function php($key) + { + $key = $this->normalize_relative_path($key); + $relativePath = $this->assets[$key] ?? $key; + $path = Str::before("{$this->path}/{$relativePath}", '?'); + $uri = "{$this->uri}/{$relativePath}"; + return Asset_Factory::create($path, $uri, 'php'); + } + + /** + * Get specified meta asset. + * + * @param string $key + */ + public function meta($key): Asset_Meta_Interface + { + $key = $this->normalize_relative_path($key); + // Check if the meta asset is already cached + if (isset($this->metas[$key])) { + return $this->metas[$key]; + } + + $relativePath = $this->assets[$key] ?? $key; + $path = Str::before("{$this->path}/{$relativePath}", '?'); + $uri = "{$this->uri}/{$relativePath}"; + if (! isset($this->metas[$key])) { + $meta = Asset_Factory::create($path, $uri, 'meta'); + } else { + $meta = new Meta($key, $this->metas[$key], $this->path, $this->uri); + } + + // Cache the created meta asset + $this->metas[$key] = $meta; + return $meta; + } + + /** + * Get specified bundles. + * + * @param string $key + * + * @throws \Webshr\Core\Assets\Exceptions\Bundle_Not_Found_Exception + */ + public function bundle($key): Bundle_Interface + { + if (! isset($this->bundles[$key])) { + throw new Bundle_Not_Found_Exception("Bundle [{$key}] not found in manifest."); + } + + return new Bundle($key, $this->bundles[$key], $this->path, $this->uri); + } + + /** + * Normalizes to forward slashes and removes leading slash. + */ + protected function normalize_relative_path(string $path): string + { + $path = str_replace('\\', '/', $path); + $path = preg_replace('%//+%', '/', $path); + return ltrim($path, './'); + } +} diff --git a/src/Assets/Meta.php b/src/Assets/Meta.php new file mode 100644 index 0000000..7fc34d4 --- /dev/null +++ b/src/Assets/Meta.php @@ -0,0 +1,75 @@ +id = $id; + $this->path = $path; + $this->uri = $uri; + $this->meta = $meta; + $this->dependencies(); + $this->version(); + } + + /** + * Get the meta dependencies. + * + * @return array + */ + public function version() + { + return $this->meta['version'] ?? ''; + } + + /** + * Get the meta dependencies. + * + * @return array + */ + public function dependencies() + { + return $this->meta['dependencies'] ?? []; + } +} diff --git a/src/Bootloader.php b/src/Bootloader.php new file mode 100644 index 0000000..fc3477e --- /dev/null +++ b/src/Bootloader.php @@ -0,0 +1,242 @@ +app = $app; + $this->files = $files ?? new Filesystem(); + // Load all configuration files into the repository + $this->config = new Repository($this->load_configuration_files()); + static::$instance ??= $this; + } + + /** + * Boot the Application. + * + * @return void + */ + public function __invoke(): void + { + $this->boot(); + } + + /** + * Set the Bootloader instance. + * + * @param \Webshr\Core\Bootloader|null $bootloader + * + * @return void + */ + public static function set_instance(?self $bootloader): void + { + static::$instance = $bootloader; + } + + /** + * Get the Bootloader instance. + * + * @param \Webshr\Core\Application|null $app + * + * @return \Webshr\Core\Bootloader + */ + public static function get_instance(?Application $app = null): static + { + return static::$instance ??= new static($app); + } + + /** + * Boot the Application. + * + * @param callable|null $callback + * + * @return void + */ + public function boot(?callable $callback = null): void + { + $this->get_application(); + if ($callback) { + $callback($this->app); + } + + if ($this->app->has_been_bootstrapped()) { + return; + } + + $this->app->boot(); + } + + /** + * Initialize and retrieve the Application instance. + * + * @return \Webshr\Core\Application + */ + public function get_application(): Application + { + $this->app ??= new Application($this->encryption(), $this->base_path(), $this->use_path()); + $this->app->use_environment_path($this->environment_path()); + $this->app->use_default_manifest($this->default_manifest()); + $this->app->use_manifests($this->manifests()); + $this->app->use_modules($this->modules()); + return $this->app; + } + + /** + * Load all configuration files. + * + * @return array + */ + protected function load_configuration_files(): array + { + $config_path = get_template_directory() . '/config'; + $config_files = $this->files->files($config_path); + $config = []; + foreach ($config_files as $file) { + $key = basename($file, '.php'); + $config[$key] = require $file; + } + + return $config; + } + + /** + * Get the application's encryption values. + * + * @return array + */ + protected function encryption(): array + { + $encryption = []; + $encryption['cipher'] = $this->config->get('app.cipher'); + $encryption['key'] = $this->config->get('app.key'); + $encryption['previous_keys'] = $this->config->get('app.previous_keys'); + return $encryption; + } + + /** + * Get the application's base path. + * + * @return string + */ + protected function base_path(): string + { + return $this->config->get('app.paths.base'); + } + + /** + * Get the environment file path. + * + * @return string + */ + protected function environment_path(): string + { + return $this->config->get('app.paths.env'); + } + + /** + * Use paths that are configurable by the developer. + * + * @return array + */ + protected function use_path(): array + { + return $this->config->get('app.paths'); + } + + /** + * Get the default manifest name. + * + * @return string + */ + protected function default_manifest(): string + { + return $this->config->get('assets.default'); + } + + /** + * Get the application's manifests. + * + * @return array + */ + protected function manifests(): array + { + return $this->config->get('assets.manifests'); + } + + /** + * Get the application's modules + * + * @return array + */ + protected function modules(): array + { + return $this->config->get('app.modules'); + } + + /** + * Get the application's aliases. + * + * @return array + */ + protected function aliases(): array + { + return $this->config->get('app.aliases'); + } +} diff --git a/src/Config/Environment.php b/src/Config/Environment.php new file mode 100644 index 0000000..992894a --- /dev/null +++ b/src/Config/Environment.php @@ -0,0 +1,109 @@ + 1 && $value[0] === '"' && $value[($valueLength - 1)] === '"') { + return substr($value, 1, -1); + } + + return $value; + } + + /** + * Get the value of a required environment variable. + * + * @param string $key + * @return mixed + * + * @throws \RuntimeException + */ + public static function get_or_fail($key) + { + $value = static::get($key); + + if (is_null($value)) { + throw new RuntimeException("Environment variable [{$key}] has no value."); + } + + return $value; + } + + /** + * Check if an environment variable exists. + * + * @param string $key + * @return bool + */ + public static function has($key) + { + return getenv($key) !== false; + } + + /** + * Set an environment variable. + * + * @param string $key + * @param mixed $value + * @return bool + */ + public static function set($key, $value) + { + return putenv("{$key}={$value}"); + } + + /** + * Get all environment variables. + * + * @return array + */ + public static function all() + { + return getenv(); + } +} diff --git a/src/Config/Repository.php b/src/Config/Repository.php new file mode 100644 index 0000000..deb27d9 --- /dev/null +++ b/src/Config/Repository.php @@ -0,0 +1,189 @@ +items = $items; + } + + /** + * Determine if the given configuration value exists. + * + * @param string $key + * @return bool + */ + public function has($key) + { + return Arriable::has($this->items, $key); + } + + /** + * Get the specified configuration value. + * + * @param array|string $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + if (is_array($key)) { + return $this->get_many($key); + } + + return Arriable::get($this->items, $key, $default); + } + + /** + * Get many configuration values. + * + * @param array $keys + * @return array + */ + public function get_many($keys) + { + $config = []; + foreach ($keys as $key => $default) { + if (is_numeric($key)) { + [$key, $default] = [$default, null]; + } + + $config[$key] = Arriable::get($this->items, $key, $default); + } + + return $config; + } + + /** + * Set a given configuration value. + * + * @param array|string $key + * @param mixed $value + * @return void + */ + public function set($key, $value = null) + { + $keys = is_array($key) ? $key : [$key => $value]; + foreach ($keys as $key => $value) { + Arriable::set($this->items, $key, $value); + } + } + + /** + * Prepend a value onto an array configuration value. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function prepend($key, $value) + { + $array = $this->get($key, []); + array_unshift($array, $value); + $this->set($key, $array); + } + + /** + * Push a value onto an array configuration value. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function push($key, $value) + { + $array = $this->get($key, []); + $array[] = $value; + $this->set($key, $array); + } + + /** + * Get all of the configuration items for the application. + * + * @return array + */ + public function all() + { + return $this->items; + } + + /** + * Determine if the given configuration option exists. + * + * @param string $key + * @return bool + */ + public function offsetExists($key): bool + { + return $this->has($key); + } + + /** + * Get a configuration option. + * + * @param string $key + * @return mixed + */ + public function offsetGet($key): mixed + { + return $this->get($key); + } + + /** + * Set a configuration option. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value): void + { + $this->set($key, $value); + } + + /** + * Unset a configuration option. + * + * @param string $key + * @return void + */ + public function offsetUnset($key): void + { + $this->set($key, null); + } +} diff --git a/src/Contracts/Application.php b/src/Contracts/Application.php new file mode 100644 index 0000000..3d6c2b9 --- /dev/null +++ b/src/Contracts/Application.php @@ -0,0 +1,87 @@ +is_readable($currentDirectory)) { + if ($this->is_file($filePath = $currentDirectory . DIRECTORY_SEPARATOR . $file)) { + return $filePath; + } + + $parentDirectory = $this->dirname($currentDirectory); + if (empty($parentDirectory) || $parentDirectory === $currentDirectory) { + break; + } + + $currentDirectory = $parentDirectory; + } + + return null; + } + + /** + * Get relative path of target from specified base + * + * @param string $base_path + * @param string $target_path + * @return string + * + * @copyright Fabien Potencier + * @license GPL-3.0-or-later + * + * @link https://github.com/symfony/routing/blob/v4.1.1/Generator/UrlGenerator.php#L280-L329 + */ + public function get_relative_path($base_path, $target_path) + { + $base_path = $this->normalize_path($base_path); + $target_path = $this->normalize_path($target_path); + if ($base_path === $target_path) { + return ''; + } + + $source_dirs = explode('/', ltrim($base_path, '/')); + $target_dirs = explode('/', ltrim($target_path, '/')); + array_pop($source_dirs); + $target_file = array_pop($target_dirs); + foreach ($source_dirs as $i => $dir) { + if (isset($target_dirs[$i]) && $dir === $target_dirs[$i]) { + unset($source_dirs[$i], $target_dirs[$i]); + } else { + break; + } + } + + $target_dirs[] = $target_file; + $path = str_repeat('../', count($source_dirs)) . implode('/', $target_dirs); + return $path === '' || $path[0] === '/' + || ($colon_pos = strpos($path, ':')) !== false && ($colon_pos < ($slash_pos = strpos($path, '/')) + || $slash_pos === false) + ? "./$path" : $path; + } + + /** + * Ensure a directory exists. + * + * @param string $path + * @param int $mode + * @param bool $recursive + * @return void + */ + public function ensure_directory_exists($path, $mode = 0755, $recursive = true) + { + if (! $this->is_directory($path)) { + $this->make_directory($path, $mode, $recursive); + } + } + + /** + * Create a directory. + * + * @param string $path + * @param int $mode + * @param bool $recursive + * @param bool $force + * @return bool + */ + public function make_directory($path, $mode = 0755, $recursive = false, $force = false) + { + if ($force) { + return @mkdir($path, $mode, $recursive); + } + + return mkdir($path, $mode, $recursive); + } + + /** + * Extract the parent directory from a file path. + * + * @param string $path + * @return string + */ + public function dirname($path) + { + return pathinfo($path, PATHINFO_DIRNAME); + } + + /** + * Determine if the given path is a directory. + * + * @param string $directory + * @return bool + */ + public function is_directory($directory) + { + return is_dir($directory); + } + + /** + * Get all files in a directory. + * + * @param string $directory + * @return array + */ + public function files(string $directory): array + { + return glob($directory . '/*.php'); + } + + /** + * Determine if the given path is a file. + * + * @param string $file + * @return bool + */ + public function is_file($file) + { + return is_file($file); + } + + /** + * Determine if the given path is readable. + * + * @param string $path + * @return bool + */ + public function is_readable($path) + { + return is_readable($path); + } +} diff --git a/src/Filesystem/Loader.php b/src/Filesystem/Loader.php new file mode 100644 index 0000000..f756ae0 --- /dev/null +++ b/src/Filesystem/Loader.php @@ -0,0 +1,97 @@ +isDot()) { + continue; + } + + $callback_result = call_user_func($callback, $file); + $output[] = $callback_result; + } + + return $output; + } + + /** + * Recursively require all files in a specific directory. + * + * By default, requires all php files in a specific directory once. + * Optionally able to specify the files in an array to load in a certain order. + * Starting and trailing slashes will be stripped for the directory and all files provided. + * + * @since 0.1.0 + * + * @param string $dir Directory to search through. + * @param array $files Optional array of files to include. If this is set, only the files specified will be loaded. + */ + public function load(string $dir, array $files = []): void + { + $dir = trim($dir, '/'); + if ($files === []) { + $dir = get_template_directory() . '/' . $dir; + $php_files = []; + $this->iterate_dir($dir, function ($file) use (&$php_files): void { + + if ($file->isDir()) { + $dir_path = trim(str_replace(get_template_directory(), '', $file->getPathname()), '/'); + $this->load($dir_path); + } elseif ($file->isFile() && $file->getExtension() === 'php') { + $file_path = $file->getPathname(); + $php_files[] = $file_path; + } + }); + // Sort files alphabetically. + sort($php_files); + foreach ($php_files as $php_file) { + require_once $php_file; + } + } else { + sort($files); + foreach ($files as $file) { + $file = $file ?? ''; + // Fix Passing null to parameter #1 ($string) of type string is deprecated error. + $file_path = $dir . '/' . ltrim($file, '/'); + if (locate_template($file_path, true, true) === '' || locate_template($file_path, true, true) === '0') { + trigger_error(sprintf(__('Error locating %s for inclusion', 'webshr'), $file_path), E_USER_ERROR,); + } + } + } + } +} diff --git a/src/Filesystem/functions.php b/src/Filesystem/functions.php new file mode 100644 index 0000000..8c75984 --- /dev/null +++ b/src/Filesystem/functions.php @@ -0,0 +1,25 @@ + $path) { + if (empty($path)) { + unset($paths[$index]); + } else { + $paths[$index] = DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR); + } + } + + return $base_path . implode('', $paths); + } +} diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 0000000..f0cc543 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,60 @@ +config = $config; + } + + /** + * Register the given module + * + * @param Module_Interface $module + * @return static + */ + public function register(string $name, Module_Interface $module): self + { + $this->modules[$name] = $module; + return $this; + } + + /** + * Get a Module + * + */ + public function module(string $name, ?array $config = null): Module_Interface + { + $module = $this->modules[$name] ?? $this->resolve($name, $config); + return $this->modules[$name] = $module; + } + + /** + * Get all modules. + */ + public function modules(): array + { + return $this->modules; + } + + /** + * Resolve the given module. + * + * @throws InvalidArgumentException + */ + protected function resolve(string $name, ?array $config): Module_Interface + { + $config = $config ?? $this->get_config($name); + + if (isset($config['handler'])) { + return new $config['handler']($config); + } + + // If there's no handler in the config, use the module class directly from the modules array + if (isset($this->config['modules'][$name])) { + $moduleClass = $this->config['modules'][$name]; + return new $moduleClass($this->app ?? null); + } + + throw new InvalidArgumentException("Module '{$name}' has no handler defined and could not be resolved."); + } + + /** + * Get the modules configuration. + */ + protected function get_config(string $name): array + { + return $this->config['modules'][$name]; + } +} diff --git a/src/Modules/Module/Module.php b/src/Modules/Module/Module.php new file mode 100644 index 0000000..89afdd0 --- /dev/null +++ b/src/Modules/Module/Module.php @@ -0,0 +1,155 @@ +app = $app; + } + + /** + * Checks whether the module should be registered in the current context. + * + * Must be implemented by the child module. + * + * @return bool + */ + abstract public function can_register(): bool; + /** + * Register the module in WordPress. + * + * Must be implemented by the child module. + * + * @return void + */ + abstract public function register(): void; + /** + * Register a booting callback to be run before the "boot" method is called. + * + * @param \Closure $callback + * @return void + */ + public function booting(Closure $callback) + { + $this->booting_callbacks[] = $callback; + } + + /** + * Register a booted callback to be run after the "boot" method is called. + * + * @param \Closure $callback + * @return void + */ + public function booted(Closure $callback) + { + $this->booted_callbacks[] = $callback; + } + + /** + * Call the registered booting callbacks. + * + * @return void + */ + public function call_booting_callbacks() + { + $index = 0; + while ($index < count($this->booting_callbacks)) { + $this->app->call($this->booting_callbacks[$index]); + $index++; + } + } + + /** + * Call the registered booted callbacks. + * + * @return void + */ + public function call_booted_callbacks() + { + $index = 0; + while ($index < count($this->booted_callbacks)) { + $this->app->call($this->booted_callbacks[$index]); + $index++; + } + } + + /** + * Get the services provided by the module. + * + * @return array + */ + public function provides() + { + return []; + } + + /** + * Get the events that trigger this module to register. + * + * @return array + */ + public function when() + { + return []; + } + + /** + * Determine if the module is deferred. + * + * @return bool + */ + public function is_deferred() + { + return $this instanceof Deferrable_Module_Interface; + } +} diff --git a/src/Modules/Module_Factory.php b/src/Modules/Module_Factory.php new file mode 100644 index 0000000..64005ab --- /dev/null +++ b/src/Modules/Module_Factory.php @@ -0,0 +1,35 @@ + $value) { + if (\is_array($value) && ! empty($value)) { + $results = \array_merge($results, static::dot($value, $prepend . $key . '.')); + } else { + $results[$prepend . $key] = $value; + } + } + + return $results; + } + + /** + * Get all of the given array except for a specified array of items. + * + * @param array $array + * @param array|string $keys + * @return array + */ + public static function except($array, $keys) + { + static::forget($array, $keys); + return $array; + } + + /** + * Determine if the given key exists in the provided array. + * + * @param array|ArrayAccess $array + * @param string|int $key + * @return bool + */ + public static function exists($array, $key) + { + if ($array instanceof ArrayAccess) { + return $array->offsetExists($key); + } + + return \array_key_exists($key, $array); + } + + /** + * Get the first element in an array passing a given truth test. + * + * @param array $array + * @param callable|null $callback + * @param mixed $default + * @return mixed + */ + public static function first($array, $callback = null, $default = null) + { + if (\is_null($callback)) { + if (empty($array)) { + return $default; + } + + foreach ($array as $item) { + return $item; + } + } + + foreach ($array as $key => $value) { + if (\call_user_func($callback, $value, $key)) { + return $value; + } + } + + return $default; + } + + /** + * Get the last element in an array passing a given truth test. + * + * @param array $array + * @param callable|null $callback + * @param mixed $default + * @return mixed + */ + public static function last($array, $callback = null, $default = null) + { + if (\is_null($callback)) { + return empty($array) ? $default : \end($array); + } + + return static::first(\array_reverse($array, true), $callback, $default); + } + + /** + * Remove one or many array items from a given array using "dot" notation. + * + * @param array $array + * @param array|string $keys + * @return void + */ + public static function forget(&$array, $keys) + { + $original = &$array; + $keys = (array) $keys; + if (\count($keys) === 0) { + return; + } + + foreach ($keys as $key) { + // if the exact key exists in the top-level, remove it + if (static::exists($array, $key)) { + unset($array[$key]); + continue; + } + + $parts = \explode('.', $key); + // clean up before each pass + $array = &$original; + while (\count($parts) > 1) { + $part = \array_shift($parts); + if (isset($array[$part]) && \is_array($array[$part])) { + $array = &$array[$part]; + } else { + continue 2; + } + } + + unset($array[\array_shift($parts)]); + } + } + + /** + * Get an item from an array using "dot" notation. + * + * @param array|ArrayAccess $array + * @param int|string $key + * @param mixed $default + * @return mixed + */ + public static function get($array, $key, $default = null) + { + if (! static::accessible($array)) { + return self::return_default($default); + } + + if (static::exists($array, $key)) { + return $array[$key]; + } + + $key = (string) $key; + if (false === strpos($key, '.')) { + return $array[$key] ?? self::return_default($default); + } + + foreach (\explode('.', $key) as $segment) { + if (static::accessible($array) && static::exists($array, $segment)) { + $array = $array[$segment]; + } else { + return self::return_default($default); + } + } + + return $array; + } + + /** + * Check if an item or items exist in an array using "dot" notation. + * + * @param array|ArrayAccess $array + * @param string|array $keys + * @return bool + */ + public static function has($array, $keys) + { + if (\is_null($keys)) { + return false; + } + + $keys = (array) $keys; + if (! $array) { + return false; + } + + if ($keys === []) { + return false; + } + + foreach ($keys as $key) { + $subKeyArray = $array; + if (static::exists($array, $key)) { + continue; + } + + foreach (\explode('.', $key) as $segment) { + if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { + $subKeyArray = $subKeyArray[$segment]; + } else { + return false; + } + } + } + + return true; + } + + /** + * Determines if an array is associative. + * + * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. + * + * @param array $array + * @return bool + */ + public static function is_assoc(array $array) + { + $keys = \array_keys($array); + return \array_keys($keys) !== $keys; + } + + /** + * Get a subset of the items from the given array. + * + * @param array $array + * @param array|string $keys + * @return array + */ + public static function only($array, $keys) + { + return \array_intersect_key($array, \array_flip((array) $keys)); + } + + /** + * Pluck an array of values from an array. + * + * @param array $array + * @param string|array $value + * @param string|array|null $key + * @return array + */ + public static function pluck($array, $value, $key = null) + { + $results = []; + list($value, $key) = static::exploded_pluck_parameters($value, $key); + foreach ($array as $item) { + $itemValue = static::data_get($item, $value); + // If the key is "null", we will just append the value to the array and keep + // looping. Otherwise we will key the array using the value of the key we + // received from the developer. Then we'll return the final array form. + if (\is_null($key)) { + $results[] = $itemValue; + } else { + $itemKey = static::data_get($item, $key); + $results[$itemKey] = $itemValue; + } + } + + return $results; + } + + /** + * Explode the "value" and "key" arguments passed to "pluck". + * + * @param string|array $value + * @param string|array|null $key + * @return array + */ + protected static function exploded_pluck_parameters($value, $key) + { + $value = \is_string($value) ? \explode('.', $value) : $value; + $key = \is_null($key) || \is_array($key) ? $key : \explode('.', $key); + return [$value, $key]; + } + + /** + * Push an item onto the beginning of an array. + * + * @param array $array + * @param mixed $value + * @param mixed $key + * @return array + */ + public static function prepend($array, $value, $key = null) + { + if (\is_null($key)) { + \array_unshift($array, $value); + } else { + $array = [$key => $value] + $array; + } + + return $array; + } + + /** + * Get a value from the array, and remove it. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + public static function pull(&$array, $key, $default = null) + { + $value = static::get($array, $key, $default); + static::forget($array, $key); + return $value; + } + + /** + * Set an array item to a given value using "dot" notation. + * + * If no key is given to the method, the entire array will be replaced. + * + * @param array $array + * @param string $key + * @param mixed $value + * @return array + */ + public static function set(&$array, $key, $value) + { + if (\is_null($key)) { + return $array = $value; + } + + $keys = \explode('.', $key); + while (\count($keys) > 1) { + $key = \array_shift($keys); + // If the key doesn't exist at this depth, we will just create an empty array + // to hold the next value, allowing us to create the arrays to hold final + // values at the correct depth. Then we'll keep digging into the array. + if (! isset($array[$key]) || ! \is_array($array[$key])) { + $array[$key] = []; + } + + $array = &$array[$key]; + } + + $array[\array_shift($keys)] = $value; + return $array; + } + + /** + * Shuffle the given array and return the result. + * + * @param array $array + * @return array + */ + public static function shuffle($array) + { + \shuffle($array); + return $array; + } + + /** + * Recursively sort an array by keys and values. + * + * @param array $array + * @return array + */ + public static function sort_recursive($array) + { + foreach ($array as &$value) { + if (\is_array($value)) { + $value = static::sort_recursive($value); + } + } + + if (static::is_assoc($array)) { + \ksort($array); + } else { + \sort($array); + } + + return $array; + } + + /** + * Get an item from an array or object using "dot" notation. + * + * @param mixed $target + * @param string|array $key + * @param mixed $default + * @return mixed + */ + public static function data_get($target, $key, $default = null) + { + if (\is_null($key)) { + return $target; + } + $key = \is_array($key) ? $key : \explode('.', $key); + while (! \is_null($segment = \array_shift($key))) { + if ($segment === '*') { + if (! \is_array($target)) { + return $default; + } + $result = static::pluck($target, $key); + return \in_array('*', $key) ? static::collapse($result) : $result; + } + if (static::accessible($target) && static::exists($target, $segment)) { + $target = $target[$segment]; + } elseif (\is_object($target) && isset($target->{$segment})) { + $target = $target->{$segment}; + } else { + return $default; + } + } + return $target; + } + + /** + * Filter the array using the given callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + public static function where($array, callable $callback) + { + return array_filter($array, $callback); + } + + /** + * Returns the default value. If the default value is a Closure, it executes the Closure and returns its result. + * + * @param mixed $default The default value or a Closure that returns the default value. + * @return mixed The default value or the result of the Closure execution. + */ + private static function return_default($default) + { + if ($default instanceof Closure) { + $default = $default(); + } + + return $default; + } +} diff --git a/src/Support/Contracts/Arrayable.php b/src/Support/Contracts/Arrayable.php new file mode 100644 index 0000000..8e04945 --- /dev/null +++ b/src/Support/Contracts/Arrayable.php @@ -0,0 +1,29 @@ + + */ + public function to_array(); +} diff --git a/src/Support/Contracts/Jsonable.php b/src/Support/Contracts/Jsonable.php new file mode 100644 index 0000000..053aa0f --- /dev/null +++ b/src/Support/Contracts/Jsonable.php @@ -0,0 +1,30 @@ + $substrings + * @return bool + */ + public static function starts_with(string $string, string $substrings): bool + { + if (! is_iterable($substrings)) { + $substrings = [$substrings]; + } + + foreach ($substrings as $substring) { + if ((string) $substring !== '' && str_starts_with($string, $substring)) { + return true; + } + } + + return false; + } + + /** + * Determine if a given string ends with a given substring. + * + * @param string $string The string to search in. + * @param string $substring The substring to search for. + * @return bool True if the subject ends with the substring, false otherwise. + */ + public static function ends_with(string $string, string $substring): bool + { + if ('' === $substring) { + return false; + } + + return substr($string, -strlen($substring)) === $substring; + } + + /** + * Determine if a given string does not end with a given substring. + * + * @param string $string The string to check. + * @param string $substring The substring to search for at the end of the subject string. + * @return bool True if the subject string does not end with the given substring, false otherwise. + */ + public static function does_not_end_with(string $string, string $substring): bool + { + return ! self::ends_with($string, $substring); + } + + /** + * Return the remainder of a string after the first occurrence of a given value. + * + * @param string $subject + * @param string $search + * @return string + */ + public static function after(string $subject, string $search): string + { + return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; + } + + /** + * Returns the portion of the string after the first occurrence of the given search string. + * + * @param string $string The input string. + * @param string $substring The string to search for. + * @return string The portion of the string after the first occurrence of the search string. + */ + public static function after_first(string $string, string $substring): string + { + return '' === $substring ? $string : array_reverse(explode($substring, $string, 2))[0]; + } + + /** + * Returns the portion of the string after the last occurrence of a given substring. + * + * @param string $string The string to search in. + * @param string $substring The substring to search for. + * @return string The portion of the string after the last occurrence of the substring. + * @throws RuntimeException If the substr function returns false. + */ + public static function after_last(string $string, string $substring): string + { + if ('' === $substring) { + return $string; + } + + $position = strrpos($string, $substring); + if (false === $position) { + return $string; + } + + $res = substr($string, $position + strlen($substring)); + if (false === $res) { + // @codeCoverageIgnoreStart + throw new RuntimeException(sprintf('substr returned false for subject [%s].', $string)); + // @codeCoverageIgnoreEnd + } + + return $res; + } + + /** + * Extracts the substring between the first occurrence of the given "from" and "to" strings. + * + * Usage: Str::between_first('xayyy', 'x', 'y') => 'a'. + * + * @param string $string The string to extract the substring from. + * @param string $from The starting delimiter string. + * @param string $to The ending delimiter string. + * @return string The extracted substring. If either "from" or "to" is an empty string, the original subject is returned. + */ + public static function between_first(string $string, string $from, string $to): string + { + if ('' === $from) { + return $string; + } + + if ('' === $to) { + return $string; + } + + return self::before_first(self::after_first($string, $from), $to); + } + + /** + * Extracts the substring between the last occurrence of the given "from" and "to" strings. + * + * Usage: Str::between_last('xayyy', 'x', 'y') => 'a'. + * + * @param string $string The input string from which to extract the substring. + * @param string $from The starting delimiter string. + * @param string $to The ending delimiter string. + * @return string The extracted substring, or the entire `$string` string if + * either `$from` or `$to` is empty. + */ + public static function between_last(string $string, string $from, string $to): string + { + if ('' === $from) { + return $string; + } + + if ('' === $to) { + return $string; + } + + return self::before_last(self::after_first($string, $from), $to); + } + + /** + * Returns the portion of the string before the first occurrence of the given search string. + * + * @param string $string The input string to search within. + * @param string $substring The string to search for. + * @return string The portion of the input string before the first occurrence of the search string, + * or the entire input string if the search string is not found or is empty. + */ + public static function before_first(string $string, string $substring): string + { + if ('' === $substring) { + return $string; + } + + $result = strstr($string, $substring, true); + return false === $result ? $string : $result; + } + + /** + * Returns the portion of the string before the last occurrence of the given substring. + * + * @param string $string The input string. + * @param string $substring The substring to search for. + * @return string The portion of the string before the last occurrence of the substring. + */ + public static function before_last(string $string, string $substring): string + { + if ('' === $substring) { + return $string; + } + + $pos = mb_strrpos($string, $substring); + if (false === $pos) { + return $string; + } + + return self::substr($string, 0, $pos); + } + + /** + * Returns the portion of the string specified by the start and length parameters. + * + * @param string $string The input string. + * @param int $start The starting position. + * @param int|null $length The length of the substring. If omitted, the substring will extend to the end of the string. + * @return string The extracted substring. + */ + public static function substr(string $string, int $start, int $length = null): string + { + return mb_substr($string, $start, $length, 'UTF-8'); + } + + /** + * Cap a string with a single instance of a given value. + * + * @param string $value + * @param string $cap + * @return string + */ + public static function finish(string $value, string $cap): string + { + $quoted = preg_quote($cap, '/'); + return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; + } + + /** + * Get a new stringable object from the given string. + * + * @param string $string + * @return \Webshr\Core\Support\Stringable + */ + public static function of(string $string): Stringable + { + return new Stringable($string); + } + + /** + * Determine if a given string matches a given pattern. + * + * This method checks if the given subject string matches the specified pattern. + * If the pattern is an exact match to the subject, it returns true immediately. + * Otherwise, it translates asterisks in the pattern into regular expression + * wildcards and performs a pattern match against the subject string. + * + * @param string $string The string to be checked. + * @param string $pattern The pattern to match against the subject. + * @return bool True if the subject matches the pattern, false otherwise. + */ + public static function is(string $string, string $pattern): bool + { + // If the given value is an exact match we can of course return true right + // from the beginning. Otherwise, we will translate asterisks and do an + // actual pattern match against the two strings to see if they match. + if ($pattern === $string) { + return true; + } + + $pattern = preg_quote($pattern, '#'); + // Asterisks are translated into zero-or-more regular expression wildcards + // to make it convenient to check if the strings starts with the given + // pattern such as "library/*", making any string check convenient. + $pattern = str_replace('\*', '.*', $pattern); + return 1 === preg_match('#^' . $pattern . '\z#u', $string); + } + + /** + * Replace all occurrences of a substring within a string with another string. + * + * @param string $string The string to search and replace within. + * @param string $substring The substring to search for. + * @param string $replace The string to replace the substring with. + * @return string The resulting string after the replacements. + */ + public static function replace_all(string $string, string $substring, string $replace): string + { + return str_replace($substring, $replace, $string); + } + + /** + * Remove all whitespace from both ends of a string. + * + * @param string $value + * @param string|null $charlist + * @return string + */ + public static function trim($value, $charlist = null) + { + if ($charlist === null) { + $trim_default_characters = " \n\r\t\v\0"; + + return preg_replace('~^[\s\x{FEFF}\x{200B}\x{200E}' . $trim_default_characters . ']+|[\s\x{FEFF}\x{200B}\x{200E}' . $trim_default_characters . ']+$~u', '', $value) ?? trim($value); + } + + return trim($value, $charlist); + } + + /** + * Remove all whitespace from the beginning of a string. + * + * @param string $value + * @param string|null $charlist + * @return string + */ + public static function ltrim($value, $charlist = null) + { + if ($charlist === null) { + $trim_default_characters = " \n\r\t\v\0"; + + return preg_replace('~^[\s\x{FEFF}\x{200B}\x{200E}' . $trim_default_characters . ']+~u', '', $value) ?? ltrim($value); + } + + return ltrim($value, $charlist); + } +} diff --git a/src/Support/Stringable.php b/src/Support/Stringable.php new file mode 100644 index 0000000..be841f4 --- /dev/null +++ b/src/Support/Stringable.php @@ -0,0 +1,110 @@ +value = (string) $value; + } + + /** + * Return the remainder of a string after the first occurrence of a given value. + * + * @param string $search + * @return static + */ + public function after($search) + { + return new static(Str::after($this->value, $search)); + } + + /** + * Return the remainder of a string after the last occurrence of a given value. + * + * @param string $search + * @return static + */ + public function after_last($search) + { + return new static(Str::after_last($this->value, $search)); + } + + /** + * Trim the string of the given characters. + * + * @param string $characters + * @return static + */ + public function trim($characters = null) + { + return new static(Str::trim(...array_merge([$this->value], func_get_args()))); + } + + /** + * Left trim the string of the given characters. + * + * @param string $characters + * @return static + */ + public function ltrim($characters = null) + { + return new static(Str::ltrim(...array_merge([$this->value], func_get_args()))); + } + + /** + * Begin a string with a single instance of a given value. + * + * @param string $prefix + * @return static + */ + public function start($prefix) + { + return new static(Str::start($this->value, $prefix)); + } + + /** + * Get the string value. + * + * @return string + */ + public function to_string() + { + return $this->value; + } + + /** + * Get the string value. + * + * @return string + */ + public function __toString() + { + return $this->value; + } +} diff --git a/src/Support/Traits/Aliases.php b/src/Support/Traits/Aliases.php new file mode 100644 index 0000000..b4ccfd4 --- /dev/null +++ b/src/Support/Traits/Aliases.php @@ -0,0 +1,123 @@ + + */ + protected $aliases = []; + + /** + * Get whether an alias is registered. + * + * @param string $alias + * @return boolean + */ + public function has_alias($alias) + { + return isset($this->aliases[$alias]); + } + + /** + * Get a registered alias. + * + * @param string $alias + * @return array|null + */ + public function get_alias($alias) + { + if (! $this->has_alias($alias)) { + return null; + } + + return $this->aliases[$alias]; + } + + /** + * Register an alias. + * Useful when passed the return value of getAlias() to restore + * a previously registered alias, for example. + * + * @param array $alias + * @return void + */ + public function set_alias($alias) + { + $name = Arriable::get($alias, 'name'); + + $this->aliases[$name] = [ + 'name' => $name, + 'target' => Arriable::get($alias, 'target'), + 'method' => Arriable::get($alias, 'method', ''), + ]; + } + + /** + * Register an alias. + * Identical to setAlias but with a more user-friendly interface. + * + * @codeCoverageIgnore + * @param string $alias + * @param string|Closure $target + * @param string $method + * @return void + */ + public function alias($alias, $target, $method = '') + { + $this->set_alias([ + 'name' => $alias, + 'target' => $target, + 'method' => $method, + ]); + } + + /** + * Call alias if registered. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if (! $this->has_alias($method)) { + throw new BadMethodCallException("Method {$method} does not exist."); + } + + $alias = $this->aliases[$method]; + + if ($alias['target'] instanceof Closure) { + return call_user_func_array($alias['target']->bindTo($this, static::class), $parameters); + } + + $target = $this->resolve($alias['target']); + + if (! empty($alias['method'])) { + return call_user_func_array([$target, $alias['method']], $parameters); + } + + return $target; + } + + /** + * Resolve a dependency from the IoC container. + * + * @param string $key + * @return mixed|null + */ + abstract public function resolve($key); +} diff --git a/src/Support/Traits/Application.php b/src/Support/Traits/Application.php new file mode 100644 index 0000000..82655df --- /dev/null +++ b/src/Support/Traits/Application.php @@ -0,0 +1,7 @@ +getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); + foreach ($methods as $method) { + if ($replace || ! static::has_macro($method->name)) { + static::macro($method->name, $method->invoke($mixin)); + } + } + } + + /** + * Checks if macro is registered. + * + * @param string $name + * @return bool + */ + public static function has_macro($name) + { + return isset(static::$macros[$name]); + } + + /** + * Flush the existing macros. + * + * @return void + */ + public static function flush_macros() + { + static::$macros = []; + } + + /** + * Dynamically handle calls to the class. + * + * @param string $method + * @param array $parameters + * @return mixed + * + * @throws \BadMethodCallException + */ + public static function __callStatic($method, $parameters) + { + if (! static::has_macro($method)) { + throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method,)); + } + + $macro = static::$macros[$method]; + if ($macro instanceof Closure) { + $macro = $macro->bindTo(null, static::class); + } + + return $macro(...$parameters); + } + + /** + * Dynamically handle calls to the class. + * + * @param string $method + * @param array $parameters + * @return mixed + * + * @throws \BadMethodCallException + */ + public function __call($method, $parameters) + { + if (! static::has_macro($method)) { + throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method,)); + } + + $macro = static::$macros[$method]; + if ($macro instanceof Closure) { + $macro = $macro->bindTo($this, static::class); + } + + return $macro(...$parameters); + } +} diff --git a/src/Utility/Contracts/Encrypter.php b/src/Utility/Contracts/Encrypter.php new file mode 100644 index 0000000..73f36f0 --- /dev/null +++ b/src/Utility/Contracts/Encrypter.php @@ -0,0 +1,55 @@ + ['size' => 16, 'aead' => false], + 'aes-256-cbc' => ['size' => 32, 'aead' => false], + 'aes-128-gcm' => ['size' => 16, 'aead' => true], + 'aes-256-gcm' => ['size' => 32, 'aead' => true], + ]; + /** + * Initialize the Encryption instance. + * + * @param Application_Interface $app + */ + public function __construct(Application_Interface $app) + { + $key = $app->get('key'); + $cipher = $app->get('cipher') ?? 'aes-256-cbc'; + // Ensure the key length matches the expected length for the cipher + $key = $this->ensure_key_length($key, $cipher); + if (! static::supported($key, $cipher)) { + $ciphers = implode(', ', array_keys(self::$supported_ciphers)); + throw new RuntimeException("Unsupported cipher or incorrect key length. Supported ciphers are: {$ciphers}."); + } + + $this->key = $key; + $this->cipher = $cipher; + } + + /** + * Ensure the key length matches the expected length for the cipher. + * + * @param string $key + * @param string $cipher + * @return string + */ + private function ensure_key_length(string $key, string $cipher): string + { + $expected_length = self::$supported_ciphers[strtolower($cipher)]['size']; + if (mb_strlen($key, '8bit') !== $expected_length) { + // Truncate or hash the key to the required length + $key = substr(hash('sha256', $key), 0, $expected_length); + } + return $key; + } + + /** + * Determine if the given key and cipher combination is valid. + * + * @param string $key + * @param string $cipher + * @return bool + */ + public static function supported($key, $cipher) + { + if (! isset(self::$supported_ciphers[strtolower($cipher)])) { + return false; + } + + return mb_strlen($key, '8bit') === self::$supported_ciphers[strtolower($cipher)]['size']; + } + + /** + * Create a new encryption key for the given cipher. + * + * @param string $cipher + * @return string + */ + public static function generate_key($cipher) + { + return random_bytes(self::$supported_ciphers[strtolower($cipher)]['size'] ?? 32); + } + + /** + * {@inheritDoc} + */ + public function encrypt(string $value, $serialize = true): string + { + if (! extension_loaded('openssl')) { + throw new Encrypt_Exception('The OpenSSL extension is not loaded.'); + } + + $iv = random_bytes(openssl_cipher_iv_length(strtolower($this->cipher))); + $value = \openssl_encrypt($serialize ? serialize($value) : $value, strtolower($this->cipher), $this->key, 0, $iv, $tag,); + if ($value === false) { + throw new Encrypt_Exception('Could not encrypt the data.'); + } + + $iv = base64_encode($iv); + $tag = base64_encode($tag ?? ''); + $mac = self::$supported_ciphers[strtolower($this->cipher)]['aead'] + ? '' // For AEAD-algorithms, the tag / MAC is returned by openssl_encrypt... + : $this->hash($iv, $value, $this->key); + $json = json_encode(compact('iv', 'value', 'mac', 'tag'), JSON_UNESCAPED_SLASHES); + if (json_last_error() !== JSON_ERROR_NONE) { + throw new RuntimeException('Could not encrypt the data.'); + } + + return base64_encode($json); + } + + /** + * {@inheritDoc} + */ + public function encrypt_string(string $value): string + { + return $this->encrypt($value, false); + } + + /** + * {@inheritDoc} + */ + public function decrypt(string $payload, bool $unserialize = true): string + { + $payload = $this->get_json_payload($payload); + $iv = base64_decode($payload['iv']); + $this->ensure_tag_is_valid($tag = empty($payload['tag']) ? null : base64_decode($payload['tag'])); + $found_valid_mac = false; + // Here we will decrypt the value. If we are able to successfully decrypt it + // we will then unserialize it and return it out to the caller. If we are + // unable to decrypt this value we will throw out an exception message. + foreach ($this->get_all_keys() as $key) { + if ( + $this->should_validate_mac() && + ! ($found_valid_mac = $found_valid_mac || $this->valid_mac_for_key($payload, $key)) + ) { + continue; + } + + $decrypted = \openssl_decrypt($payload['value'], strtolower($this->cipher), $key, 0, $iv, $tag ?? ''); + if ($decrypted !== false) { + break; + } + } + + if ($this->should_validate_mac() && ! $found_valid_mac) { + throw new Decrypt_Exception('The MAC is invalid.'); + } + + if (($decrypted ?? false) === false) { + throw new Decrypt_Exception('Could not decrypt the data.'); + } + + return $unserialize ? unserialize($decrypted) : $decrypted; + } + + /** + * {@inheritDoc} + */ + public function decrypt_string(string $payload): string + { + return $this->decrypt($payload, false); + } + + /** + * Create a MAC for the given value. + * + * @param string $iv + * @param mixed $value + * @param string $key + * @return string + */ + protected function hash(string $iv, mixed $value, string $key) + { + return hash_hmac('sha256', $iv . $value, $key); + } + + /** + * Get the JSON array from the given payload. + * + * @param string $payload + * @return array + * + * @throws Decrypt_Exception + */ + protected function get_json_payload(string $payload): array + { + if (! is_string($payload)) { + throw new Decrypt_Exception('The payload is invalid.'); + } + + $payload = json_decode(base64_decode($payload), true); + // If the payload is not valid JSON or does not have the proper keys set we will + // assume it is invalid and bail out of the routine since we will not be able + // to decrypt the given value. We'll also check the MAC for this encryption. + if (! $this->valid_payload($payload)) { + throw new Decrypt_Exception('The payload is invalid.'); + } + + return $payload; + } + + /** + * Verify that the encryption payload is valid. + * + * @param mixed $payload + * @return bool + */ + protected function valid_payload(mixed $payload): bool + { + if (! is_array($payload)) { + return false; + } + + foreach (['iv', 'value', 'mac'] as $item) { + if (! isset($payload[$item]) || ! is_string($payload[$item])) { + return false; + } + } + + if (isset($payload['tag']) && ! is_string($payload['tag'])) { + return false; + } + + return strlen(base64_decode($payload['iv'], true)) === openssl_cipher_iv_length(strtolower($this->cipher)); + } + + /** + * Determine if the MAC for the given payload is valid for the primary key. + * + * @param array $payload + * @return bool + */ + protected function valid_mac(array $payload): bool + { + return $this->valid_mac_for_key($payload, $this->key); + } + + /** + * Determine if the MAC is valid for the given payload and key. + * + * @param array $payload + * @param string $key + * @return bool + */ + protected function valid_mac_for_key(array $payload, string $key): bool + { + return hash_equals($this->hash($payload['iv'], $payload['value'], $key), $payload['mac'],); + } + + /** + * Ensure the given tag is a valid tag given the selected cipher. + * + * @param string $tag + * @return void + */ + protected function ensure_tag_is_valid($tag) + { + if (self::$supported_ciphers[strtolower($this->cipher)]['aead'] && strlen($tag) !== 16) { + throw new Decrypt_Exception('Could not decrypt the data.'); + } + + if (! self::$supported_ciphers[strtolower($this->cipher)]['aead'] && is_string($tag)) { + throw new Decrypt_Exception('Unable to use tag because the cipher algorithm does not support AEAD.'); + } + } + + /** + * Determine if we should validate the MAC while decrypting. + * + * @return bool + */ + protected function should_validate_mac() + { + return ! self::$supported_ciphers[strtolower($this->cipher)]['aead']; + } + + /** + * {@inheritDoc} + */ + public function get_key(): string + { + return $this->key; + } + + /** + * {@inheritDoc} + */ + public function get_all_keys(): array + { + return [$this->key, ...$this->previous_keys]; + } + + /** + * {@inheritDoc} + */ + public function get_previous_keys(): array + { + return $this->previous_keys; + } + + /** + * Set the previous / legacy encryption keys that should be utilized if decryption fails. + * + * @param array $keys + * @return $this + */ + public function previous_keys(array $keys) + { + foreach ($keys as $key) { + if (! static::supported($key, $this->cipher)) { + $ciphers = implode(', ', array_keys(self::$supported_ciphers)); + throw new RuntimeException("Unsupported cipher or incorrect key length. Supported ciphers are: {$ciphers}."); + } + } + + $this->previous_keys = $keys; + return $this; + } +} diff --git a/src/Utility/Exceptions/Decrypt_Exception.php b/src/Utility/Exceptions/Decrypt_Exception.php new file mode 100644 index 0000000..a87269b --- /dev/null +++ b/src/Utility/Exceptions/Decrypt_Exception.php @@ -0,0 +1,10 @@ +make($abstract, $parameters); + } +} + +if (! function_exists('lang_path')) { + /** + * Get the path to the language folder. + * + * @param string $path + * @return string + */ + function lang_path(string $path = '') + { + return app()->lang_path($path); + } +} + +if (! function_exists('app_public_path')) { + /** + * Get the path to the public folder. + * + * @param string $path + * @return string + */ + function app_public_path(string $path = '') + { + return app()->public_path($path); + } +} + +if (! function_exists('app_asset_path')) { + /** + * Generate an asset path for the application. + * + * @param string $path + * @param bool|null $secure + * @return string + */ + function app_asset_path(string $path, bool|null $secure = null) + { + return app('url')->asset($path, $secure); + } +} + +if (!function_exists('asset')) { + /** + * Get an asset instance and return the URL or other methods. + * + * @param string $path + * @param string|null $manifest + * @return Asset + */ + function asset(string $path, ?string $manifest = null): Asset + { + // Use the core `asset()` from the helpers file + return \Webshr\Core\asset($path, $manifest); + } +} + +if (!function_exists('bundle')) { + /** + * Get a bundle instance and return the methods. + * + * @param string $path + * @param string|null $manifest + * @return Bundle + */ + function bundle(string $path, ?string $manifest = null): Bundle + { + // Use the core `bundle()` from the helpers file + return \Webshr\Core\bundle($path, $manifest); + } +} + +if (! function_exists('module')) { + /** + * Return the given module + * + * @param string $path + * @param bool|null $secure + * @return string + */ + function module($name) + { + return app('modules')->module($name); + } +} + +/** Deprecated **/ +if (! function_exists('asset_content')) { + /** + * Get the asset file content. + * + * @param string $path + * @example '/icons/..svg' + * @return void + */ + + function asset_content(string $path): void + { + _doing_it_wrong('asset_content', 'This method has been deprecated in favor of asset()->contents', '0.2.0'); + echo asset($path)->contents(); + } +} + +if (! function_exists('asset_path')) { + /** + * Get the asset file path. + * + * @param string $path + * @example '/images/..img' + * @return string + */ + + function asset_path(string $path): string + { + _doing_it_wrong('asset_path', 'This method has been deprecated in favor of asset()->path', '0.2.0'); + return asset($path)->path(); + } +} + +if (! function_exists('asset_uri')) { + /** + * Get the asset file uri. + * + * @param string $path + * @example '/images/..img' + * @return string + */ + + function asset_uri(string $path): string + { + _doing_it_wrong('asset_uri', 'This method has been deprecated in favor of asset()->uri', '0.2.0'); + return asset($path)->uri(); + } +} diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..e83719f --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,310 @@ +get_application(); + + if ($app->has_been_bootstrapped()) { + return; + } + + \Webshr\Core\wp_die( + 'Webshr Core failed to boot. Run \\Webshr\\Core\\bootloader()->boot().

If you\'re using a Webshore Theme, you need to update webshr/functions.php:32', + '\\Webshr\\Core\\bootloader() was called incorrectly.', + 'Webshr Core › Boot Error', + 'Check out the release notes for more information.', + ); + }, 6); + + return $bootloader; +} + +/** + * Get the available theme instance. + * + * @param string|null $abstract + * @param array $parameters + * @return \Webshr\Core\Application|mixed + */ +function app($abstract = null, array $parameters = []) +{ + if (is_null($abstract)) { + return Application::get_instance(); + } + return Application::get_instance()->make($abstract, $parameters); +} + +/** + * Require files from a directory + * + * @param string|null $path + * @return void + */ +function require_files(string $dir = null): void +{ + $loader = new Loader(); + $loader->load($dir); +} + +/** + * Get asset from manifest + */ +function asset(string $asset, ?string $manifest = null): Asset +{ + if (! $manifest) { + return \app('assets.manifest')->asset($asset); + } + + return \app('assets')->manifest($manifest)->asset($asset); +} + +/** + * Get bundle from manifest + */ +function bundle(string $bundle, ?string $manifest = null): Bundle +{ + if (! $manifest) { + return \app('assets.manifest')->bundle($bundle); + } + + return \app('assets')->manifest($manifest)->bundle($bundle); +} + +/** + * Get asset meta from manifest + */ +function meta(string $asset, ?string $manifest = null): Asset_Meta +{ + if (! $manifest) { + return \app('assets.manifest')->meta($asset); + } else { + return \app('assets')->manifest($manifest)->meta($asset); + } +} + +/** + * Get module from manager + */ +function module(string $module): Module +{ + return \app()->module_manager->module($module); +} + +/** + * Encrypts the given data. + */ +function encrypt(string $data): string +{ + return \app('encryption')->encrypt($data); +} + +/** + * Encrypts the given string without serialization. + */ +function encrypt_string(string $data): string +{ + return \app('encryption')->encrypt_string($data); +} + +/** + * Decrypts the given data. + */ +function decrypt(string $payload): string +{ + return \app('encryption')->decrypt($payload); +} + +/** + * Decrypts the given string without unserialization. + */ +function decrypt_string(string $payload): string +{ + return \app('encryption')->decrypt_string($payload); +} + +/** + * Hashes the given data. + */ +function hash(string $data): string +{ + return \app('hash')->make($data); +} + +/** + * Checks the given data against the hash. + */ +function check(string $data, string $hash): bool +{ + return \app('hash')->check($data, $hash); +} + +/** + * Gets the value of an environment variable. + * + * @param string $key + * @param mixed $default + * @return mixed + * + * @copyright Taylor Otwell + * @license https://opensource.org/licenses/GPL-3.0-or-later GPL-3.0-or-later + * @link https://github.com/laravel/framework/blob/v5.6.25/src/Illuminate/Support/helpers.php#L597-L632 Original + * + * @deprecated use Webshr\Core\Config\Environment::get() instead + */ +function env($key, $default = null) +{ + if (class_exists(Environment::class)) { + return Environment::get($key, $default); + } + + $value = getenv($key); + if ($value === false) { + return value($default); + } + + switch (strtolower($value)) { + case 'true': + case '(true)': + return true; + + case 'false': + case '(false)': + return false; + + case 'empty': + case '(empty)': + return ''; + + case 'null': + case '(null)': + return; + } + + if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[($valueLength - 1)] === '"') { + return substr($value, 1, -1); + } + + return $value; +} + +/** + * Return the default value of the given value. + * + * @param mixed $value + * @return mixed + * + * @copyright Taylor Otwell + * @license https://opensource.org/licenses/GPL-3.0-or-later GPL-3.0-or-later + * @link https://github.com/laravel/framework/blob/v5.6.25/src/Illuminate/Support/helpers.php#L1143-L1152 Original + */ +function value($value) +{ + return $value instanceof \Closure ? $value() : $value; +} + +/** + * Bind single callback to multiple filters + * + * @param iterable $filters List of filters + * @param callable $callback + * @param integer $priority + * @param integer $args + * @return void + */ +function add_filters(iterable $filters, $callback, $priority = 10, $args = 2) +{ + $count = count($filters); + array_map( + '\add_filter', + (array) $filters, + array_fill(0, $count, $callback), + array_fill(0, $count, $priority), + array_fill(0, $count, $args), + ); +} + +/** + * Remove single callback from multiple filters + * + * @param iterable $filters List of filters + * @param callable $callback + * @param integer $priority + * @return void + */ +function remove_filters(iterable $filters, $callback, $priority = 10) +{ + $count = count($filters); + array_map( + '\remove_filter', + (array) $filters, + array_fill(0, $count, $callback), + array_fill(0, $count, $priority), + ); +} + +/** + * Alias of add_filters + * + * @see add_filters + * @param iterable $actions List of actions + * @param callable $callback + * @param integer $priority + * @param integer $args + * @return void + */ +function add_actions(iterable $actions, $callback, $priority = 10, $args = 2) +{ + add_filters($actions, $callback, $priority, $args); +} + +/** + * Alias of remove_filters + * + * @see remove_filters + * @param iterable $actions List of actions + * @param callable $callback + * @param integer $priority + * @return void + */ +function remove_actions(iterable $actions, $callback, $priority = 10) +{ + remove_filters($actions, $callback, $priority); +} + +/** + * Helper function for prettying up errors + * + * @param string $message + * @param string $subtitle + * @param string $title + * @param string $footer + */ +function wp_die($message, $subtitle = '', $title = '', $footer = '') +{ + $title = $title ?: __('WordPress › Error', 'webshr'); + $footer = $footer ?: 'Webshore'; + $message = "

{$title}
{$subtitle}

{$message}

{$footer}

"; + \wp_die($message, $title); +}