Compare commits

...

50 Commits

Author SHA1 Message Date
Simon Sessingø 45a5176b3c Merge pull request #416 from skipperbent/v4-development
Version 4.2.0.3
2018-04-22 05:37:29 +02:00
Simon Sessingø 2d042391aa Merge pull request #415 from skipperbent/v4-fix-input-all-empty
Fixed returning empty array when positing json (issue #413)
2018-04-22 05:36:10 +02:00
Simon Sessingo 4d842d0583 Fixed returning empty array when positing json (issue #413) 2018-04-22 05:35:15 +02:00
Simon Sessingø 9ccff91287 Merge pull request #410 from skipperbent/v4-development
Version 4.2.0.2
2018-04-06 19:45:51 +02:00
Simon Sessingø 8653bfa86f Development
- Fixed 403 not allowed exception is now thrown as NotFoundHttpException.
- Added REQUEST_TYPE_HEAD to Route class.
- Minor optimizations.
2018-04-06 19:44:30 +02:00
Simon Sessingø 13501b3f88 Merge pull request #408 from skipperbent/v4-development
Version 4.2.0.1
2018-04-06 18:04:01 +02:00
Simon Sessingø b8cfc4eb0b Fixed default parameter for all method allowed to by empty. 2018-04-06 18:01:49 +02:00
Simon Sessingø 5db4621831 Added methods for adding get, post and file parameters manually. 2018-04-06 18:00:59 +02:00
Simon Sessingø af641e3805 Merge pull request #406 from skipperbent/v4-development
Version 4.2.0.0
2018-04-06 17:27:42 +02:00
Simon Sessingø d38f81836d Development
- Added new Redirect method to SimpleRouter class.
- Changed method-names in InputHandler for better description.
- Fixed return-types for InputHandler for collections.
- Added unit-tests for InputHandler (get, post).
- Optimisations.
2018-04-06 17:20:00 +02:00
Simon Sessingø 89be00a72a Merge pull request #402 from skipperbent/v4-development
Version 4.1.0.0
2018-04-02 14:56:12 +02:00
Simon Sessingø 30a2ddeed9 Development
- Added new event when adding route.
- Added `prependUrl` method to `LoadableRoute` class.
- Added unit-test for add-route event.
- Updated documentation to reflect new changes.
2018-04-02 14:53:36 +02:00
Simon Sessingø 313833d78a Merge pull request #400 from skipperbent/v4-development
Fixed `exists` method in `InputHandler` returning incorrect value.
2018-04-01 04:28:06 +02:00
Simon Sessingø 17a7b28e82 Fixed exists method in InputHandler returning incorrect value. 2018-04-01 04:26:48 +02:00
Simon Sessingø e77d78e2f2 Merge pull request #399 from skipperbent/v4-development
Bugfixes and optimizations
2018-04-01 03:02:49 +02:00
Simon Sessingø 1dc88d23e1 Bugfixes and optimizations
- Fixed `hasParam` not working returning expected value in `Url` class.
- Chained the remaining methods in the `Url` class.
- Simplified `removeParam` method in `Url` class.
- Added new `removeParams` method to `Url` class for removal of multiple params.
2018-04-01 03:02:21 +02:00
Simon Sessingø bd033d9e13 Merge pull request #398 from skipperbent/v4-development
Version 4.0.0.11
2018-03-30 06:48:15 +02:00
Simon Sessingø 53f0b7d8e2 - Fixed getName method in LoadableRoute class can contain nullable value. 2018-03-30 06:47:27 +02:00
Simon Sessingø 5df0c12864 Updated helpers 2018-03-30 05:54:12 +02:00
Simon Sessingø 5bae3ff773 Merge pull request #397 from skipperbent/v4-development
Version 4.0.0.10
2018-03-30 05:38:27 +02:00
Simon Sessingø 833961ddc3 Fixed getError in InputFile returning string instead of int. 2018-03-30 05:37:04 +02:00
Simon Sessingø 36388f0f79 Merge pull request #396 from skipperbent/v4-development
Version 4.0.0.9
2018-03-30 05:23:54 +02:00
Simon Sessingø ce63e247b1 Bugfixes
- Fixed `Url` not outputting correct class when used in json_encode.
- Fixed `IInputItem` being too strict about strings which may be nullable.
2018-03-30 05:22:41 +02:00
Simon Sessingø d2d3938bf4 Merge pull request #395 from skipperbent/v4-development
Bugfixes
2018-03-29 23:48:32 +02:00
Simon Sessingø 80a42030ea Bugfixes
- Fixed getting specific input-value by request-method in InputHandler.
- Added .idea files
2018-03-29 23:47:27 +02:00
Simon Sessingø 1d6a2fafff Merge pull request #394 from skipperbent/v4-development
Removed namespace from groups
2018-03-29 23:28:47 +02:00
Simon Sessingø 17471a53cd Removed namespace from groups 2018-03-29 23:28:03 +02:00
Simon Sessingø e97e624cef Merge pull request #393 from skipperbent/v4-development
Bugfixes
2018-03-29 23:14:22 +02:00
Simon Sessingø da219d0b19 Bugfixes
- Fixed rewrite from ExceptionHandler sometimes not working correctly.
- Fixed default-namespace for Group and partial groups.
2018-03-29 23:13:56 +02:00
Simon Sessingø 30d2285699 Merge pull request #392 from skipperbent/v4-development
Bugfixes
2018-03-29 22:36:01 +02:00
Simon Sessingø a1dc4c5119 Bugfixes
- Updated `input` helper function.
- Update documentation to reflect v4 changes in `InputHandler` class.
2018-03-29 22:35:21 +02:00
Simon Sessingø 87e1fa3775 Merge pull request #391 from skipperbent/v4-development
Bugfixes
2018-03-29 22:18:26 +02:00
Simon Sessingø a11595fb86 Bugfixes
- Fixed `$methods` argument not properly passed in `InputHandler` class.
- Updated helpers.php with latest changes.
2018-03-29 22:17:53 +02:00
Simon Sessingø 555afd04f1 Merge pull request #390 from skipperbent/v4-development
Fixed defaultValue issue in `getValue` method in `InputHandler` class.
2018-03-29 21:45:26 +02:00
Simon Sessingø e6db83c97a Fixed defaultValue issue in getValue method in InputHandler class. 2018-03-29 21:44:41 +02:00
Simon Sessingø 32e5dd623c Merge pull request #389 from skipperbent/v4-development
Version 4.0.0.1
2018-03-29 21:26:37 +02:00
Simon Sessingø 8eded4a619 Updated documentation. 2018-03-29 21:19:52 +02:00
Simon Sessingø af2ac6031d Development
- Added dependency injection support.
- Added php-di composer dependency.
- Added `ClassLoader` class.
- Added `IClassLoader` interface.
- Added unit-tests for dependency injection.
- Updated documentation to reflect new features.
2018-03-29 21:16:02 +02:00
Simon Sessingø cca2f5cb88 Added donate option 2018-03-29 19:13:55 +02:00
Simon Sessingø 1a59a659fe Updated documentation 2018-03-29 19:02:31 +02:00
Simon Sessingø 4c61899560 Updated documentation 2018-03-29 19:00:18 +02:00
Simon Sessingø 931b50098c Updated documentation 2018-03-29 18:54:03 +02:00
Simon Sessingø f5a023117a Development
- Added event-arguments data.
- Added event-arguments to the event list in documentation.
- Fixed missing exceptions thrown in phpDocs.
- Added unit-tests for new event functionality.
2018-03-29 18:51:28 +02:00
Simon Sessingø a9c03f9271 Development
- Updated `helpers.php` and helpers example in documentation.
- MalformedUrlException is now handled properly by Router to avoid phpStorm syntax highlights in routes.
- Added `getUrlCopy` to `Request` class, used to clone the current route (to keep domain etc.)
- `setUrl` in `Request` are now strict and requires `Url` object and no longer accepts strings.
- Renamed `hasRewrite` property to `hasPendingRewrite` in `Request` class.
- Renamed `hasRewrite` and `setHasRewrite` methods to `hasPendingRewrite` and `setHasPendingRewrite` in `Request` class.
- Added better usage of `Url` class. When calling `url` you can now use the methods on the `Url` class to filter params, get relative/absolute url etc. See documentation for more info.
- Renamed `get` method to `getValue` in `InputHandler` class.
- Renamed `getObject` to `get` and removed `$defaultValue` argument in `InputHandler` class.
- Optimized `InputHandler` class.
- Fixed issue with `$token` not being proper string in `BaseCsrfVerifier` when token is not found.
- Added php.ini configuration settings to `setcookie` in `CookieTokenProvider` for improved security.
- Added `$router` parameter to `boot` method in `IRouterBootManager` which allows for further manipulation of the router within the bootmanager.
- Renamed `$processingRoute` property to `$isProcessingRoute` in `Router` class.
- Fixed `reset` method not resetting CSRF-verifier in `Router` class.
- Moved `arrayToParams` helper-method from `Router` to `Url` class.
- Began to add Event-functionality to router.
- Added `addEventHandler` method to `SimpleRouter` class.
- Moved `Pecee\SimpleRouter\Handler\CallbackExceptionHandler` to `Pecee\SimpleRouter\Handlers\CallbackExceptionHandler`.
- Moved `Pecee\SimpleRouter\Handler\IExceptionHandler` to `Pecee\SimpleRouter\Handlers\IExceptionHandler`.
- Added Events section to documentation.
- Added more information on url-handling in documentation.
- Optimisations.
2018-03-29 18:17:42 +02:00
Simon Sessingø aa56d45f9c Updated documentation 2018-03-29 10:13:23 +02:00
Simon Sessingø 9b175d5794 Merge pull request #388 from skipperbent/v4-development
Version 4.0.0.0
2018-03-27 01:13:25 +02:00
Simon Sessingø ef4582dbe0 Fixed wrong return-type in loadClass. 2018-03-27 01:11:44 +02:00
Simon Sessingø 54ae830ec8 Merge pull request #386 from skipperbent/v4-php7-port
Version 4
2018-03-26 23:57:54 +02:00
Simon Sessingø 085f98cf08 Development
- Better php7 support.
- Added easier way to debug router.
- Improvements and bugfixes.
- Updated documentation.
2018-03-26 23:43:27 +02:00
Simon Sessingø f23d569757 Added support for PHP7 2018-03-20 03:38:55 +01:00
90 changed files with 5006 additions and 1362 deletions
+22
View File
@@ -0,0 +1,22 @@
engines:
phpmd:
enabled: true
checks:
Design/TooManyPublicMethods:
enabled: true
Naming/ShortVariable:
enabled: true
CleanCode/StaticAccess:
enabled: true
Controversial/CamelCaseMethodName:
enabled: true
fixme:
enabled: true
duplication:
enabled: true
config:
languages:
- php:
ratings:
paths:
- src/**
+2 -2
View File
@@ -1,3 +1,3 @@
.idea
composer.lock
vendor/
vendor/
tests/tmp/*
+5
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Simon" />
</state>
</component>
+12
View File
@@ -0,0 +1,12 @@
<component name="ProjectDictionaryState">
<dictionary name="simon">
<words>
<w>bootmanager</w>
<w>bootmanagers</w>
<w>csrf</w>
<w>middlewares</w>
<w>pecee</w>
<w>urldecode</w>
</words>
</dictionary>
</component>
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.25" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true">
<PanelProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false">
<PegdownExtensions>
<option name="ABBREVIATIONS" value="false" />
<option name="ANCHORLINKS" value="true" />
<option name="ASIDE" value="false" />
<option name="ATXHEADERSPACE" value="true" />
<option name="AUTOLINKS" value="true" />
<option name="DEFINITIONS" value="false" />
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="FOOTNOTES" value="false" />
<option name="HARDWRAPS" value="false" />
<option name="HTML_DEEP_PARSER" value="false" />
<option name="INSERTED" value="false" />
<option name="QUOTES" value="false" />
<option name="RELAXEDHRULES" value="true" />
<option name="SMARTS" value="false" />
<option name="STRIKETHROUGH" value="true" />
<option name="SUBSCRIPT" value="false" />
<option name="SUPERSCRIPT" value="false" />
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
<option name="SUPPRESS_INLINE_HTML" value="false" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
<option name="TOC" value="false" />
<option name="WIKILINKS" value="true" />
</PegdownExtensions>
<ParserOptions>
<option name="COMMONMARK_LISTS" value="true" />
<option name="DUMMY" value="false" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="FLEXMARK_FRONT_MATTER" value="false" />
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="GITBOOK_URL_ENCODING" value="false" />
<option name="GITHUB_EMOJI_URL" value="false" />
<option name="GITHUB_LISTS" value="false" />
<option name="GITHUB_WIKI_LINKS" value="true" />
<option name="JEKYLL_FRONT_MATTER" value="false" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true">
<GeneratorProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
</CssSettings>
<HtmlExportSettings updateOnSave="false" parentDir="$ProjectFileDir$" targetDir="$ProjectFileDir$" cssDir="" scriptDir="" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetExt="" useTargetExt="false" noCssNoScripts="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>
+3
View File
@@ -0,0 +1,3 @@
<component name="MarkdownNavigator.ProfileManager">
<settings default="" pdf-export="" />
</component>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/simple-php-router.iml" filepath="$PROJECT_DIR$/.idea/simple-php-router.iml" />
</modules>
</component>
</project>
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpTestFrameworkVersionCache">
<tools_cache>
<tool tool_name="PHPUnit">
<cache>
<versions>
<info id="Local" version="6.5.7" />
</versions>
</cache>
</tool>
</tools_cache>
</component>
</project>
Generated
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit-mock-objects" />
<path value="$PROJECT_DIR$/vendor/sebastian/version" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-token-stream" />
<path value="$PROJECT_DIR$/vendor/sebastian/diff" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" />
<path value="$PROJECT_DIR$/vendor/sebastian/recursion-context" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
<path value="$PROJECT_DIR$/vendor/sebastian/exporter" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" />
<path value="$PROJECT_DIR$/vendor/sebastian/environment" />
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" />
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" />
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" />
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<path value="$PROJECT_DIR$/vendor/sebastian/object-reflector" />
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" />
<path value="$PROJECT_DIR$/vendor/hamcrest/hamcrest-php" />
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
<path value="$PROJECT_DIR$/vendor/phar-io/version" />
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" />
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" />
<path value="$PROJECT_DIR$/vendor/mockery/mockery" />
<path value="$PROJECT_DIR$/vendor/jeremeamia/SuperClosure" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-util" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php56" />
<path value="$PROJECT_DIR$/vendor/php-di/invoker" />
<path value="$PROJECT_DIR$/vendor/php-di/phpdoc-reader" />
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
<path value="$PROJECT_DIR$/vendor/psr/container" />
<path value="$PROJECT_DIR$/vendor/php-di/php-di" />
<path value="$PROJECT_DIR$/vendor/symfony/yaml" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings load_method="CUSTOM_LOADER" configuration_file_path="$PROJECT_DIR$/phpunit.xml" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" phpunit_phar_path="" use_configuration_file="true" />
</phpunit_settings>
</component>
</project>
+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/Pecee" isTestSource="false" packagePrefix="Pecee\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hamcrest/hamcrest-php" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jeremeamia/SuperClosure" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mockery/mockery" />
<excludeFolder url="file://$MODULE_DIR$/vendor/myclabs/deep-copy" />
<excludeFolder url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/manifest" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-di/invoker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-di/php-di" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-di/phpdoc-reader" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-common" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-docblock" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/type-resolver" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-code-coverage" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-file-iterator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-text-template" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-token-stream" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit-mock-objects" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/comparator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/environment" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/exporter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/global-state" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-enumerator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-reflector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/resource-operations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php56" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-util" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/yaml" />
<excludeFolder url="file://$MODULE_DIR$/vendor/theseer/tokenizer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+958
View File
@@ -0,0 +1,958 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BookmarkManager">
<bookmark url="file://$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php" line="221" />
</component>
<component name="ChangeListManager">
<list default="true" id="a7058529-bdc4-40b4-a50d-c50564dc83f0" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/php.xml" afterPath="$PROJECT_DIR$/.idea/php.xml" />
<change beforePath="$PROJECT_DIR$/.idea/simple-php-router.iml" afterPath="$PROJECT_DIR$/.idea/simple-php-router.iml" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php" afterPath="$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ComposerSettings" doNotAsk="true" synchronizationState="SYNCHRONIZE">
<pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath>
</component>
<component name="FavoritesManager">
<favorites_list name="simple-php-router" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
<file leaf-file-name="SimpleRouter.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/SimpleRouter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1275">
<caret line="100" column="16" lean-forward="false" selection-start-line="100" selection-start-column="8" selection-end-line="100" selection-end-column="16" />
<folding>
<element signature="e#302#319#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="LoadableRoute.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/LoadableRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1207">
<caret line="71" column="33" lean-forward="false" selection-start-line="71" selection-start-column="27" selection-end-line="71" selection-end-column="33" />
<folding>
<element signature="e#44#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="RouteResource.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteResource.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1598">
<caret line="94" column="116" lean-forward="false" selection-start-line="94" selection-start-column="116" selection-end-line="94" selection-end-column="116" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="RouteUrl.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteUrl.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="64" lean-forward="false" selection-start-line="16" selection-start-column="64" selection-end-line="16" selection-end-column="64" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="IRoute.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/IRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="16" column="20" lean-forward="false" selection-start-line="16" selection-start-column="20" selection-end-line="16" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Route.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/Route.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2261">
<caret line="133" column="43" lean-forward="false" selection-start-line="133" selection-start-column="43" selection-end-line="133" selection-end-column="43" />
<folding>
<element signature="e#44#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="InputHandler.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="299" column="30" lean-forward="false" selection-start-line="299" selection-start-column="30" selection-end-line="299" selection-end-column="30" />
<folding>
<element signature="e#36#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Router.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Router.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15181">
<caret line="893" column="20" lean-forward="false" selection-start-line="893" selection-start-column="20" selection-end-line="893" selection-end-column="20" />
<folding>
<element signature="e#38#84#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>-&gt;setUrl</find>
<find>EVENT_LOAD</find>
<find>addRoute</find>
<find>$this-&gt;isPro</find>
<find>7.2</find>
<find>options</find>
<find>parent::set</find>
<find>parseParameters</find>
<find>stripos</find>
<find>setPrefix</find>
<find>var_dum</find>
<find>parse</find>
<find>getParams</find>
<find>setQuery</find>
<find>contains</find>
<find>matchRoute</find>
<find>-&gt;getValue</find>
<find>-&gt;find</find>
<find />
<find>Req</find>
<find>value(</find>
<find>file(</find>
<find>setUrl</find>
<find>TODO</find>
<find>input()-&gt;get</find>
<find />
<find>REQUEST_TYPE_</find>
<find />
<find>setDebugEnabled</find>
<find>debugEnabled</find>
</findStrings>
<dirStrings>
<dir>D:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Route</dir>
<dir>D:\Workspace\simple-php-router\src</dir>
<dir>D:\Workspace\simple-php-router\tests\Pecee\SimpleRouter\Dummy</dir>
<dir>D:\Workspace\simple-php-router</dir>
<dir>E:\Workspace\simple-php-router\tests</dir>
<dir>E:\Workspace\simple-php-router\src\Pecee</dir>
<dir>E:\Workspace\simple-php-router\tests\Pecee\SimpleRouter</dir>
<dir>E:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Route</dir>
<dir>E:\Workspace\simple-php-router\src\Pecee\SimpleRouter</dir>
<dir>E:\Workspace\simple-php-router\src</dir>
<dir>E:\Workspace\simple-php-router</dir>
</dirStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/Dummy/Handler/ExceptionHandlerFirst.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/Dummy/Handler/ExceptionHandlerSecond.php" />
<option value="$PROJECT_DIR$/tests/TestRouter.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Event/IEventArgument.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/IRouterBootManager.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/Dummy/Security/SilentTokenProvider.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/Dummy/Managers/TestBootManager.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Security/CookieTokenProvider.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Security/ITokenProvider.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Response.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/IRoute.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RoutePartialGroup.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/IEventHandler.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Event/EventArgument.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/ClassHandler.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/ClassLoader.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/DIContainerBuilder.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/Containers/DIContainerBuilder.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/ContainerInterface.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/IContainer.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/IClassLoader.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php" />
<option value="$PROJECT_DIR$/composer.json" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/GroupTest.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterRouteTest.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/DependencyInjectionTest.php" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Input/IInputItem.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Input/InputItem.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Input/InputFile.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/EventHandlerTest.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/EventHandler.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteGroup.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteResource.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Url.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterUrlTest.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Middleware/BaseCsrfVerifier.php" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Request.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/LoadableRoute.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteController.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/ILoadableRoute.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteUrl.php" />
<option value="$PROJECT_DIR$/helpers.php" />
<option value="$PROJECT_DIR$/tests/Pecee/SimpleRouter/InputHandlerTest.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/Route.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/Router.php" />
<option value="$PROJECT_DIR$/src/Pecee/SimpleRouter/SimpleRouter.php" />
<option value="$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsFlowSettings">
<service-enabled>false</service-enabled>
<exe-path />
<annotation-enable>false</annotation-enable>
<other-services-enabled>false</other-services-enabled>
<auto-save>true</auto-save>
</component>
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP 7.2">
<include_path>
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit-mock-objects" />
<path value="$PROJECT_DIR$/vendor/sebastian/version" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-token-stream" />
<path value="$PROJECT_DIR$/vendor/sebastian/diff" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" />
<path value="$PROJECT_DIR$/vendor/sebastian/recursion-context" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
<path value="$PROJECT_DIR$/vendor/sebastian/exporter" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" />
<path value="$PROJECT_DIR$/vendor/sebastian/environment" />
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" />
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" />
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" />
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<path value="$PROJECT_DIR$/vendor/sebastian/object-reflector" />
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" />
<path value="$PROJECT_DIR$/vendor/hamcrest/hamcrest-php" />
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
<path value="$PROJECT_DIR$/vendor/phar-io/version" />
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" />
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" />
<path value="$PROJECT_DIR$/vendor/mockery/mockery" />
<path value="$PROJECT_DIR$/vendor/jeremeamia/SuperClosure" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-util" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php56" />
<path value="$PROJECT_DIR$/vendor/php-di/invoker" />
<path value="$PROJECT_DIR$/vendor/php-di/phpdoc-reader" />
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
<path value="$PROJECT_DIR$/vendor/psr/container" />
<path value="$PROJECT_DIR$/vendor/php-di/php-di" />
<path value="$PROJECT_DIR$/vendor/symfony/yaml" />
</include_path>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-10" />
<option name="width" value="2295" />
<option name="height" value="1235" />
</component>
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Http" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Http" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Input" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="SimpleRouter" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="SimpleRouter" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="ClassLoader" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="SimpleRouter" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Handlers" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="src" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="SimpleRouter" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Route" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="tests" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="tests" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
<path>
<item name="simple-php-router" type="b2602c69:ProjectViewProjectNode" />
<item name="simple-php-router" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="tests" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="Pecee" type="2a2b976b:PhpTreeStructureProvider$1" />
<item name="SimpleRouter" type="2a2b976b:PhpTreeStructureProvider$1" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../ninjaimg-service" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.standard" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.standard" value="project" />
<property name="node.js.selected.package.eslint" value="" />
<property name="node.js.selected.package.standard" value="" />
<property name="run.code.analysis.last.selected.profile" value="pProject Default" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="E:\Workspace\simple-php-router\tests\Pecee\SimpleRouter" />
<recent name="D:\Workspace\simple-php-router\tests" />
<recent name="D:\Workspace\simple-php-router" />
<recent name="D:\Workspace\simple-php-router\test" />
<recent name="D:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Route" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="E:\Workspace\simple-php-router\src\Pecee\SimpleRouter\ClassLoader\Containers" />
<recent name="E:\Workspace\simple-php-router\src\Pecee\SimpleRouter\ClassLoader" />
<recent name="E:\Workspace\simple-php-router\src\Pecee\SimpleRouter" />
<recent name="E:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Handler" />
<recent name="D:\Workspace\simple-php-router\tests" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="PHPUnit.phpunit.xml">
<configuration name="EventHandlerTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
<TestRunner class="EventHandlerTest" file="$PROJECT_DIR$/tests/Pecee/SimpleRouter/EventHandlerTest.php" scope="Class" />
</configuration>
<configuration name="RouterUrlTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
<TestRunner class="RouterUrlTest" file="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterUrlTest.php" scope="Class" />
</configuration>
<configuration name="phpunit.xml" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" scope="XML" use_alternative_configuration_file="true" />
</configuration>
<configuration name="tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
<TestRunner directory="$PROJECT_DIR$/tests" />
</configuration>
<configuration name="debug.php" type="PhpLocalRunConfigurationType" factoryName="PHP Console" temporary="true" path="$PROJECT_DIR$/tests/debug.php" />
<list size="5">
<item index="0" class="java.lang.String" itemvalue="PHPUnit.tests" />
<item index="1" class="java.lang.String" itemvalue="PHPUnit.RouterUrlTest" />
<item index="2" class="java.lang.String" itemvalue="PHPUnit.phpunit.xml" />
<item index="3" class="java.lang.String" itemvalue="PHP Script.debug.php" />
<item index="4" class="java.lang.String" itemvalue="PHPUnit.EventHandlerTest" />
</list>
<recent_temporary>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="PHPUnit.phpunit.xml" />
<item index="1" class="java.lang.String" itemvalue="PHP Script.debug.php" />
<item index="2" class="java.lang.String" itemvalue="PHPUnit.EventHandlerTest" />
<item index="3" class="java.lang.String" itemvalue="PHPUnit.tests" />
<item index="4" class="java.lang.String" itemvalue="PHPUnit.RouterUrlTest" />
</list>
</recent_temporary>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a7058529-bdc4-40b4-a50d-c50564dc83f0" name="Default" comment="" />
<created>1502498236860</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1502498236860</updated>
<workItem from="1502498238130" duration="495000" />
<workItem from="1502589327470" duration="1325000" />
<workItem from="1502643621164" duration="1124000" />
<workItem from="1502665379176" duration="1624000" />
<workItem from="1502669212357" duration="163000" />
<workItem from="1503009054866" duration="109000" />
<workItem from="1503143546207" duration="965000" />
<workItem from="1503146420259" duration="656000" />
<workItem from="1503148077591" duration="1223000" />
<workItem from="1503157038418" duration="7000" />
<workItem from="1503418539960" duration="475000" />
<workItem from="1503499434906" duration="6410000" />
<workItem from="1503519096046" duration="649000" />
<workItem from="1503520310378" duration="280000" />
<workItem from="1503521737747" duration="856000" />
<workItem from="1503524427576" duration="2573000" />
<workItem from="1503536487719" duration="1589000" />
<workItem from="1503542802083" duration="820000" />
<workItem from="1503585789014" duration="820000" />
<workItem from="1504176764746" duration="658000" />
<workItem from="1504283976613" duration="694000" />
<workItem from="1504448385820" duration="7834000" />
<workItem from="1504459201935" duration="83000" />
<workItem from="1504459311471" duration="1376000" />
<workItem from="1504486369526" duration="451000" />
<workItem from="1504917061077" duration="1291000" />
<workItem from="1507375921398" duration="131000" />
<workItem from="1508785846050" duration="916000" />
<workItem from="1508786969551" duration="615000" />
<workItem from="1508787603350" duration="1889000" />
<workItem from="1509491007644" duration="14000" />
<workItem from="1509491033605" duration="6000" />
<workItem from="1510192196700" duration="11000" />
<workItem from="1510192217149" duration="152000" />
<workItem from="1510193026656" duration="140000" />
<workItem from="1511567082879" duration="3024000" />
<workItem from="1511629790083" duration="1115000" />
<workItem from="1511632906778" duration="6000" />
<workItem from="1511709768816" duration="954000" />
<workItem from="1511710733832" duration="10000" />
<workItem from="1511710754848" duration="6388000" />
<workItem from="1511717327384" duration="1762000" />
<workItem from="1511736112440" duration="855000" />
<workItem from="1511741616771" duration="3149000" />
<workItem from="1512583258866" duration="985000" />
<workItem from="1512706044104" duration="1603000" />
<workItem from="1521506970558" duration="7811000" />
<workItem from="1522072655826" duration="1072000" />
<workItem from="1522073747209" duration="63000" />
<workItem from="1522073847648" duration="23574000" />
<workItem from="1522309434425" duration="745000" />
<workItem from="1522310203119" duration="120000" />
<workItem from="1522310337826" duration="117000" />
<workItem from="1522310475899" duration="12840000" />
<workItem from="1522325810130" duration="30260000" />
<workItem from="1522360506281" duration="168000" />
<workItem from="1522378435862" duration="2772000" />
<workItem from="1522385007533" duration="313000" />
<workItem from="1522507670882" duration="309000" />
<workItem from="1522508007514" duration="2427000" />
<workItem from="1522530661439" duration="3502000" />
<workItem from="1522668357317" duration="4847000" />
<workItem from="1523014652739" duration="16240000" />
<workItem from="1523035686391" duration="174000" />
<workItem from="1523035884787" duration="578000" />
<workItem from="1524367929693" duration="135000" />
</task>
<servers />
</component>
<component name="TestHistory">
<history-entry file="phpunit_xml - 2018.04.06 at 16h 54m 36s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 16h 55m 10s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 16h 55m 25s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 16h 57m 00s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 16h 57m 10s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 19h 04m 25s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 19h 04m 32s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 19h 35m 48s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 19h 35m 53s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="phpunit_xml - 2018.04.06 at 19h 35m 56s.xml">
<configuration name="phpunit.xml" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="166342000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
<is-autoscroll-to-source value="true" />
</todo-panel>
<todo-panel id="all">
<are-packages-shown value="true" />
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.21108742" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32983023" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32902184" sideWeight="0.50919265" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3272727" sideWeight="0.49080735" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32828283" sideWeight="0.5" order="14" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24975026" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2826087" sideWeight="0.49680257" order="12" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32967034" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="PHP-CGI Server" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Command Line Tools Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32928804" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Database Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="13" side_tool="false" content_ui="tabs" />
<window_info id="REST Client" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32929292" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection Results" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32828283" sideWeight="0.5" order="15" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3272727" sideWeight="0.48880896" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<option name="time" value="3" />
</breakpoint-manager>
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/IExceptionHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="48">
<caret line="2" column="10" lean-forward="true" selection-start-line="2" selection-start-column="10" selection-end-line="2" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="7" column="38" lean-forward="true" selection-start-line="7" selection-start-column="38" selection-end-line="7" selection-end-column="38" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/IEventHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="552">
<caret line="23" column="20" lean-forward="false" selection-start-line="23" selection-start-column="20" selection-end-line="23" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Event/EventArgument.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="54">
<caret line="45" column="26" lean-forward="true" selection-start-line="45" selection-start-column="26" selection-end-line="45" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/CallbackExceptionHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="48">
<caret line="2" column="0" lean-forward="false" selection-start-line="2" selection-start-column="0" selection-end-line="2" selection-end-column="38" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/vendor/php-di/php-di/src/ContainerBuilder.php" />
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/Containers/IContainer.php" />
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/Containers/DIContainerBuilder.php" />
<entry file="file://$PROJECT_DIR$/vendor/php-di/php-di/src/FactoryInterface.php" />
<entry file="file://$PROJECT_DIR$/vendor/php-di/invoker/src/InvokerInterface.php" />
<entry file="file://$PROJECT_DIR$/vendor/psr/container/src/ContainerInterface.php" />
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/IContainer.php" />
<entry file="file://$PROJECT_DIR$/vendor/mockery/mockery/library/Mockery/Container.php" />
<entry file="file://$PROJECT_DIR$/vendor/php-di/php-di/src/Container.php" />
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/IClassLoader.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="6" column="0" lean-forward="false" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tmp/CompiledContainer.php" />
<entry file="file://$PROJECT_DIR$/composer.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="370">
<caret line="30" column="27" lean-forward="false" selection-start-line="30" selection-start-column="27" selection-end-line="30" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="384">
<caret line="34" column="47" lean-forward="false" selection-start-line="34" selection-start-column="47" selection-end-line="34" selection-end-column="47" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/GroupTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="258">
<caret line="21" column="8" lean-forward="false" selection-start-line="21" selection-start-column="8" selection-end-line="21" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterRouteTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="572">
<caret line="105" column="33" lean-forward="false" selection-start-line="105" selection-start-column="33" selection-end-line="105" selection-end-column="33" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/Dummy/Exception/ResponseException.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="8" column="8" lean-forward="false" selection-start-line="8" selection-start-column="8" selection-end-line="8" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/DependencyInjectionTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="696">
<caret line="29" column="38" lean-forward="false" selection-start-line="29" selection-start-column="38" selection-end-line="29" selection-end-column="38" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Input/IInputItem.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="380">
<caret line="19" column="40" lean-forward="false" selection-start-line="19" selection-start-column="40" selection-end-line="19" selection-end-column="40" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Input/InputItem.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="80">
<caret line="4" column="37" lean-forward="false" selection-start-line="4" selection-start-column="37" selection-end-line="4" selection-end-column="37" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Input/InputFile.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="9" column="17" lean-forward="false" selection-start-line="9" selection-start-column="17" selection-end-line="9" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Handlers/EventHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="540">
<caret line="28" column="0" lean-forward="false" selection-start-line="28" selection-start-column="0" selection-end-line="28" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/EventHandlerTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1860">
<caret line="94" column="24" lean-forward="false" selection-start-line="94" selection-start-column="24" selection-end-line="94" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/IPartialGroupRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="80">
<caret line="4" column="10" lean-forward="false" selection-start-line="4" selection-start-column="10" selection-end-line="4" selection-end-column="10" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Response.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-2096">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/vendor/phpunit/phpunit/src/Framework/TestCase.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-687">
<caret line="100" column="15" lean-forward="false" selection-start-line="100" selection-start-column="15" selection-end-line="100" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Middleware/BaseCsrfVerifier.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="213">
<caret line="69" column="56" lean-forward="false" selection-start-line="69" selection-start-column="56" selection-end-line="69" selection-end-column="56" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Request.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="286">
<caret line="88" column="24" lean-forward="true" selection-start-line="88" selection-start-column="24" selection-end-line="88" selection-end-column="35" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/MiddlewareTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="6" column="53" lean-forward="true" selection-start-line="6" selection-start-column="53" selection-end-line="6" selection-end-column="53" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterUrlTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-34">
<caret line="85" column="0" lean-forward="false" selection-start-line="85" selection-start-column="0" selection-end-line="85" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/vendor/phpunit/phpunit/src/Framework/Assert.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="333">
<caret line="1197" column="27" lean-forward="false" selection-start-line="1197" selection-start-column="27" selection-end-line="1197" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Url.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="86">
<caret line="25" column="20" lean-forward="false" selection-start-line="25" selection-start-column="20" selection-end-line="25" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteGroup.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="716">
<caret line="55" column="45" lean-forward="false" selection-start-line="55" selection-start-column="45" selection-end-line="55" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/TestRouter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240">
<caret line="12" column="0" lean-forward="false" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="20">
<caret line="15" column="22" lean-forward="false" selection-start-line="15" selection-start-column="22" selection-end-line="15" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/ILoadableRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="640">
<caret line="32" column="36" lean-forward="false" selection-start-line="32" selection-start-column="30" selection-end-line="32" selection-end-column="36" />
<folding>
<element signature="e#44#67#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/helpers.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="960">
<caret line="51" column="59" lean-forward="false" selection-start-line="51" selection-start-column="59" selection-end-line="51" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="24400">
<caret line="1220" column="10" lean-forward="false" selection-start-line="1220" selection-start-column="10" selection-end-line="1220" selection-end-column="10" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Pecee/SimpleRouter/InputHandlerTest.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="405">
<caret line="81" column="60" lean-forward="false" selection-start-line="81" selection-start-column="60" selection-end-line="81" selection-end-column="60" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Router.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15181">
<caret line="893" column="20" lean-forward="false" selection-start-line="893" selection-start-column="20" selection-end-line="893" selection-end-column="20" />
<folding>
<element signature="e#38#84#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/Route.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2261">
<caret line="133" column="43" lean-forward="false" selection-start-line="133" selection-start-column="43" selection-end-line="133" selection-end-column="43" />
<folding>
<element signature="e#44#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/SimpleRouter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1275">
<caret line="100" column="16" lean-forward="false" selection-start-line="100" selection-start-column="8" selection-end-line="100" selection-end-column="16" />
<folding>
<element signature="e#302#319#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/LoadableRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1207">
<caret line="71" column="33" lean-forward="false" selection-start-line="71" selection-start-column="27" selection-end-line="71" selection-end-column="33" />
<folding>
<element signature="e#44#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteResource.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1598">
<caret line="94" column="116" lean-forward="false" selection-start-line="94" selection-start-column="116" selection-end-line="94" selection-end-column="116" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/IRoute.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="16" column="20" lean-forward="false" selection-start-line="16" selection-start-column="20" selection-end-line="16" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteUrl.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="64" lean-forward="false" selection-start-line="16" selection-start-column="64" selection-end-line="16" selection-end-column="64" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Pecee/Http/Input/InputHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="299" column="30" lean-forward="false" selection-start-line="299" selection-start-column="30" selection-end-line="299" selection-end-column="30" />
<folding>
<element signature="e#36#82#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>
+13
View File
@@ -0,0 +1,13 @@
build:
tests:
override:
-
command: './vendor/bin/phpunit --coverage-clover=coverage.clover'
coverage:
file: 'coverage.clover'
format: 'clover'
checks:
php:
code_rating: true
duplication: true
+13
View File
@@ -0,0 +1,13 @@
sudo: false
language: php
php:
- 7.1
before_script:
- curl -sS http://getcomposer.org/installer | php
- php composer.phar install --prefer-source --no-interaction
script:
- ./vendor/bin/phpunit
+720 -158
View File
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -27,14 +27,16 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=7.1",
"php-di/php-di": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "4.7.7"
"phpunit/phpunit": "^6.0",
"mockery/mockery": "^1"
},
"autoload": {
"psr-4": {
"Pecee\\": "src/Pecee/"
}
}
}
}
+18 -11
View File
@@ -1,6 +1,9 @@
<?php
use Pecee\SimpleRouter\SimpleRouter as Router;
use Pecee\Http\Url;
use Pecee\Http\Response;
use Pecee\Http\Request;
/**
* Get url for a route by using either name/alias, class or method name.
@@ -17,10 +20,10 @@ use Pecee\SimpleRouter\SimpleRouter as Router;
* @param string|null $name
* @param string|array|null $parameters
* @param array|null $getParams
* @return string
* @return \Pecee\Http\Url
* @throws \InvalidArgumentException
*/
function url($name = null, $parameters = null, $getParams = null)
function url(?string $name = null, $parameters = null, ?array $getParams = null): Url
{
return Router::getUrl($name, $parameters, $getParams);
}
@@ -28,7 +31,7 @@ function url($name = null, $parameters = null, $getParams = null)
/**
* @return \Pecee\Http\Response
*/
function response()
function response(): Response
{
return Router::response();
}
@@ -36,7 +39,7 @@ function response()
/**
* @return \Pecee\Http\Request
*/
function request()
function request(): Request
{
return Router::request();
}
@@ -45,19 +48,23 @@ function request()
* Get input class
* @param string|null $index Parameter index name
* @param string|null $defaultValue Default return value
* @param string|array|null $methods Default method
* @return \Pecee\Http\Input\Input|string
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|array|string|null
*/
function input($index = null, $defaultValue = null, $methods = null)
function input($index = null, $defaultValue = null, ...$methods)
{
if ($index !== null) {
return request()->getInput()->get($index, $defaultValue, $methods);
return request()->getInputHandler()->value($index, $defaultValue, ...$methods);
}
return request()->getInput();
return request()->getInputHandler();
}
function redirect($url, $code = null)
/**
* @param string $url
* @param int|null $code
*/
function redirect(string $url, ?int $code = null): void
{
if ($code !== null) {
response()->httpCode($code);
@@ -70,7 +77,7 @@ function redirect($url, $code = null)
* Get current csrf-token
* @return string|null
*/
function csrf_token()
function csrf_token(): ?string
{
$baseVerifier = Router::router()->getCsrfVerifier();
if ($baseVerifier !== null) {
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="SimpleRouter Test Suite">
<directory>tests/Pecee/SimpleRouter/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
+15 -14
View File
@@ -1,47 +1,48 @@
<?php
namespace Pecee\Controllers;
interface IResourceController
{
/**
* @return void
* @return string|null
*/
public function index();
public function index(): ?string;
/**
* @param mixed $id
* @return void
* @return string|null
*/
public function show($id);
public function show($id): ?string;
/**
* @return void
* @return string|null
*/
public function store();
public function store(): ?string;
/**
* @return void
* @return string|null
*/
public function create();
public function create(): ?string;
/**
* View
* @param mixed $id
* @return void
* @return string|null
*/
public function edit($id);
public function edit($id): ?string;
/**
* @param mixed $id
* @return void
* @return string|null
*/
public function update($id);
public function update($id): ?string;
/**
* @param mixed $id
* @return void
* @return string|null
*/
public function destroy($id);
public function destroy($id): ?string;
}
@@ -1,6 +1,8 @@
<?php
namespace Pecee\Exceptions;
class InvalidArgumentException extends \InvalidArgumentException {
class InvalidArgumentException extends \InvalidArgumentException
{
}
+7 -7
View File
@@ -5,18 +5,18 @@ namespace Pecee\Http\Input;
interface IInputItem
{
public function getIndex();
public function getIndex(): string;
public function setIndex($index);
public function setIndex(string $index): self;
public function getName();
public function getName(): ?string;
public function setName($name);
public function setName(string $name): self;
public function getValue();
public function getValue(): ?string;
public function setValue($value);
public function setValue(string $value): self;
public function __toString();
public function __toString(): string;
}
-296
View File
@@ -1,296 +0,0 @@
<?php
namespace Pecee\Http\Input;
use Pecee\Exceptions\InvalidArgumentException;
use Pecee\Http\Request;
class Input
{
/**
* @var array
*/
public $get = [];
/**
* @var array
*/
public $post = [];
/**
* @var array
*/
public $file = [];
/**
* @var Request
*/
protected $request;
/**
* Input constructor.
* @param Request $request
*/
public function __construct(Request $request)
{
$this->request = $request;
$this->parseInputs();
}
/**
* Parse input values
*
*/
public function parseInputs()
{
/* Parse get requests */
if (count($_GET) !== 0) {
$this->get = $this->handleGetPost($_GET);
}
/* Parse post requests */
$postVars = $_POST;
if (in_array($this->request->getMethod(), ['put', 'patch', 'delete'], false) === true) {
parse_str(file_get_contents('php://input'), $postVars);
}
if (count($postVars) !== 0) {
$this->post = $this->handleGetPost($postVars);
}
/* Parse get requests */
if (count($_FILES) !== 0) {
$this->file = $this->parseFiles();
}
}
/**
* @return array
*/
public function parseFiles()
{
$list = [];
foreach ((array)$_FILES as $key => $value) {
// Handle array input
if (is_array($value['name']) === false) {
$values['index'] = $key;
try {
$list[$key] = InputFile::createFromArray($values + $value);
} catch(InvalidArgumentException $e ){
}
continue;
}
$keys = [$key];
$files = $this->rearrangeFiles($value['name'], $keys, $value);
if (isset($list[$key]) === true) {
$list[$key][] = $files;
} else {
$list[$key] = $files;
}
}
return $list;
}
protected function rearrangeFiles(array $values, &$index, $original)
{
$originalIndex = $index[0];
array_shift($index);
$output = [];
foreach ($values as $key => $value) {
if (is_array($original['name'][$key]) === false) {
try {
$file = InputFile::createFromArray([
'index' => (empty($key) === true && empty($originalIndex) === false) ? $originalIndex : $key,
'name' => $original['name'][$key],
'error' => $original['error'][$key],
'tmp_name' => $original['tmp_name'][$key],
'type' => $original['type'][$key],
'size' => $original['size'][$key],
]);
if (isset($output[$key]) === true) {
$output[$key][] = $file;
continue;
}
$output[$key] = $file;
continue;
} catch(InvalidArgumentException $e) {
}
}
$index[] = $key;
$files = $this->rearrangeFiles($value, $index, $original);
if (isset($output[$key]) === true) {
$output[$key][] = $files;
} else {
$output[$key] = $files;
}
}
return $output;
}
protected function handleGetPost(array $array)
{
$list = [];
foreach ($array as $key => $value) {
// Handle array input
if (is_array($value) === false) {
$list[$key] = new InputItem($key, $value);
continue;
}
$output = $this->handleGetPost($value);
$list[$key] = $output;
}
return $list;
}
/**
* Find post-value by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputItem|string
*/
public function findPost($index, $defaultValue = null)
{
return isset($this->post[$index]) ? $this->post[$index] : $defaultValue;
}
/**
* Find file by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputFile|string
*/
public function findFile($index, $defaultValue = null)
{
return isset($this->file[$index]) ? $this->file[$index] : $defaultValue;
}
/**
* Find parameter/query-string by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputItem|string
*/
public function findGet($index, $defaultValue = null)
{
return isset($this->get[$index]) ? $this->get[$index] : $defaultValue;
}
/**
* Get input object
*
* @param string $index
* @param string|null $defaultValue
* @param array|string|null $methods
* @return IInputItem|string
*/
public function getObject($index, $defaultValue = null, $methods = null)
{
if ($methods !== null && is_string($methods) === true) {
$methods = [$methods];
}
$element = null;
if ($methods === null || in_array('get', $methods, false) === true) {
$element = $this->findGet($index);
}
if (($element === null && $methods === null) || ($methods !== null && in_array('post', $methods, false) === true)) {
$element = $this->findPost($index);
}
if (($element === null && $methods === null) || ($methods !== null && in_array('file', $methods, false) === true)) {
$element = $this->findFile($index);
}
return ($element !== null) ? $element : $defaultValue;
}
/**
* Get input element value matching index
*
* @param string $index
* @param string|null $defaultValue
* @param array|string|null $methods
* @return InputItem|string
*/
public function get($index, $defaultValue = null, $methods = null)
{
$input = $this->getObject($index, $defaultValue, $methods);
if ($input instanceof InputItem) {
return (trim($input->getValue()) === '') ? $defaultValue : $input->getValue();
}
return $input;
}
/**
* Check if a input-item exist
*
* @param string $index
* @return bool
*/
public function exists($index)
{
return ($this->getObject($index) !== null);
}
/**
* Get all get/post items
* @param array|null $filter Only take items in filter
* @return array
*/
public function all(array $filter = null)
{
$output = $_GET + $_POST;
if ($this->request->getMethod() === 'post') {
$contents = file_get_contents('php://input');
if (strpos(trim($contents), '{') === 0) {
$post = json_decode($contents, true);
if ($post !== false) {
$output += $post;
}
}
}
return ($filter !== null) ? array_intersect_key($output, array_flip($filter)) : $output;
}
}
+36 -36
View File
@@ -14,7 +14,7 @@ class InputFile implements IInputItem
public $errors;
public $tmpName;
public function __construct($index)
public function __construct(string $index)
{
$this->index = $index;
@@ -31,7 +31,7 @@ class InputFile implements IInputItem
* @throws InvalidArgumentException
* @return static
*/
public static function createFromArray(array $values)
public static function createFromArray(array $values): self
{
if (isset($values['index']) === false) {
throw new InvalidArgumentException('Index key is required');
@@ -48,8 +48,8 @@ class InputFile implements IInputItem
];
return (new static($values['index']))
->setSize($values['size'])
->setError($values['error'])
->setSize((int)$values['size'])
->setError((int)$values['error'])
->setType($values['type'])
->setTmpName($values['tmp_name'])
->setFilename($values['name']);
@@ -59,7 +59,7 @@ class InputFile implements IInputItem
/**
* @return string
*/
public function getIndex()
public function getIndex(): string
{
return $this->index;
}
@@ -67,9 +67,9 @@ class InputFile implements IInputItem
/**
* Set input index
* @param string $index
* @return static $this
* @return static
*/
public function setIndex($index)
public function setIndex(string $index): IInputItem
{
$this->index = $index;
@@ -79,7 +79,7 @@ class InputFile implements IInputItem
/**
* @return string
*/
public function getSize()
public function getSize(): string
{
return $this->size;
}
@@ -87,9 +87,9 @@ class InputFile implements IInputItem
/**
* Set file size
* @param int $size
* @return static $this
* @return static
*/
public function setSize($size)
public function setSize(int $size): IInputItem
{
$this->size = $size;
@@ -100,7 +100,7 @@ class InputFile implements IInputItem
* Get mime-type of file
* @return string
*/
public function getMime()
public function getMime(): string
{
return $this->getType();
}
@@ -108,7 +108,7 @@ class InputFile implements IInputItem
/**
* @return string
*/
public function getType()
public function getType(): string
{
return $this->type;
}
@@ -116,9 +116,9 @@ class InputFile implements IInputItem
/**
* Set type
* @param string $type
* @return static $this
* @return static
*/
public function setType($type)
public function setType(string $type): IInputItem
{
$this->type = $type;
@@ -130,7 +130,7 @@ class InputFile implements IInputItem
*
* @return string
*/
public function getExtension()
public function getExtension(): string
{
return pathinfo($this->getFilename(), PATHINFO_EXTENSION);
}
@@ -140,7 +140,7 @@ class InputFile implements IInputItem
*
* @return string
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -150,9 +150,9 @@ class InputFile implements IInputItem
* Useful for adding validation etc.
*
* @param string $name
* @return static $this
* @return static
*/
public function setName($name)
public function setName(string $name): IInputItem
{
$this->name = $name;
@@ -163,9 +163,9 @@ class InputFile implements IInputItem
* Set filename
*
* @param string $name
* @return static $this
* @return static
*/
public function setFilename($name)
public function setFilename($name): IInputItem
{
$this->filename = $name;
@@ -177,7 +177,7 @@ class InputFile implements IInputItem
*
* @return string mixed
*/
public function getFilename()
public function getFilename(): ?string
{
return $this->filename;
}
@@ -188,7 +188,7 @@ class InputFile implements IInputItem
* @param string $destination
* @return bool
*/
public function move($destination)
public function move($destination): bool
{
return move_uploaded_file($this->tmpName, $destination);
}
@@ -198,7 +198,7 @@ class InputFile implements IInputItem
*
* @return string
*/
public function getContents()
public function getContents(): string
{
return file_get_contents($this->tmpName);
}
@@ -208,7 +208,7 @@ class InputFile implements IInputItem
*
* @return bool
*/
public function hasError()
public function hasError(): bool
{
return ($this->getError() !== 0);
}
@@ -216,20 +216,20 @@ class InputFile implements IInputItem
/**
* Get upload-error code.
*
* @return string
* @return int
*/
public function getError()
public function getError(): int
{
return $this->errors;
return (int)$this->errors;
}
/**
* Set error
*
* @param int $error
* @return static $this
* @return static
*/
public function setError($error)
public function setError($error): IInputItem
{
$this->errors = (int)$error;
@@ -239,7 +239,7 @@ class InputFile implements IInputItem
/**
* @return string
*/
public function getTmpName()
public function getTmpName(): string
{
return $this->tmpName;
}
@@ -247,21 +247,21 @@ class InputFile implements IInputItem
/**
* Set file temp. name
* @param string $name
* @return static $this
* @return static
*/
public function setTmpName($name)
public function setTmpName($name): IInputItem
{
$this->tmpName = $name;
return $this;
}
public function __toString()
public function __toString(): string
{
return $this->getTmpName();
}
public function getValue()
public function getValue(): ?string
{
return $this->getFilename();
}
@@ -270,14 +270,14 @@ class InputFile implements IInputItem
* @param string $value
* @return static
*/
public function setValue($value)
public function setValue(string $value): IInputItem
{
$this->filename = $value;
return $this;
}
public function toArray()
public function toArray(): array
{
return [
'tmp_name' => $this->tmpName,
+348
View File
@@ -0,0 +1,348 @@
<?php
namespace Pecee\Http\Input;
use Pecee\Exceptions\InvalidArgumentException;
use Pecee\Http\Request;
class InputHandler
{
/**
* @var array
*/
protected $get = [];
/**
* @var array
*/
protected $post = [];
/**
* @var array
*/
protected $file = [];
/**
* @var Request
*/
protected $request;
/**
* Input constructor.
* @param Request $request
*/
public function __construct(Request $request)
{
$this->request = $request;
$this->parseInputs();
}
/**
* Parse input values
*
*/
public function parseInputs(): void
{
/* Parse get requests */
if (\count($_GET) !== 0) {
$this->get = $this->parseInputItem($_GET);
}
/* Parse post requests */
$postVars = $_POST;
if (\in_array($this->request->getMethod(), ['put', 'patch', 'delete'], false) === true) {
parse_str(file_get_contents('php://input'), $postVars);
}
if (\count($postVars) !== 0) {
$this->post = $this->parseInputItem($postVars);
}
/* Parse get requests */
if (\count($_FILES) !== 0) {
$this->file = $this->parseFiles();
}
}
/**
* @return array
*/
public function parseFiles(): array
{
$list = [];
foreach ((array)$_FILES as $key => $value) {
// Handle array input
if (\is_array($value['name']) === false) {
$values['index'] = $key;
try {
$list[$key] = InputFile::createFromArray($values + $value);
} catch (InvalidArgumentException $e) {
}
continue;
}
$keys = [$key];
$files = $this->rearrangeFile($value['name'], $keys, $value);
if (isset($list[$key]) === true) {
$list[$key][] = $files;
} else {
$list[$key] = $files;
}
}
return $list;
}
/**
* Rearrange multi-dimensional file object created by PHP.
*
* @param array $values
* @param array $index
* @param array|null $original
* @return array
*/
protected function rearrangeFile(array $values, &$index, $original): array
{
$originalIndex = $index[0];
array_shift($index);
$output = [];
foreach ($values as $key => $value) {
if (\is_array($original['name'][$key]) === false) {
try {
$file = InputFile::createFromArray([
'index' => (empty($key) === true && empty($originalIndex) === false) ? $originalIndex : $key,
'name' => $original['name'][$key],
'error' => $original['error'][$key],
'tmp_name' => $original['tmp_name'][$key],
'type' => $original['type'][$key],
'size' => $original['size'][$key],
]);
if (isset($output[$key]) === true) {
$output[$key][] = $file;
continue;
}
$output[$key] = $file;
continue;
} catch (InvalidArgumentException $e) {
}
}
$index[] = $key;
$files = $this->rearrangeFile($value, $index, $original);
if (isset($output[$key]) === true) {
$output[$key][] = $files;
} else {
$output[$key] = $files;
}
}
return $output;
}
/**
* Parse input item from array
*
* @param array $array
* @return array
*/
protected function parseInputItem(array $array): array
{
$list = [];
foreach ($array as $key => $value) {
// Handle array input
if (\is_array($value) === false) {
$list[$key] = new InputItem($key, $value);
continue;
}
$output = $this->parseInputItem($value);
$list[$key] = $output;
}
return $list;
}
/**
* Find input object
*
* @param string $index
* @param array ...$methods
* @return IInputItem|array|null
*/
public function find(string $index, ...$methods)
{
$element = null;
if (\count($methods) === 0 || \in_array('get', $methods, true) === true) {
$element = $this->get($index);
}
if (($element === null && \count($methods) === 0) || (\count($methods) !== 0 && \in_array('post', $methods, true) === true)) {
$element = $this->post($index);
}
if (($element === null && \count($methods) === 0) || (\count($methods) !== 0 && \in_array('file', $methods, true) === true)) {
$element = $this->file($index);
}
return $element;
}
/**
* Get input element value matching index
*
* @param string $index
* @param string|null $defaultValue
* @param array ...$methods
* @return string|array
*/
public function value(string $index, ?string $defaultValue = null, ...$methods)
{
$input = $this->find($index, ...$methods);
$output = [];
/* Handle collection */
if (\is_array($input) === true) {
/* @var $item InputItem */
foreach ($input as $item) {
$output[] = $item->getValue();
}
return (\count($output) === 0) ? $defaultValue : $output;
}
return ($input === null || ($input !== null && trim($input->getValue()) === '')) ? $defaultValue : $input->getValue();
}
/**
* Check if a input-item exist
*
* @param string $index
* @param array ...$methods
* @return bool
*/
public function exists(string $index, ...$methods): bool
{
return $this->value($index, null, ...$methods) !== null;
}
/**
* Find post-value by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputItem|array|string|null
*/
public function post(string $index, ?string $defaultValue = null)
{
return $this->post[$index] ?? $defaultValue;
}
/**
* Find file by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputFile|array|string|null
*/
public function file(string $index, ?string $defaultValue = null)
{
return $this->file[$index] ?? $defaultValue;
}
/**
* Find parameter/query-string by index or return default value.
*
* @param string $index
* @param string|null $defaultValue
* @return InputItem|array|string|null
*/
public function get(string $index, ?string $defaultValue = null)
{
return $this->get[$index] ?? $defaultValue;
}
/**
* Get all get/post items
* @param array $filter Only take items in filter
* @return array
*/
public function all(array $filter = []): array
{
$output = $_GET;
if ($this->request->getMethod() === 'post') {
// Append POST data
$output += $_POST;
$contents = file_get_contents('php://input');
// Append any PHP-input json
if (strpos(trim($contents), '{') === 0) {
$post = json_decode($contents, true);
if ($post !== false) {
$output += $post;
}
}
}
return (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output;
}
/**
* Add GET parameter
*
* @param string $key
* @param InputItem $item
*/
public function addGet(string $key, InputItem $item): void
{
$this->get[$key] = $item;
}
/**
* Add POST parameter
*
* @param string $key
* @param InputItem $item
*/
public function addPost(string $key, InputItem $item): void
{
$this->post[$key] = $item;
}
/**
* Add FILE parameter
*
* @param string $key
* @param InputFile $item
*/
public function addFile(string $key, InputFile $item): void
{
$this->file[$key] = $item;
}
}
+10 -10
View File
@@ -8,7 +8,7 @@ class InputItem implements IInputItem
public $name;
public $value;
public function __construct($index, $value = null)
public function __construct(string $index, ?string $value = null)
{
$this->index = $index;
$this->value = $value;
@@ -20,12 +20,12 @@ class InputItem implements IInputItem
/**
* @return string
*/
public function getIndex()
public function getIndex(): string
{
return $this->index;
}
public function setIndex($index)
public function setIndex(string $index): IInputItem
{
$this->index = $index;
@@ -35,7 +35,7 @@ class InputItem implements IInputItem
/**
* @return string
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -43,9 +43,9 @@ class InputItem implements IInputItem
/**
* Set input name
* @param string $name
* @return static $this
* @return static
*/
public function setName($name)
public function setName(string $name): IInputItem
{
$this->name = $name;
@@ -55,7 +55,7 @@ class InputItem implements IInputItem
/**
* @return string
*/
public function getValue()
public function getValue(): ?string
{
return $this->value;
}
@@ -63,16 +63,16 @@ class InputItem implements IInputItem
/**
* Set input value
* @param string $value
* @return static $this
* @return static
*/
public function setValue($value)
public function setValue(string $value): IInputItem
{
$this->value = $value;
return $this;
}
public function __toString()
public function __toString(): string
{
return (string)$this->value;
}
+17 -18
View File
@@ -9,8 +9,8 @@ use Pecee\Http\Security\ITokenProvider;
class BaseCsrfVerifier implements IMiddleware
{
const POST_KEY = 'csrf-token';
const HEADER_KEY = 'X-CSRF-TOKEN';
public const POST_KEY = 'csrf-token';
public const HEADER_KEY = 'X-CSRF-TOKEN';
protected $except;
protected $tokenProvider;
@@ -29,21 +29,21 @@ class BaseCsrfVerifier implements IMiddleware
* @param Request $request
* @return bool
*/
protected function skip(Request $request)
protected function skip(Request $request): bool
{
if ($this->except === null || count($this->except) === 0) {
if ($this->except === null || \count($this->except) === 0) {
return false;
}
$max = count($this->except) - 1;
$max = \count($this->except) - 1;
for ($i = $max; $i >= 0; $i--) {
$url = $this->except[$i];
$url = rtrim($url, '/');
if ($url[strlen($url) - 1] === '*') {
if ($url[\strlen($url) - 1] === '*') {
$url = rtrim($url, '*');
$skip = (stripos($request->getUrl()->getOriginalUrl(), $url) === 0);
$skip = $request->getUrl()->contains($url);
} else {
$skip = ($url === $request->getUrl()->getOriginalUrl());
}
@@ -62,19 +62,18 @@ class BaseCsrfVerifier implements IMiddleware
* @param Request $request
* @throws TokenMismatchException
*/
public function handle(Request $request)
public function handle(Request $request): void
{
if ($this->skip($request) === false && in_array($request->getMethod(), ['post', 'put', 'delete'], false) === true) {
if ($this->skip($request) === false && \in_array($request->getMethod(), ['post', 'put', 'delete'], true) === true) {
$token = $request->getInput()->get(static::POST_KEY, null, 'post');
$token = $request->getInputHandler()->value(
static::POST_KEY,
$request->getHeader(static::HEADER_KEY),
'post'
);
// If the token is not posted, check headers for valid x-csrf-token
if ($token === null) {
$token = $request->getHeader(static::HEADER_KEY);
}
if ($this->tokenProvider->validate($token) === false) {
if ($this->tokenProvider->validate((string)$token) === false) {
throw new TokenMismatchException('Invalid CSRF-token.');
}
@@ -85,7 +84,7 @@ class BaseCsrfVerifier implements IMiddleware
}
public function getTokenProvider()
public function getTokenProvider(): ITokenProvider
{
return $this->tokenProvider;
}
@@ -94,7 +93,7 @@ class BaseCsrfVerifier implements IMiddleware
* Set token provider
* @param ITokenProvider $provider
*/
public function setTokenProvider(ITokenProvider $provider)
public function setTokenProvider(ITokenProvider $provider): void
{
$this->tokenProvider = $provider;
}
@@ -1,4 +1,5 @@
<?php
namespace Pecee\Http\Middleware\Exceptions;
class TokenMismatchException extends \Exception
+2 -2
View File
@@ -1,4 +1,5 @@
<?php
namespace Pecee\Http\Middleware;
use Pecee\Http\Request;
@@ -7,8 +8,7 @@ interface IMiddleware
{
/**
* @param Request $request
* @return Request|null
*/
public function handle(Request $request);
public function handle(Request $request): void;
}
+159 -84
View File
@@ -2,61 +2,94 @@
namespace Pecee\Http;
use Pecee\Http\Input\Input;
use Pecee\Http\Exceptions\MalformedUrlException;
use Pecee\Http\Input\InputHandler;
use Pecee\SimpleRouter\Route\ILoadableRoute;
use Pecee\SimpleRouter\Route\RouteUrl;
use Pecee\SimpleRouter\SimpleRouter;
class Request
{
/**
* Additional data
*
* @var array
*/
private $data = [];
protected $headers;
protected $host;
protected $url;
protected $method;
protected $input;
protected $hasRewrite = false;
/**
* Server headers
* @var array
*/
protected $headers = [];
/**
* Request host
* @var string
*/
protected $host;
/**
* Current request url
* @var Url
*/
protected $url;
/**
* Request method
* @var string
*/
protected $method;
/**
* Input handler
* @var InputHandler
*/
protected $inputHandler;
/**
* Defines if request has pending rewrite
* @var bool
*/
protected $hasPendingRewrite = false;
/**
* @var ILoadableRoute|null
*/
protected $rewriteRoute;
/**
* Rewrite url
* @var string|null
*/
protected $rewriteUrl;
/**
* @var ILoadableRoute|null
* @var array
*/
protected $loadedRoute;
protected $loadedRoutes = [];
/**
* Request constructor.
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* @throws MalformedUrlException
*/
public function __construct()
{
$this->parseHeaders();
$this->setHost($this->getHeader('http-host'));
// Check if special IIS header exist, otherwise use default.
$this->setUrl($this->getHeader('unencoded-url', $this->getHeader('request-uri')));
$this->input = new Input($this);
$this->method = strtolower($this->input->get('_method', $this->getHeader('request-method')));
}
protected function parseHeaders()
{
$this->headers = [];
foreach ($_SERVER as $key => $value) {
$this->headers[strtolower($key)] = $value;
$this->headers[strtolower(str_replace('_', '-', $key))] = $value;
}
$this->setHost($this->getHeader('http-host'));
// Check if special IIS header exist, otherwise use default.
$this->setUrl(new Url($this->getHeader('unencoded-url', $this->getHeader('request-uri'))));
$this->inputHandler = new InputHandler($this);
$this->method = strtolower($this->inputHandler->value('_method', $this->getHeader('request-method')));
}
public function isSecure()
public function isSecure(): bool
{
return $this->getHeader('http-x-forwarded-proto') === 'https' || $this->getHeader('https') !== null || $this->getHeader('server-port') === 443;
}
@@ -64,23 +97,33 @@ class Request
/**
* @return Url
*/
public function getUrl()
public function getUrl(): Url
{
return $this->url;
}
/**
* @return string
* Copy url object
*
* @return Url
*/
public function getHost()
public function getUrlCopy(): Url
{
return clone $this->url;
}
/**
* @return string|null
*/
public function getHost(): ?string
{
return $this->host;
}
/**
* @return string
* @return string|null
*/
public function getMethod()
public function getMethod(): ?string
{
return $this->method;
}
@@ -89,7 +132,7 @@ class Request
* Get http basic auth user
* @return string|null
*/
public function getUser()
public function getUser(): ?string
{
return $this->getHeader('php-auth-user');
}
@@ -98,7 +141,7 @@ class Request
* Get http basic auth password
* @return string|null
*/
public function getPassword()
public function getPassword(): ?string
{
return $this->getHeader('php-auth-pw');
}
@@ -107,16 +150,16 @@ class Request
* Get all headers
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}
/**
* Get id address
* @return string
* @return string|null
*/
public function getIp()
public function getIp(): ?string
{
if ($this->getHeader('http-cf-connecting-ip') !== null) {
return $this->getHeader('http-cf-connecting-ip');
@@ -133,27 +176,27 @@ class Request
* Get remote address/ip
*
* @alias static::getIp
* @return string
* @return string|null
*/
public function getRemoteAddr()
public function getRemoteAddr(): ?string
{
return $this->getIp();
}
/**
* Get referer
* @return string
* @return string|null
*/
public function getReferer()
public function getReferer(): ?string
{
return $this->getHeader('http-referer');
}
/**
* Get user agent
* @return string
* @return string|null
*/
public function getUserAgent()
public function getUserAgent(): ?string
{
return $this->getHeader('http-user-agent');
}
@@ -166,18 +209,18 @@ class Request
*
* @return string|null
*/
public function getHeader($name, $defaultValue = null)
public function getHeader($name, $defaultValue = null): ?string
{
return isset($this->headers[strtolower($name)]) ? $this->headers[strtolower($name)] : $defaultValue;
return $this->headers[strtolower($name)] ?? $defaultValue;
}
/**
* Get input class
* @return Input
* @return InputHandler
*/
public function getInput()
public function getInputHandler(): InputHandler
{
return $this->input;
return $this->inputHandler;
}
/**
@@ -187,9 +230,9 @@ class Request
*
* @return bool
*/
public function isFormatAccepted($format)
public function isFormatAccepted($format): bool
{
return ($this->getHeader('http-accept') !== null && stripos($this->getHeader('http-accept'), $format) > -1);
return ($this->getHeader('http-accept') !== null && stripos($this->getHeader('http-accept'), $format) !== false);
}
/**
@@ -197,7 +240,7 @@ class Request
*
* @return bool
*/
public function isAjax()
public function isAjax(): bool
{
return (strtolower($this->getHeader('http-x-requested-with')) === 'xmlhttprequest');
}
@@ -206,24 +249,27 @@ class Request
* Get accept formats
* @return array
*/
public function getAcceptFormats()
public function getAcceptFormats(): array
{
return explode(',', $this->getHeader('http-accept'));
}
/**
* @param string|Url $url
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* @param Url $url
*/
public function setUrl($url)
public function setUrl(Url $url): void
{
$this->url = ($url instanceof Url) ? $url : new Url($url);
$this->url = $url;
if ($this->url->getHost() === null) {
$this->url->setHost((string)$this->getHost());
}
}
/**
* @param string $host
* @param string|null $host
*/
public function setHost($host)
public function setHost(?string $host): void
{
$this->host = $host;
}
@@ -231,9 +277,9 @@ class Request
/**
* @param string $method
*/
public function setMethod($method)
public function setMethod(string $method): void
{
$this->method = $method;
$this->method = strtolower($method);
}
/**
@@ -242,9 +288,9 @@ class Request
* @param ILoadableRoute $route
* @return static
*/
public function setRewriteRoute(ILoadableRoute $route)
public function setRewriteRoute(ILoadableRoute $route): self
{
$this->hasRewrite = true;
$this->hasPendingRewrite = true;
$this->rewriteRoute = SimpleRouter::addDefaultNamespace($route);
return $this;
@@ -255,7 +301,7 @@ class Request
*
* @return ILoadableRoute|null
*/
public function getRewriteRoute()
public function getRewriteRoute(): ?ILoadableRoute
{
return $this->rewriteRoute;
}
@@ -263,9 +309,9 @@ class Request
/**
* Get rewrite url
*
* @return string
* @return string|null
*/
public function getRewriteUrl()
public function getRewriteUrl(): ?string
{
return $this->rewriteUrl;
}
@@ -276,9 +322,9 @@ class Request
* @param string $rewriteUrl
* @return static
*/
public function setRewriteUrl($rewriteUrl)
public function setRewriteUrl(string $rewriteUrl): self
{
$this->hasRewrite = true;
$this->hasPendingRewrite = true;
$this->rewriteUrl = rtrim($rewriteUrl, '/') . '/';
return $this;
@@ -286,12 +332,12 @@ class Request
/**
* Set rewrite callback
* @param string $callback
* @param string|\Closure $callback
* @return static
*/
public function setRewriteCallback($callback)
public function setRewriteCallback($callback): self
{
$this->hasRewrite = true;
$this->hasPendingRewrite = true;
return $this->setRewriteRoute(new RouteUrl($this->getUrl()->getPath(), $callback));
}
@@ -300,44 +346,73 @@ class Request
* Get loaded route
* @return ILoadableRoute|null
*/
public function getLoadedRoute()
public function getLoadedRoute(): ?ILoadableRoute
{
return $this->loadedRoute;
return (\count($this->loadedRoutes) > 0) ? end($this->loadedRoutes) : null;
}
/**
* Set loaded route
* Get all loaded routes
*
* @return array
*/
public function getLoadedRoutes(): array
{
return $this->loadedRoutes;
}
/**
* Set loaded routes
*
* @param array $routes
* @return static
*/
public function setLoadedRoutes(array $routes): self
{
$this->loadedRoutes = $routes;
return $this;
}
/**
* Added loaded route
*
* @param ILoadableRoute $route
* @return static
*/
public function setLoadedRoute(ILoadableRoute $route)
public function addLoadedRoute(ILoadableRoute $route): self
{
$this->loadedRoute = $route;
$this->loadedRoutes[] = $route;
return $this;
}
public function hasRewrite()
/**
* Returns true if the request contains a rewrite
*
* @return bool
*/
public function hasPendingRewrite(): bool
{
return $this->hasRewrite;
return $this->hasPendingRewrite;
}
public function setHasRewrite($value)
/**
* Defines if the current request contains a rewrite.
*
* @param bool $boolean
* @return Request
*/
public function setHasPendingRewrite(bool $boolean): self
{
$this->hasRewrite = $value;
$this->hasPendingRewrite = $boolean;
return $this;
}
public function isRewrite($url)
{
return ($this->rewriteUrl === $url);
}
public function __isset($name)
{
return array_key_exists($name, $this->data);
return array_key_exists($name, $this->data) === true;
}
public function __set($name, $value = null)
@@ -347,7 +422,7 @@ class Request
public function __get($name)
{
return isset($this->data[$name]) ? $this->data[$name] : null;
return $this->data[$name] ?? null;
}
}
+13 -14
View File
@@ -19,7 +19,7 @@ class Response
* @param int $code
* @return static
*/
public function httpCode($code)
public function httpCode(int $code): self
{
http_response_code($code);
@@ -32,7 +32,7 @@ class Response
* @param string $url
* @param int $httpCode
*/
public function redirect($url, $httpCode = null)
public function redirect(string $url, ?int $httpCode = null): void
{
if ($httpCode !== null) {
$this->httpCode($httpCode);
@@ -42,7 +42,7 @@ class Response
exit(0);
}
public function refresh()
public function refresh(): void
{
$this->redirect($this->request->getUrl()->getOriginalUrl());
}
@@ -52,7 +52,7 @@ class Response
* @param string $name
* @return static
*/
public function auth($name = '')
public function auth(string $name = ''): self
{
$this->headers([
'WWW-Authenticate: Basic realm="' . $name . '"',
@@ -62,23 +62,22 @@ class Response
return $this;
}
public function cache($eTag, $lastModified = 2592000)
public function cache(string $eTag, int $lastModifiedTime = 2592000): self
{
$this->headers([
'Cache-Control: public',
'Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT',
'Etag: ' . $eTag,
sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $lastModifiedTime)),
sprintf('Etag: %s', $eTag),
]);
$httpModified = $this->request->getHeader('http-if-modified-since');
$httpIfNoneMatch = $this->request->getHeader('http-if-none-match');
if (($httpIfNoneMatch !== null && $httpIfNoneMatch === $eTag) || ($httpModified !== null && strtotime($httpModified) === $lastModified)) {
if (($httpIfNoneMatch !== null && $httpIfNoneMatch === $eTag) || ($httpModified !== null && strtotime($httpModified) === $lastModifiedTime)) {
$this->header('HTTP/1.1 304 Not Modified');
exit();
exit(0);
}
return $this;
@@ -91,9 +90,9 @@ class Response
* @param int $dept JSON debt.
* @throws InvalidArgumentException
*/
public function json($value, $options = null, $dept = 512)
public function json($value, ?int $options = null, int $dept = 512): void
{
if (($value instanceof \JsonSerializable) === false && is_array($value) === false) {
if (($value instanceof \JsonSerializable) === false && \is_array($value) === false) {
throw new InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
}
@@ -107,7 +106,7 @@ class Response
* @param string $value
* @return static
*/
public function header($value)
public function header(string $value): self
{
header($value);
@@ -119,7 +118,7 @@ class Response
* @param array $headers
* @return static
*/
public function headers(array $headers)
public function headers(array $headers): self
{
foreach ($headers as $header) {
$this->header($header);
+17 -28
View File
@@ -6,7 +6,7 @@ use Pecee\Http\Security\Exceptions\SecurityException;
class CookieTokenProvider implements ITokenProvider
{
const CSRF_KEY = 'CSRF-TOKEN';
public const CSRF_KEY = 'CSRF-TOKEN';
protected $token;
protected $cookieTimeoutMinutes = 120;
@@ -30,24 +30,13 @@ class CookieTokenProvider implements ITokenProvider
* @return string
* @throws SecurityException
*/
public function generateToken()
public function generateToken(): string
{
if (function_exists('random_bytes') === true) {
try {
return bin2hex(random_bytes(32));
} catch(\Exception $e) {
throw new SecurityException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
try {
return bin2hex(random_bytes(32));
} catch (\Exception $e) {
throw new SecurityException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
$isSourceStrong = false;
$random = openssl_random_pseudo_bytes(32, $isSourceStrong);
if ($isSourceStrong === false || $random === false) {
throw new SecurityException('IV generation failed');
}
return $random;
}
/**
@@ -56,9 +45,9 @@ class CookieTokenProvider implements ITokenProvider
* @param string $token
* @return bool
*/
public function validate($token)
public function validate(string $token): bool
{
if ($token !== null && $this->getToken() !== null) {
if ($this->getToken() !== null) {
return hash_equals($token, $this->getToken());
}
@@ -71,10 +60,10 @@ class CookieTokenProvider implements ITokenProvider
*
* @param string $token
*/
public function setToken($token)
public function setToken(string $token): void
{
$this->token = $token;
setcookie(static::CSRF_KEY, $token, time() + 60 * $this->cookieTimeoutMinutes, '/');
setcookie(static::CSRF_KEY, $token, (int)((time() + 60) * $this->cookieTimeoutMinutes), '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
}
/**
@@ -82,17 +71,17 @@ class CookieTokenProvider implements ITokenProvider
* @param string|null $defaultValue
* @return string|null
*/
public function getToken($defaultValue = null)
public function getToken(?string $defaultValue = null): ?string
{
$this->token = ($this->hasToken() === true) ? $_COOKIE[static::CSRF_KEY] : null;
return ($this->token !== null) ? $this->token : $defaultValue;
return $this->token ?? $defaultValue;
}
/**
* Refresh existing token
*/
public function refresh()
public function refresh(): void
{
if ($this->token !== null) {
$this->setToken($this->token);
@@ -103,7 +92,7 @@ class CookieTokenProvider implements ITokenProvider
* Returns whether the csrf token has been defined
* @return bool
*/
public function hasToken()
public function hasToken(): bool
{
return isset($_COOKIE[static::CSRF_KEY]);
}
@@ -112,16 +101,16 @@ class CookieTokenProvider implements ITokenProvider
* Get timeout for cookie in minutes
* @return int
*/
public function getCookieTimeoutMinutes()
public function getCookieTimeoutMinutes(): int
{
return $this->cookieTimeoutMinutes;
}
/**
* Set cookie timeout in minutes
* @param $minutes
* @param int $minutes
*/
public function setCookieTimeoutMinutes($minutes)
public function setCookieTimeoutMinutes(int $minutes): void
{
$this->cookieTimeoutMinutes = $minutes;
}
@@ -1,6 +1,8 @@
<?php
namespace Pecee\Http\Security\Exceptions;
class SecurityException extends \Exception {
class SecurityException extends \Exception
{
}
+10 -2
View File
@@ -8,7 +8,7 @@ interface ITokenProvider
/**
* Refresh existing token
*/
public function refresh();
public function refresh(): void;
/**
* Validate valid CSRF token
@@ -16,6 +16,14 @@ interface ITokenProvider
* @param string $token
* @return bool
*/
public function validate($token);
public function validate(string $token): bool;
/**
* Get token token
*
* @param string|null $defaultValue
* @return string|null
*/
public function getToken(?string $defaultValue = null): ?string;
}
+347 -46
View File
@@ -4,142 +4,384 @@ namespace Pecee\Http;
use Pecee\Http\Exceptions\MalformedUrlException;
class Url
class Url implements \JsonSerializable
{
private $originalUrl;
private $data = [
'scheme' => null,
'host' => null,
'port' => null,
'user' => null,
'pass' => null,
'path' => null,
'query' => null,
'fragment' => null,
];
private $scheme;
private $host;
private $port;
private $username;
private $password;
private $path;
private $params = [];
private $fragment;
/**
* Url constructor.
*
* @param string $url
* @throws MalformedUrlException
*/
public function __construct($url)
public function __construct(?string $url)
{
$this->originalUrl = $url;
$this->data = $this->parseUrl($url) + $this->data;
if (isset($this->data['path']) === true && $this->data['path'] !== '/') {
$this->data['path'] = rtrim($this->data['path'], '/') . '/';
if ($url !== null && $url !== '/') {
$data = $this->parseUrl($url);
$this->scheme = $data['scheme'] ?? null;
$this->host = $data['host'] ?? null;
$this->port = $data['port'] ?? null;
$this->username = $data['user'] ?? null;
$this->password = $data['pass'] ?? null;
if (isset($data['path']) === true) {
$this->setPath($data['path']);
}
$this->fragment = $data['fragment'] ?? null;
if (isset($data['query']) === true) {
$this->setQueryString($data['query']);
}
}
}
/**
* Check if url is using a secure protocol like https
*
* @return bool
*/
public function isSecure()
public function isSecure(): bool
{
return (strtolower($this->getScheme()) === 'https');
}
/**
* Checks if url is relative
*
* @return bool
*/
public function isRelative()
public function isRelative(): bool
{
return ($this->getHost() === null);
}
/**
* Get url scheme
*
* @return string|null
*/
public function getScheme()
public function getScheme(): ?string
{
return $this->data['scheme'];
return $this->scheme;
}
/**
* Set the scheme of the url
*
* @param string $scheme
* @return static
*/
public function setScheme(string $scheme): self
{
$this->scheme = $scheme;
return $this;
}
/**
* Get url host
*
* @return string|null
*/
public function getHost()
public function getHost(): ?string
{
return $this->data['host'];
return $this->host;
}
/**
* Set the host of the url
*
* @param string $host
* @return static
*/
public function setHost(string $host): self
{
$this->host = $host;
return $this;
}
/**
* Get url port
*
* @return int|null
*/
public function getPort()
public function getPort(): ?int
{
return ($this->data['port'] !== null) ? (int)$this->data['port'] : null;
return ($this->port !== null) ? (int)$this->port : null;
}
/**
* Set the port of the url
*
* @param int $port
* @return static
*/
public function setPort(int $port): self
{
$this->port = $port;
return $this;
}
/**
* Parse username from url
*
* @return string|null
*/
public function getUserName()
public function getUsername(): ?string
{
return $this->data['user'];
return $this->username;
}
/**
* Set the username of the url
*
* @param string $username
* @return static
*/
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* Parse password from url
* @return string|null
*/
public function getPassword()
public function getPassword(): ?string
{
return $this->data['pass'];
return $this->password;
}
/**
* Set the url password
*
* @param string $password
* @return static
*/
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Get path from url
* @return string
*/
public function getPath()
public function getPath(): ?string
{
return $this->data['path'];
return $this->path ?? '/';
}
/**
* Get querystring from url
* @return string|null
* Set the url path
*
* @param string $path
* @return static
*/
public function getQueryString()
public function setPath(string $path): self
{
return $this->data['query'];
$this->path = rtrim($path, '/') . '/';
return $this;
}
/**
* Get query-string from url
*
* @return array
*/
public function getParams(): array
{
return $this->params;
}
/**
* Merge parameters array
*
* @param array $params
* @return static
*/
public function mergeParams(array $params): self
{
return $this->setParams(array_merge($this->getParams(), $params));
}
/**
* Set the url params
*
* @param array $params
* @return static
*/
public function setParams(array $params): self
{
$this->params = $params;
return $this;
}
/**
* Set raw query-string parameters as string
*
* @param string $queryString
* @return static
*/
public function setQueryString(string $queryString): self
{
$params = [];
if(parse_str($queryString, $params) !== false) {
return $this->setParams($params);
}
return $this;
}
/**
* Get query-string params as string
*
* @return string
*/
public function getQueryString(): string
{
return static::arrayToParams($this->getParams());
}
/**
* Get fragment from url (everything after #)
*
* @return string|null
*/
public function getFragment()
public function getFragment(): ?string
{
return $this->data['fragment'];
return $this->fragment;
}
/**
* Set url fragment
*
* @param string $fragment
* @return static
*/
public function setFragment(string $fragment): self
{
$this->fragment = $fragment;
return $this;
}
/**
* @return string
*/
public function getOriginalUrl()
public function getOriginalUrl(): string
{
return $this->originalUrl;
}
/**
* Get position of value.
* Returns -1 on failure.
*
* @param string $value
* @return int
*/
public function indexOf(string $value): int
{
$index = stripos($this->getOriginalUrl(), $value);
return ($index === false) ? -1 : $index;
}
/**
* Check if url contains value.
*
* @param string $value
* @return bool
*/
public function contains(string $value): bool
{
return (stripos($this->getOriginalUrl(), $value) !== false);
}
/**
* Check if url contains parameter/query string.
*
* @param string $name
* @return bool
*/
public function hasParam(string $name): bool
{
return array_key_exists($name, $this->getParams());
}
/**
* Removes multiple parameters from the query-string
*
* @param array ...$names
* @return static
*/
public function removeParams(...$names): self
{
$params = array_diff_key($this->getParams(), array_flip($names));
$this->setParams($params);
return $this;
}
/**
* Removes parameter from the query-string
*
* @param string $name
* @return static
*/
public function removeParam(string $name): self
{
$params = $this->getParams();
unset($params[$name]);
$this->setParams($params);
return $this;
}
/**
* Get parameter by name.
* Returns parameter value or default value.
*
* @param string $name
* @param string|null $defaultValue
* @return string|null
*/
public function getParam(string $name, ?string $defaultValue = null): ?string
{
return isset($this->getParams()[$name]) ?? $defaultValue;
}
/**
* UTF-8 aware parse_url() replacement.
* @param string $url
* @param int $component
* @throws MalformedUrlException
* @return array
* @throws MalformedUrlException
*/
public function parseUrl($url, $component = -1)
public function parseUrl(string $url, int $component = -1): array
{
$encodedUrl = preg_replace_callback(
'/[^:\/@?&=#]+/u',
@@ -152,24 +394,83 @@ class Url
$parts = parse_url($encodedUrl, $component);
if ($parts === false) {
throw new MalformedUrlException('Malformed URL: ' . $url);
throw new MalformedUrlException(sprintf('Failed to parse url: "%s"', $url));
}
return array_map('urldecode', $parts);
}
/**
* Returns data array with information about the url
* @return array
* Convert array to query-string params
*
* @param array $getParams
* @param bool $includeEmpty
* @return string
*/
public function getData()
public static function arrayToParams(array $getParams = [], bool $includeEmpty = true): string
{
return $this->data;
if (\count($getParams) !== 0) {
if ($includeEmpty === false) {
$getParams = array_filter($getParams, function ($item) {
return (trim($item) !== '');
});
}
return http_build_query($getParams);
}
return '';
}
public function __toString()
/**
* Returns the relative url
*
* @return string
*/
public function getRelativeUrl(): string
{
return $this->getOriginalUrl();
$params = $this->getQueryString();
$path = $this->path ?? '';
$query = $params !== '' ? '?' . $params : '';
$fragment = $this->fragment !== null ? '#' . $this->fragment : '';
return $path . $query . $fragment;
}
/**
* Returns the absolute url
*
* @return string
*/
public function getAbsoluteUrl(): string
{
$scheme = $this->scheme !== null ? $this->scheme . '://' : '';
$host = $this->host ?? '';
$port = $this->port !== null ? ':' . $this->port : '';
$user = $this->username ?? '';
$pass = $this->password !== null ? ':' . $this->password : '';
$pass = ($user || $pass) ? $pass . '@' : '';
return $scheme . $user . $pass . $host . $port . $this->getRelativeUrl();
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize(): string
{
return $this->getRelativeUrl();
}
public function __toString(): string
{
return $this->getRelativeUrl();
}
}
@@ -0,0 +1,118 @@
<?php
namespace Pecee\SimpleRouter\ClassLoader;
use DI\Container;
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
class ClassLoader implements IClassLoader
{
/**
* Dependency injection enabled
* @var bool
*/
protected $useDependencyInjection = false;
/**
* @var Container|null
*/
protected $container;
/**
* Load class
*
* @param string $class
* @return mixed
* @throws NotFoundHttpException
*/
public function loadClass(string $class)
{
if (class_exists($class) === false) {
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $class), 404);
}
if ($this->useDependencyInjection === true) {
$container = $this->getContainer();
if ($container !== null) {
try {
return $container->get($class);
} catch (\Exception $e) {
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
}
}
return new $class();
}
/**
* Load closure
*
* @param \Closure $closure
* @param array $parameters
* @return mixed
* @throws NotFoundHttpException
*/
public function loadClosure(\Closure $closure, array $parameters)
{
if ($this->useDependencyInjection === true) {
$container = $this->getContainer();
if ($container !== null) {
try {
return $container->call($closure, $parameters);
} catch (\Exception $e) {
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
}
}
return \call_user_func_array($closure, $parameters);
}
/**
* Get dependency injector container.
*
* @return Container|null
*/
public function getContainer(): ?Container
{
return $this->container;
}
/**
* Set the dependency-injector container.
*
* @param Container $container
* @return ClassLoader
*/
public function setContainer(Container $container): self
{
$this->container = $container;
return $this;
}
/**
* Enable or disable dependency injection.
*
* @param bool $enabled
* @return static
*/
public function useDependencyInjection(bool $enabled): self
{
$this->useDependencyInjection = $enabled;
return $this;
}
/**
* Return true if dependency injection is enabled.
*
* @return bool
*/
public function isDependencyInjectionEnabled(): bool
{
return $this->useDependencyInjection;
}
}
@@ -0,0 +1,12 @@
<?php
namespace Pecee\SimpleRouter\ClassLoader;
interface IClassLoader
{
public function loadClass(string $class);
public function loadClosure(\Closure $closure, array $parameters);
}
@@ -0,0 +1,111 @@
<?php
namespace Pecee\SimpleRouter\Event;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Router;
class EventArgument implements IEventArgument
{
/**
* Event name
* @var string
*/
protected $eventName;
/**
* @var Router
*/
protected $router;
/**
* @var array
*/
protected $arguments = [];
public function __construct($eventName, $router, array $arguments = [])
{
$this->eventName = $eventName;
$this->router = $router;
$this->arguments = $arguments;
}
/**
* Get event name
*
* @return string
*/
public function getEventName(): string
{
return $this->eventName;
}
/**
* Set the event name
*
* @param string $name
*/
public function setEventName(string $name): void
{
$this->eventName = $name;
}
/**
* Get the router instance
*
* @return Router
*/
public function getRouter(): Router
{
return $this->router;
}
/**
* Get the request instance
*
* @return Request
*/
public function getRequest(): Request
{
return $this->getRouter()->getRequest();
}
/**
* @param string $name
* @return mixed
*/
public function __get($name)
{
return $this->arguments[$name] ?? null;
}
/**
* @param string $name
* @return bool
*/
public function __isset($name)
{
return array_key_exists($name, $this->arguments);
}
/**
* @param string $name
* @param mixed $value
* @throws \InvalidArgumentException
*/
public function __set($name, $value)
{
throw new \InvalidArgumentException('Not supported');
}
/**
* Get arguments
*
* @return array
*/
public function getArguments(): array
{
return $this->arguments;
}
}
@@ -0,0 +1,46 @@
<?php
namespace Pecee\SimpleRouter\Event;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Router;
interface IEventArgument
{
/**
* Get event name
*
* @return string
*/
public function getEventName(): string;
/**
* Set event name
*
* @param string $name
*/
public function setEventName(string $name): void;
/**
* Get router instance
*
* @return Router
*/
public function getRouter(): Router;
/**
* Get request instance
*
* @return Request
*/
public function getRequest(): Request;
/**
* Get all event arguments
*
* @return array
*/
public function getArguments(): array;
}
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter\Exceptions;
class HttpException extends \Exception
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter\Exceptions;
class NotFoundHttpException extends HttpException
@@ -1,6 +1,6 @@
<?php
namespace Pecee\Handlers;
namespace Pecee\SimpleRouter\Handlers;
use Pecee\Http\Request;
@@ -10,7 +10,7 @@ use Pecee\Http\Request;
* Class is used to create callbacks which are fired when an exception is reached.
* This allows for easy handling 404-exception etc. without creating an custom ExceptionHandler.
*
* @package Pecee\Handlers
* @package \Pecee\SimpleRouter\Handlers
*/
class CallbackExceptionHandler implements IExceptionHandler
{
@@ -25,12 +25,11 @@ class CallbackExceptionHandler implements IExceptionHandler
/**
* @param Request $request
* @param \Exception $error
* @return Request|null
*/
public function handleError(Request $request, \Exception $error)
public function handleError(Request $request, \Exception $error): void
{
/* Fire exceptions */
return call_user_func($this->callback,
\call_user_func($this->callback,
$request,
$error
);
@@ -0,0 +1,62 @@
<?php
namespace Pecee\SimpleRouter\Handlers;
use Pecee\SimpleRouter\Event\EventArgument;
use Pecee\SimpleRouter\Router;
class DebugEventHandler implements IEventHandler
{
/**
* Debug callback
* @var \Closure
*/
protected $callback;
public function __construct()
{
$this->callback = function (EventArgument $argument) {
// todo: log in database
};
}
/**
* Get events.
*
* @param string|null $name Filter events by name.
* @return array
*/
public function getEvents(?string $name): array
{
return [
$name => [
$this->callback,
],
];
}
/**
* Fires any events registered with given event-name
*
* @param Router $router Router instance
* @param string $name Event name
* @param array $eventArgs Event arguments
*/
public function fireEvents(Router $router, string $name, array $eventArgs = []): void
{
$callback = $this->callback;
$callback(new EventArgument($router, $eventArgs));
}
/**
* Set debug callback
*
* @param \Closure $event
*/
public function setCallback(\Closure $event): void
{
$this->callback = $event;
}
}
@@ -0,0 +1,184 @@
<?php
namespace Pecee\SimpleRouter\Handlers;
use Pecee\SimpleRouter\Event\EventArgument;
use Pecee\SimpleRouter\Router;
class EventHandler implements IEventHandler
{
/**
* Fires when a event is triggered.
*/
public const EVENT_ALL = '*';
/**
* Fires when router is initializing and before routes are loaded.
*/
public const EVENT_INIT = 'onInit';
/**
* Fires when all routes has been loaded and rendered, just before the output is returned.
*/
public const EVENT_LOAD = 'onLoad';
/**
* Fires when route is added to the router
*/
public const EVENT_ADD_ROUTE = 'onAddRoute';
/**
* Fires when a url-rewrite is and just before the routes are re-initialized.
*/
public const EVENT_REWRITE = 'onRewrite';
/**
* Fires when the router is booting.
* This happens just before boot-managers are rendered and before any routes has been loaded.
*/
public const EVENT_BOOT = 'onBoot';
/**
* Fires before a boot-manager is rendered.
*/
public const EVENT_RENDER_BOOTMANAGER = 'onRenderBootManager';
/**
* Fires when the router is about to load all routes.
*/
public const EVENT_LOAD_ROUTES = 'onLoadRoutes';
/**
* Fires whenever the `findRoute` method is called within the `Router`.
* This usually happens when the router tries to find routes that
* contains a certain url, usually after the EventHandler::EVENT_GET_URL event.
*/
public const EVENT_FIND_ROUTE = 'onFindRoute';
/**
* Fires whenever the `Router::getUrl` method or `url`-helper function
* is called and the router tries to find the route.
*/
public const EVENT_GET_URL = 'onGetUrl';
/**
* Fires when a route is matched and valid (correct request-type etc).
* and before the route is rendered.
*/
public const EVENT_MATCH_ROUTE = 'onMatchRoute';
/**
* Fires before a route is rendered.
*/
public const EVENT_RENDER_ROUTE = 'onRenderRoute';
/**
* Fires when the router is loading exception-handlers.
*/
public const EVENT_LOAD_EXCEPTIONS = 'onLoadExceptions';
/**
* Fires before the router is rendering a exception-handler.
*/
public const EVENT_RENDER_EXCEPTION = 'onRenderException';
/**
* Fires before a middleware is rendered.
*/
public const EVENT_RENDER_MIDDLEWARES = 'onRenderMiddlewares';
/**
* Fires before the CSRF-verifier is rendered.
*/
public const EVENT_RENDER_CSRF = 'onRenderCsrfVerifier';
/**
* All available events
* @var array
*/
public static $events = [
self::EVENT_ALL,
self::EVENT_INIT,
self::EVENT_LOAD,
self::EVENT_ADD_ROUTE,
self::EVENT_REWRITE,
self::EVENT_BOOT,
self::EVENT_RENDER_BOOTMANAGER,
self::EVENT_LOAD_ROUTES,
self::EVENT_FIND_ROUTE,
self::EVENT_GET_URL,
self::EVENT_MATCH_ROUTE,
self::EVENT_RENDER_ROUTE,
self::EVENT_LOAD_EXCEPTIONS,
self::EVENT_RENDER_EXCEPTION,
self::EVENT_RENDER_MIDDLEWARES,
self::EVENT_RENDER_CSRF,
];
/**
* List of all registered events
* @var array
*/
private $registeredEvents = [];
/**
* Register new event
*
* @param string $name
* @param \Closure $callback
* @return static
*/
public function register(string $name, \Closure $callback): IEventHandler
{
if (isset($this->registeredEvents[$name]) === true) {
$this->registeredEvents[$name][] = $callback;
} else {
$this->registeredEvents[$name] = [$callback];
}
return $this;
}
/**
* Get events.
*
* @param string|null $name Filter events by name.
* @param array ...$names Add multiple names...
* @return array
*/
public function getEvents(?string $name, ...$names): array
{
if ($name === null) {
return $this->registeredEvents;
}
$names[] = $name;
$events = [];
foreach ($names as $eventName) {
if (isset($this->registeredEvents[$eventName]) === true) {
$events += $this->registeredEvents[$eventName];
}
}
return $events;
}
/**
* Fires any events registered with given event-name
*
* @param Router $router Router instance
* @param string $name Event name
* @param array $eventArgs Event arguments
*/
public function fireEvents(Router $router, string $name, array $eventArgs = []): void
{
$events = $this->getEvents(static::EVENT_ALL, $name);
/* @var $event \Closure */
foreach ($events as $event) {
$event(new EventArgument($name, $router, $eventArgs));
}
}
}
@@ -0,0 +1,27 @@
<?php
namespace Pecee\SimpleRouter\Handlers;
use Pecee\SimpleRouter\Router;
interface IEventHandler
{
/**
* Get events.
*
* @param string|null $name Filter events by name.
* @return array
*/
public function getEvents(?string $name): array;
/**
* Fires any events registered with given event-name
*
* @param Router $router Router instance
* @param string $name Event name
* @param array $eventArgs Event arguments
*/
public function fireEvents(Router $router, string $name, array $eventArgs = []): void;
}
@@ -1,5 +1,6 @@
<?php
namespace Pecee\Handlers;
namespace Pecee\SimpleRouter\Handlers;
use Pecee\Http\Request;
@@ -8,8 +9,7 @@ interface IExceptionHandler
/**
* @param Request $request
* @param \Exception $error
* @return Request|null
*/
public function handleError(Request $request, \Exception $error);
public function handleError(Request $request, \Exception $error): void;
}
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter;
use Pecee\Http\Request;
@@ -8,8 +9,8 @@ interface IRouterBootManager
/**
* Called when router loads it's routes
*
* @param Router $router
* @param Request $request
* @return Request
*/
public function boot(Request $request);
public function boot(Router $router, Request $request): void;
}
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter\Route;
interface IControllerRoute extends IRoute
@@ -8,7 +9,7 @@ interface IControllerRoute extends IRoute
*
* @return string
*/
public function getController();
public function getController(): string;
/**
* Set controller class-name
@@ -16,21 +17,6 @@ interface IControllerRoute extends IRoute
* @param string $controller
* @return static
*/
public function setController($controller);
/**
* Return active method
*
* @return string
*/
public function getMethod();
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod($method);
public function setController(string $controller): self;
}
+13 -13
View File
@@ -2,8 +2,8 @@
namespace Pecee\SimpleRouter\Route;
use Pecee\Handlers\IExceptionHandler;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Handlers\IExceptionHandler;
interface IGroupRoute extends IRoute
{
@@ -13,21 +13,21 @@ interface IGroupRoute extends IRoute
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request);
public function matchDomain(Request $request): bool;
/**
* Add exception handler
*
* @param IExceptionHandler|string $handler
* @return static $this;
* @return static
*/
public function addExceptionHandler($handler);
public function addExceptionHandler($handler): self;
/**
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
* @return static
*/
public function setExceptionHandlers(array $handlers);
@@ -36,35 +36,35 @@ interface IGroupRoute extends IRoute
*
* @return array
*/
public function getExceptionHandlers();
public function getExceptionHandlers(): array;
/**
* Get domains for domain.
*
* @return array
*/
public function getDomains();
public function getDomains(): array;
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
* @return static
*/
public function setDomains(array $domains);
public function setDomains(array $domains): self;
/**
* Set prefix that child-routes will inherit.
*
* @param string $prefix
* @return string
* @return static
*/
public function setPrefix($prefix);
public function setPrefix($prefix): self;
/**
* Get prefix.
*
* @return string
* @return string|null
*/
public function getPrefix();
public function getPrefix(): ?string;
}
+32 -13
View File
@@ -1,7 +1,9 @@
<?php
namespace Pecee\SimpleRouter\Route;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Router;
interface ILoadableRoute extends IRoute
{
@@ -10,29 +12,46 @@ interface ILoadableRoute extends IRoute
* Used when calling the url() helper.
*
* @param string|null $method
* @param array|null $parameters
* @param array|string|null $parameters
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null);
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string;
/**
* Loads and renders middlewares-classes
* Loads and renders middleware-classes
*
* @param Request $request
* @param Router $router
*/
public function loadMiddleware(Request $request);
public function loadMiddleware(Request $request, Router $router): void;
public function getUrl();
/**
* Get url
* @return string
*/
public function getUrl(): string;
public function setUrl($url);
/**
* Set url
* @param string $url
* @return static
*/
public function setUrl(string $url): self;
/**
* Prepend url
* @param string $url
* @return ILoadableRoute
*/
public function prependUrl(string $url): self;
/**
* Returns the provided name for the router.
*
* @return string
* @return string|null
*/
public function getName();
public function getName(): ?string;
/**
* Check if route has given name.
@@ -40,22 +59,22 @@ interface ILoadableRoute extends IRoute
* @param string $name
* @return bool
*/
public function hasName($name);
public function hasName(string $name): bool;
/**
* Sets the router name, which makes it easier to obtain the url or router at a later point.
*
* @param string $name
* @return static $this
* @return static
*/
public function setName($name);
public function setName(string $name): self;
/**
* Get regular expression match used for matching route (if defined).
*
* @return string
*/
public function getMatch();
public function getMatch(): ?string;
/**
* Add regular expression match for the entire route.
@@ -63,6 +82,6 @@ interface ILoadableRoute extends IRoute
* @param string $regex
* @return static
*/
public function setMatch($regex);
public function setMatch($regex): self;
}
+58 -36
View File
@@ -3,6 +3,7 @@
namespace Pecee\SimpleRouter\Route;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Router;
interface IRoute
{
@@ -13,17 +14,18 @@ interface IRoute
* @param Request $request
* @return bool
*/
public function matchRoute($route, Request $request);
public function matchRoute($route, Request $request): bool;
/**
* Called when route is matched.
* Returns class to be rendered.
*
* @param Request $request
* @param Router $router
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
* @return string
*/
public function renderRoute(Request $request);
public function renderRoute(Request $request, Router $router): ?string;
/**
* Returns callback name/identifier for the current route based on the callback.
@@ -32,50 +34,50 @@ interface IRoute
*
* @return string
*/
public function getIdentifier();
public function getIdentifier(): string;
/**
* Set allowed request methods
*
* @param array $methods
* @return static $this
* @return static
*/
public function setRequestMethods(array $methods);
public function setRequestMethods(array $methods): self;
/**
* Get allowed request methods
*
* @return array
*/
public function getRequestMethods();
public function getRequestMethods(): array;
/**
* @return IRoute|null
*/
public function getParent();
public function getParent(): ?IRoute;
/**
* Get the group for the route.
*
* @return IGroupRoute|null
*/
public function getGroup();
public function getGroup(): ?IGroupRoute;
/**
* Set group
*
* @param IGroupRoute $group
* @return static $this
* @return static
*/
public function setGroup(IGroupRoute $group);
public function setGroup(IGroupRoute $group): self;
/**
* Set parent route
*
* @param IRoute $parent
* @return static $this
* @return static
*/
public function setParent(IRoute $parent);
public function setParent(IRoute $parent): self;
/**
* Set callback
@@ -83,44 +85,64 @@ interface IRoute
* @param string $callback
* @return static
*/
public function setCallback($callback);
public function setCallback($callback): self;
/**
* @return string
* @return string|callable
*/
public function getCallback();
public function getMethod();
/**
* Return active method
*
* @return string|null
*/
public function getMethod(): ?string;
public function getClass();
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod(string $method): self;
public function setMethod($method);
/**
* Get class
*
* @return string|null
*/
public function getClass(): ?string;
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setNamespace($namespace);
public function setNamespace(string $namespace): self;
/**
* @return string
* @return string|null
*/
public function getNamespace();
public function getNamespace(): ?string;
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setDefaultNamespace($namespace);
public function setDefaultNamespace($namespace): IRoute;
public function getDefaultNamespace();
/**
* Get default namespace
* @return string|null
*/
public function getDefaultNamespace(): ?string;
/**
* Get parameter names.
*
* @return array
*/
public function getWhere();
public function getWhere(): array;
/**
* Set parameter names.
@@ -128,45 +150,45 @@ interface IRoute
* @param array $options
* @return static
*/
public function setWhere(array $options);
public function setWhere(array $options): self;
/**
* Get parameters
*
* @return array
*/
public function getParameters();
public function getParameters(): array;
/**
* Get parameters
*
* @param array $parameters
* @return static $this
* @return static
*/
public function setParameters(array $parameters);
public function setParameters(array $parameters): self;
/**
* Merge with information from another route.
*
* @param array $settings
* @param bool $merge
* @return static $this
* @return static
*/
public function setSettings(array $settings, $merge = false);
public function setSettings(array $settings, bool $merge = false): self;
/**
* Export route settings to array so they can be merged with another route.
*
* @return array
*/
public function toArray();
public function toArray(): array;
/**
* Get middlewares array
*
* @return array
*/
public function getMiddlewares();
public function getMiddlewares(): array;
/**
* Set middleware class-name
@@ -174,14 +196,14 @@ interface IRoute
* @param string $middleware
* @return static
*/
public function addMiddleware($middleware);
public function addMiddleware($middleware): self;
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
* @return static
*/
public function setMiddlewares(array $middlewares);
public function setMiddlewares(array $middlewares): self;
}
+45 -30
View File
@@ -5,6 +5,7 @@ namespace Pecee\SimpleRouter\Route;
use Pecee\Http\Middleware\IMiddleware;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Exceptions\HttpException;
use Pecee\SimpleRouter\Router;
abstract class LoadableRoute extends Route implements ILoadableRoute
{
@@ -24,25 +25,34 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* Loads and renders middlewares-classes
*
* @param Request $request
* @param Router $router
* @throws HttpException
*/
public function loadMiddleware(Request $request)
public function loadMiddleware(Request $request, Router $router): void
{
$router->debug('Loading middlewares');
foreach ($this->getMiddlewares() as $middleware) {
if (is_object($middleware) === false) {
$middleware = $this->loadClass($middleware);
if (\is_object($middleware) === false) {
$middleware = $router->getClassLoader()->loadClass($middleware);
}
if (($middleware instanceof IMiddleware) === false) {
throw new HttpException($middleware . ' must be inherit the IMiddleware interface');
}
$className = \get_class($middleware);
$router->debug('Loading middleware "%s"', $className);
$middleware->handle($request);
$router->debug('Finished loading middleware "%s"', $className);
}
$router->debug('Finished loading middlewares');
}
public function matchRegex(Request $request, $url)
public function matchRegex(Request $request, $url): ?bool
{
/* Match on custom defined regular expression */
@@ -59,7 +69,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $url
* @return static
*/
public function setUrl($url)
public function setUrl(string $url): ILoadableRoute
{
$this->url = ($url === '/') ? '/' : '/' . trim($url, '/') . '/';
@@ -75,7 +85,18 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
return $this;
}
public function getUrl()
/**
* Prepend url
*
* @param string $url
* @return ILoadableRoute
*/
public function prependUrl(string $url): ILoadableRoute
{
return $this->setUrl(rtrim($url, '/') . $this->url);
}
public function getUrl(): string
{
return $this->url;
}
@@ -89,19 +110,16 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null)
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string
{
$url = $this->getUrl();
$group = $this->getGroup();
if ($group !== null && count($group->getDomains()) !== 0) {
if ($group !== null && \count($group->getDomains()) !== 0) {
$url = '//' . $group->getDomains()[0] . $url;
}
/* Contains parameters that aren't recognized and will be appended at the end of the url */
$unknownParams = [];
/* Create the param string - {parameter} */
$param1 = $this->paramModifiers[0] . '%s' . $this->paramModifiers[1];
@@ -114,14 +132,14 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
foreach (array_keys($params) as $param) {
if ($parameters === '' || (is_array($parameters) === true && count($parameters) === 0)) {
if ($parameters === '' || (\is_array($parameters) === true && \count($parameters) === 0)) {
$value = '';
} else {
$p = (array)$parameters;
$value = array_key_exists($param, $p) ? $p[$param] : $params[$param];
/* If parameter is specifically set to null - use the original-defined value */
if ($value === null && isset($this->originalParameters[$param])) {
if ($value === null && isset($this->originalParameters[$param]) === true) {
$value = $this->originalParameters[$param];
}
}
@@ -130,13 +148,12 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
/* Add parameter to the correct position */
$url = str_ireplace([sprintf($param1, $param), sprintf($param2, $param)], $value, $url);
} else {
$unknownParams[$param] = $value;
/* Parameter aren't recognized and will be appended at the end of the url */
$url .= $value . '/';
}
}
$url = '/' . ltrim($url, '/') . implode('/', $unknownParams);
return rtrim($url, '/') . '/';
return rtrim('/' . ltrim($url, '/'), '/') . '/';
}
/**
@@ -144,7 +161,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*
* @return string
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -155,9 +172,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName(string $name): bool
{
return (strtolower($this->name) === strtolower($name));
return strtolower($this->name) === strtolower($name);
}
/**
@@ -166,7 +183,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $regex
* @return static
*/
public function setMatch($regex)
public function setMatch($regex): ILoadableRoute
{
$this->regex = $regex;
@@ -178,7 +195,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*
* @return string
*/
public function getMatch()
public function getMatch(): string
{
return $this->regex;
}
@@ -191,7 +208,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string|array $name
* @return static
*/
public function name($name)
public function name($name): ILoadableRoute
{
return $this->setName($name);
}
@@ -200,9 +217,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* Sets the router name, which makes it easier to obtain the url or router at a later point.
*
* @param string $name
* @return static $this
* @return static
*/
public function setName($name)
public function setName(string $name): ILoadableRoute
{
$this->name = $name;
@@ -216,7 +233,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, bool $merge = false): IRoute
{
if (isset($values['as']) === true) {
@@ -230,12 +247,10 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
}
if (isset($values['prefix']) === true) {
$this->setUrl($values['prefix'] . $this->getUrl());
$this->prependUrl($values['prefix']);
}
parent::setSettings($values, $merge);
return $this;
return parent::setSettings($values, $merge);
}
}
+97 -95
View File
@@ -5,18 +5,20 @@ namespace Pecee\SimpleRouter\Route;
use Pecee\Http\Middleware\IMiddleware;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
use Pecee\SimpleRouter\Router;
abstract class Route implements IRoute
{
const PARAMETERS_REGEX_FORMAT = '%s([\w]+)(\%s?)%s';
const PARAMETERS_DEFAULT_REGEX = '[\w]+';
protected const PARAMETERS_REGEX_FORMAT = '%s([\w]+)(\%s?)%s';
protected const PARAMETERS_DEFAULT_REGEX = '[\w]+';
const REQUEST_TYPE_GET = 'get';
const REQUEST_TYPE_POST = 'post';
const REQUEST_TYPE_PUT = 'put';
const REQUEST_TYPE_PATCH = 'patch';
const REQUEST_TYPE_OPTIONS = 'options';
const REQUEST_TYPE_DELETE = 'delete';
public const REQUEST_TYPE_GET = 'get';
public const REQUEST_TYPE_POST = 'post';
public const REQUEST_TYPE_PUT = 'put';
public const REQUEST_TYPE_PATCH = 'patch';
public const REQUEST_TYPE_OPTIONS = 'options';
public const REQUEST_TYPE_DELETE = 'delete';
public const REQUEST_TYPE_HEAD = 'head';
public static $requestTypes = [
self::REQUEST_TYPE_GET,
@@ -25,6 +27,7 @@ abstract class Route implements IRoute
self::REQUEST_TYPE_PATCH,
self::REQUEST_TYPE_OPTIONS,
self::REQUEST_TYPE_DELETE,
self::REQUEST_TYPE_HEAD,
];
/**
@@ -56,40 +59,31 @@ abstract class Route implements IRoute
protected $originalParameters = [];
protected $middlewares = [];
/**
* Load class by name
* @param string $name
* @return mixed
* @throws NotFoundHttpException
*/
protected function loadClass($name)
{
if (class_exists($name) === false) {
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $name), 404);
}
return new $name();
}
/**
* Render route
*
* @param Request $request
* @return string|mixed
* @param Router $router
* @return string|null
* @throws NotFoundHttpException
*/
public function renderRoute(Request $request)
public function renderRoute(Request $request, Router $router): ?string
{
$router->debug('Starting rendering route "%s"', \get_class($this));
$callback = $this->getCallback();
if ($callback === null) {
return null;
}
$router->debug('Parsing parameters');
$parameters = $this->getParameters();
/* Filter parameters with null-value */
$router->debug('Finished parsing parameters');
/* Filter parameters with null-value */
if ($this->filterEmptyParams === true) {
$parameters = array_filter($parameters, function ($var) {
return ($var !== null);
@@ -97,9 +91,12 @@ abstract class Route implements IRoute
}
/* Render callback function */
if (is_callable($callback) === true) {
if (\is_callable($callback) === true) {
$router->debug('Executing callback');
/* When the callback is a function */
return call_user_func_array($callback, $parameters);
return $router->getClassLoader()->loadClosure($callback, $parameters);
}
/* When the callback is a class + method */
@@ -109,36 +106,45 @@ abstract class Route implements IRoute
$className = ($namespace !== null && $controller[0][0] !== '\\') ? $namespace . '\\' . $controller[0] : $controller[0];
$class = $this->loadClass($className);
$router->debug('Loading class %s', $className);
$class = $router->getClassLoader()->loadClass($className);
$method = $controller[1];
if (method_exists($class, $method) === false) {
throw new NotFoundHttpException(sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404);
}
return call_user_func_array([$class, $method], $parameters);
$router->debug('Executing callback');
return \call_user_func_array([$class, $method], $parameters);
}
protected function parseParameters($route, $url, $parameterRegex = null)
{
$regex = sprintf(static::PARAMETERS_REGEX_FORMAT, $this->paramModifiers[0], $this->paramOptionalSymbol, $this->paramModifiers[1]);
$regex = (strpos($route, $this->paramModifiers[0]) === false) ? null :
sprintf
(
static::PARAMETERS_REGEX_FORMAT,
$this->paramModifiers[0],
$this->paramOptionalSymbol,
$this->paramModifiers[1]
);
// Ensures that host names/domains will work with parameters
$url = '/' . ltrim($url, '/');
$urlRegex = '';
$parameters = [];
// Ensures that hostnames/domains will work with parameters
$url = '/' . ltrim($url, '/');
if ((bool)preg_match_all('/' . $regex . '/u', $route, $parameters) === false) {
if ($regex === null || (bool)preg_match_all('/' . $regex . '/u', $route, $parameters) === false) {
$urlRegex = preg_quote($route, '/');
} else {
$urlParts = preg_split('/((\-?\/?)\{[^}]+\})/', $route);
foreach ($urlParts as $key => $t) {
foreach (preg_split('/((\-?\/?)\{[^}]+\})/', $route) as $key => $t) {
$regex = '';
if ($key < count($parameters[1])) {
if ($key < \count($parameters[1])) {
$name = $parameters[1][$key];
@@ -151,21 +157,18 @@ abstract class Route implements IRoute
if ($parameterRegex !== null) {
$regex = $parameterRegex;
} else {
$regex = ($this->defaultParameterRegex === null) ? static::PARAMETERS_DEFAULT_REGEX : $this->defaultParameterRegex;
$regex = $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
}
$regex = sprintf('(?:\/|\-)%1$s(?P<%2$s>%3$s)%1$s', $parameters[2][$key], $name, $regex);
}
$urlParts[$key] = preg_quote($t, '/') . $regex;
$urlRegex .= preg_quote($t, '/') . $regex;
}
$urlRegex = implode('', $urlParts);
}
if ((bool)preg_match(sprintf($this->urlRegex, $urlRegex), $url, $matches) === false) {
if (trim($urlRegex) === '' || (bool)preg_match(sprintf($this->urlRegex, $urlRegex), $url, $matches) === false) {
return null;
}
@@ -175,7 +178,7 @@ abstract class Route implements IRoute
/* Only take matched parameters with name */
foreach ((array)$parameters[1] as $name) {
$values[$name] = (isset($matches[$name]) && $matches[$name] !== '') ? $matches[$name] : null;
$values[$name] = (isset($matches[$name]) === true && $matches[$name] !== '') ? $matches[$name] : null;
}
}
@@ -189,22 +192,22 @@ abstract class Route implements IRoute
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): string
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
return $this->callback;
}
return 'function_' . md5($this->callback);
return 'function:' . md5($this->callback);
}
/**
* Set allowed request methods
*
* @param array $methods
* @return static $this
* @return static
*/
public function setRequestMethods(array $methods)
public function setRequestMethods(array $methods): IRoute
{
$this->requestMethods = $methods;
@@ -216,7 +219,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getRequestMethods()
public function getRequestMethods(): array
{
return $this->requestMethods;
}
@@ -224,7 +227,7 @@ abstract class Route implements IRoute
/**
* @return IRoute|null
*/
public function getParent()
public function getParent(): ?IRoute
{
return $this->parent;
}
@@ -234,7 +237,7 @@ abstract class Route implements IRoute
*
* @return IGroupRoute|null
*/
public function getGroup()
public function getGroup(): ?IGroupRoute
{
return $this->group;
}
@@ -243,25 +246,24 @@ abstract class Route implements IRoute
* Set group
*
* @param IGroupRoute $group
* @return static $this
* @return static
*/
public function setGroup(IGroupRoute $group)
public function setGroup(IGroupRoute $group): IRoute
{
$this->group = $group;
/* Add/merge parent settings with child */
$this->setSettings($group->toArray(), true);
return $this;
return $this->setSettings($group->toArray(), true);
}
/**
* Set parent route
*
* @param IRoute $parent
* @return static $this
* @return static
*/
public function setParent(IRoute $parent)
public function setParent(IRoute $parent): IRoute
{
$this->parent = $parent;
@@ -274,7 +276,7 @@ abstract class Route implements IRoute
* @param string $callback
* @return static
*/
public function setCallback($callback)
public function setCallback($callback): IRoute
{
$this->callback = $callback;
@@ -282,16 +284,16 @@ abstract class Route implements IRoute
}
/**
* @return string
* @return string|callable
*/
public function getCallback()
{
return $this->callback;
}
public function getMethod()
public function getMethod(): ?string
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
$tmp = explode('@', $this->callback);
return $tmp[1];
@@ -300,9 +302,9 @@ abstract class Route implements IRoute
return null;
}
public function getClass()
public function getClass(): ?string
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
$tmp = explode('@', $this->callback);
return $tmp[0];
@@ -311,14 +313,14 @@ abstract class Route implements IRoute
return null;
}
public function setMethod($method)
public function setMethod(string $method): IRoute
{
$this->callback = sprintf('%s@%s', $this->getClass(), $method);
return $this;
}
public function setClass($class)
public function setClass(string $class): IRoute
{
$this->callback = sprintf('%s@%s', $class, $this->getMethod());
@@ -327,9 +329,9 @@ abstract class Route implements IRoute
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setNamespace($namespace)
public function setNamespace(string $namespace): IRoute
{
$this->namespace = $namespace;
@@ -338,26 +340,26 @@ abstract class Route implements IRoute
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setDefaultNamespace($namespace)
public function setDefaultNamespace($namespace): IRoute
{
$this->defaultNamespace = $namespace;
return $this;
}
public function getDefaultNamespace()
public function getDefaultNamespace(): ?string
{
return $this->defaultNamespace;
}
/**
* @return string
* @return string|null
*/
public function getNamespace()
public function getNamespace(): ?string
{
return ($this->namespace === null) ? $this->defaultNamespace : $this->namespace;
return $this->namespace ?? $this->defaultNamespace;
}
/**
@@ -365,7 +367,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function toArray()
public function toArray(): array
{
$values = [];
@@ -373,15 +375,15 @@ abstract class Route implements IRoute
$values['namespace'] = $this->namespace;
}
if (count($this->requestMethods) !== 0) {
if (\count($this->requestMethods) !== 0) {
$values['method'] = $this->requestMethods;
}
if (count($this->where) !== 0) {
if (\count($this->where) !== 0) {
$values['where'] = $this->where;
}
if (count($this->middlewares) !== 0) {
if (\count($this->middlewares) !== 0) {
$values['middleware'] = $this->middlewares;
}
@@ -397,9 +399,9 @@ abstract class Route implements IRoute
*
* @param array $values
* @param bool $merge
* @return static $this
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, bool $merge = false): IRoute
{
if ($this->namespace === null && isset($values['namespace']) === true) {
$this->setNamespace($values['namespace']);
@@ -434,7 +436,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getWhere()
public function getWhere(): array
{
return $this->where;
}
@@ -445,7 +447,7 @@ abstract class Route implements IRoute
* @param array $options
* @return static
*/
public function setWhere(array $options)
public function setWhere(array $options): IRoute
{
$this->where = $options;
@@ -470,12 +472,12 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getParameters()
public function getParameters(): array
{
/* Sort the parameters after the user-defined param order, if any */
$parameters = [];
if (count($this->originalParameters) !== 0) {
if (\count($this->originalParameters) !== 0) {
$parameters = $this->originalParameters;
}
@@ -486,15 +488,15 @@ abstract class Route implements IRoute
* Get parameters
*
* @param array $parameters
* @return static $this
* @return static
*/
public function setParameters(array $parameters)
public function setParameters(array $parameters): IRoute
{
/*
* If this is the first time setting parameters we store them so we
* later can organize the array, in case somebody tried to sort the array.
*/
if (count($parameters) !== 0 && count($this->originalParameters) === 0) {
if (\count($parameters) !== 0 && \count($this->originalParameters) === 0) {
$this->originalParameters = $parameters;
}
@@ -523,7 +525,7 @@ abstract class Route implements IRoute
* @param IMiddleware|string $middleware
* @return static
*/
public function addMiddleware($middleware)
public function addMiddleware($middleware): IRoute
{
$this->middlewares[] = $middleware;
@@ -534,9 +536,9 @@ abstract class Route implements IRoute
* Set middlewares array
*
* @param array $middlewares
* @return $this
* @return static
*/
public function setMiddlewares(array $middlewares)
public function setMiddlewares(array $middlewares): IRoute
{
$this->middlewares = $middlewares;
@@ -546,7 +548,7 @@ abstract class Route implements IRoute
/**
* @return array
*/
public function getMiddlewares()
public function getMiddlewares(): array
{
return $this->middlewares;
}
@@ -556,7 +558,7 @@ abstract class Route implements IRoute
* This is used when no custom parameter regex is found.
*
* @param string $regex
* @return static $this
* @return static
*/
public function setDefaultParameterRegex($regex)
{
@@ -570,7 +572,7 @@ abstract class Route implements IRoute
*
* @return string
*/
public function getDefaultParameterRegex()
public function getDefaultParameterRegex(): string
{
return $this->defaultParameterRegex;
}
@@ -24,7 +24,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName(string $name): bool
{
if ($this->name === null) {
return false;
@@ -35,7 +35,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
$method = substr($name, strrpos($name, '.') + 1);
$newName = substr($name, 0, strrpos($name, '.'));
if (in_array($method, $this->names, false) === true && strtolower($this->name) === strtolower($newName)) {
if (\in_array($method, $this->names, true) === true && strtolower($this->name) === strtolower($newName)) {
return true;
}
}
@@ -49,7 +49,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null)
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string
{
if (strpos($name, '.') !== false) {
$found = array_search(substr($name, strrpos($name, '.') + 1), $this->names, false);
@@ -67,7 +67,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
foreach (static::$requestTypes as $requestType) {
if (stripos($method, $requestType) === 0) {
$method = (string)substr($method, strlen($requestType));
$method = (string)substr($method, \strlen($requestType));
break;
}
}
@@ -77,7 +77,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
$group = $this->getGroup();
if ($group !== null && count($group->getDomains()) !== 0) {
if ($group !== null && \count($group->getDomains()) !== 0) {
$url .= '//' . $group->getDomains()[0];
}
@@ -86,28 +86,28 @@ class RouteController extends LoadableRoute implements IControllerRoute
return '/' . trim($url, '/') . '/';
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
/* Match global regular-expression for route */
$regexMatch = $this->matchRegex($request, $url);
if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtolower($url) !== strtolower($this->url))) {
if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtoupper($url) !== strtoupper($this->url))) {
return false;
}
$strippedUrl = trim(str_ireplace($this->url, '/', $url), '/');
$path = explode('/', $strippedUrl);
if (count($path) !== 0) {
if (\count($path) !== 0) {
$method = (isset($path[0]) === false || trim($path[0]) === '') ? $this->defaultMethod : $path[0];
$this->method = $request->getMethod() . ucfirst($method);
$this->parameters = array_slice($path, 1);
$this->parameters = \array_slice($path, 1);
// Set callback
$this->setCallback($this->controller . '@' . $this->method);
@@ -123,7 +123,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
*
* @return string
*/
public function getController()
public function getController(): string
{
return $this->controller;
}
@@ -134,7 +134,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $controller
* @return static
*/
public function setController($controller)
public function setController(string $controller): IControllerRoute
{
$this->controller = $controller;
@@ -144,9 +144,9 @@ class RouteController extends LoadableRoute implements IControllerRoute
/**
* Return active method
*
* @return string
* @return string|null
*/
public function getMethod()
public function getMethod(): ?string
{
return $this->method;
}
@@ -157,7 +157,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $method
* @return static
*/
public function setMethod($method)
public function setMethod(string $method): IRoute
{
$this->method = $method;
@@ -171,15 +171,13 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, bool $merge = false): IRoute
{
if (isset($values['names']) === true) {
$this->names = $values['names'];
}
parent::setSettings($values, $merge);
return $this;
return parent::setSettings($values, $merge);
}
}
+21 -23
View File
@@ -2,8 +2,8 @@
namespace Pecee\SimpleRouter\Route;
use Pecee\Handlers\IExceptionHandler;
use Pecee\Http\Request;
use Pecee\SimpleRouter\Handlers\IExceptionHandler;
class RouteGroup extends Route implements IGroupRoute
{
@@ -18,9 +18,9 @@ class RouteGroup extends Route implements IGroupRoute
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request)
public function matchDomain(Request $request): bool
{
if ($this->domains === null || count($this->domains) === 0) {
if ($this->domains === null || \count($this->domains) === 0) {
return true;
}
@@ -28,7 +28,7 @@ class RouteGroup extends Route implements IGroupRoute
$parameters = $this->parseParameters($domain, $request->getHost(), '.*');
if ($parameters !== null && count($parameters) !== 0) {
if ($parameters !== null && \count($parameters) !== 0) {
$this->parameters = $parameters;
@@ -46,9 +46,9 @@ class RouteGroup extends Route implements IGroupRoute
* @param Request $request
* @return bool
*/
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
@@ -64,9 +64,9 @@ class RouteGroup extends Route implements IGroupRoute
* Add exception handler
*
* @param IExceptionHandler|string $handler
* @return static $this
* @return static
*/
public function addExceptionHandler($handler)
public function addExceptionHandler($handler): IGroupRoute
{
$this->exceptionHandlers[] = $handler;
@@ -77,9 +77,9 @@ class RouteGroup extends Route implements IGroupRoute
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
* @return static
*/
public function setExceptionHandlers(array $handlers)
public function setExceptionHandlers(array $handlers): IGroupRoute
{
$this->exceptionHandlers = $handlers;
@@ -91,7 +91,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function getExceptionHandlers()
public function getExceptionHandlers(): array
{
return $this->exceptionHandlers;
}
@@ -101,7 +101,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function getDomains()
public function getDomains(): array
{
return $this->domains;
}
@@ -110,9 +110,9 @@ class RouteGroup extends Route implements IGroupRoute
* Set allowed domains for group.
*
* @param array $domains
* @return $this
* @return static
*/
public function setDomains(array $domains)
public function setDomains(array $domains): IGroupRoute
{
$this->domains = $domains;
@@ -123,7 +123,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param string $prefix
* @return static
*/
public function setPrefix($prefix)
public function setPrefix($prefix): IGroupRoute
{
$this->prefix = '/' . trim($prefix, '/');
@@ -133,9 +133,9 @@ class RouteGroup extends Route implements IGroupRoute
/**
* Set prefix that child-routes will inherit.
*
* @return string
* @return string|null
*/
public function getPrefix()
public function getPrefix(): ?string
{
return $this->prefix;
}
@@ -147,7 +147,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, bool $merge = false): IRoute
{
if (isset($values['prefix']) === true) {
@@ -173,9 +173,7 @@ class RouteGroup extends Route implements IGroupRoute
$this->name = $name;
}
parent::setSettings($values, $merge);
return $this;
return parent::setSettings($values, $merge);
}
/**
@@ -183,7 +181,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function toArray()
public function toArray(): array
{
$values = [];
@@ -195,7 +193,7 @@ class RouteGroup extends Route implements IGroupRoute
$values['as'] = $this->name;
}
if (count($this->parameters) !== 0) {
if (\count($this->parameters) !== 0) {
$values['parameters'] = $this->parameters;
}
@@ -6,7 +6,14 @@ use Pecee\Http\Request;
class RoutePartialGroup extends RouteGroup implements IPartialGroupRoute
{
protected $urlRegex = '/^%s\/?/u';
/**
* RoutePartialGroup constructor.
*/
public function __construct()
{
$this->urlRegex = '/^%s\/?/u';
}
/**
* Method called to check if route matches
@@ -15,12 +22,12 @@ class RoutePartialGroup extends RouteGroup implements IPartialGroupRoute
* @param Request $request
* @return bool
*/
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
if ($this->prefix !== null) {
/* Parse parameters from current route */
$parameters = $this->parseParameters($this->prefix, $url);
+19 -15
View File
@@ -42,7 +42,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName(string $name): bool
{
if ($this->name === null) {
return false;
@@ -60,7 +60,13 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return (strtolower($this->name) === strtolower($name));
}
public function findUrl($method = null, $parameters = null, $name = null)
/**
* @param string|null $method
* @param array|string|null $parameters
* @param string|null $name
* @return string
*/
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string
{
$url = array_search($name, $this->names, false);
if ($url !== false) {
@@ -77,16 +83,16 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return true;
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
/* Match global regular-expression for route */
$regexMatch = $this->matchRegex($request, $url);
if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtolower($url) !== strtolower($this->url))) {
if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtoupper($url) !== strtoupper($this->url))) {
return false;
}
@@ -114,7 +120,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
}
// Update
if ($id !== null && in_array($method, [static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT], false) === true) {
if ($id !== null && \in_array($method, [static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT], true) === true) {
return $this->call($this->methodNames['update']);
}
@@ -145,7 +151,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/**
* @return string
*/
public function getController()
public function getController(): string
{
return $this->controller;
}
@@ -154,14 +160,14 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param string $controller
* @return static
*/
public function setController($controller)
public function setController(string $controller): IControllerRoute
{
$this->controller = $controller;
return $this;
}
public function setName($name)
public function setName(string $name): ILoadableRoute
{
$this->name = $name;
@@ -194,9 +200,9 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/**
* Get method names
*
* @return array $this
* @return array
*/
public function getMethodNames()
public function getMethodNames(): array
{
return $this->methodNames;
}
@@ -208,7 +214,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, bool $merge = false): IRoute
{
if (isset($values['names']) === true) {
$this->names = $values['names'];
@@ -218,9 +224,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
$this->methodNames = $values['methods'];
}
parent::setSettings($values, $merge);
return $this;
return parent::setSettings($values, $merge);
}
}
+2 -2
View File
@@ -12,9 +12,9 @@ class RouteUrl extends LoadableRoute
$this->setCallback($callback);
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
+454 -148
View File
@@ -3,11 +3,17 @@
namespace Pecee\SimpleRouter;
use Pecee\Exceptions\InvalidArgumentException;
use Pecee\Handlers\IExceptionHandler;
use Pecee\Http\Exceptions\MalformedUrlException;
use Pecee\Http\Middleware\BaseCsrfVerifier;
use Pecee\Http\Request;
use Pecee\Http\Url;
use Pecee\SimpleRouter\ClassLoader\ClassLoader;
use Pecee\SimpleRouter\ClassLoader\IClassLoader;
use Pecee\SimpleRouter\Exceptions\HttpException;
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
use Pecee\SimpleRouter\Handlers\EventHandler;
use Pecee\SimpleRouter\Handlers\IEventHandler;
use Pecee\SimpleRouter\Handlers\IExceptionHandler;
use Pecee\SimpleRouter\Route\IControllerRoute;
use Pecee\SimpleRouter\Route\IGroupRoute;
use Pecee\SimpleRouter\Route\ILoadableRoute;
@@ -27,32 +33,32 @@ class Router
* Defines if a route is currently being processed.
* @var bool
*/
protected $processingRoute;
protected $isProcessingRoute;
/**
* All added routes
* @var array
*/
protected $routes;
protected $routes = [];
/**
* List of processed routes
* @var array
*/
protected $processedRoutes;
protected $processedRoutes = [];
/**
* Stack of routes used to keep track of sub-routes added
* when a route is being processed.
* @var array
*/
protected $routeStack;
protected $routeStack = [];
/**
* List of added bootmanagers
* @var array
*/
protected $bootManagers;
protected $bootManagers = [];
/**
* Csrf verifier class
@@ -64,11 +70,48 @@ class Router
* Get exception handlers
* @var array
*/
protected $exceptionHandlers;
protected $exceptionHandlers = [];
/**
* List of loaded exception that has been loaded.
* Used to ensure that exception-handlers aren't loaded twice when rewriting route.
*
* @var array
*/
protected $loadedExceptionHandlers = [];
/**
* Enable or disabled debugging
* @var bool
*/
protected $debugEnabled = false;
/**
* The start time used when debugging is enabled
* @var float
*/
protected $debugStartTime;
/**
* List containing all debug messages
* @var array
*/
protected $debugList = [];
/**
* Contains any registered event-handler.
* @var array
*/
protected $eventHandlers = [];
/**
* Class loader instance
* @var ClassLoader
*/
protected $classLoader;
/**
* Router constructor.
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public function __construct()
{
@@ -76,17 +119,29 @@ class Router
}
/**
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* Resets the router by reloading request and clearing all routes and data.
*/
public function reset()
public function reset(): void
{
$this->processingRoute = false;
$this->request = new Request();
$this->debugStartTime = microtime(true);
$this->isProcessingRoute = false;
try {
$this->request = new Request();
} catch (MalformedUrlException $e) {
$this->debug(sprintf('Invalid request-uri url: %s', $e->getMessage()));
}
$this->routes = [];
$this->bootManagers = [];
$this->routeStack = [];
$this->processedRoutes = [];
$this->exceptionHandlers = [];
$this->loadedExceptionHandlers = [];
$this->eventHandlers = [];
$this->debugList = [];
$this->csrfVerifier = null;
$this->classLoader = new ClassLoader();
}
/**
@@ -94,18 +149,22 @@ class Router
* @param IRoute $route
* @return IRoute
*/
public function addRoute(IRoute $route)
public function addRoute(IRoute $route): IRoute
{
$this->fireEvents(EventHandler::EVENT_ADD_ROUTE, [
'route' => $route,
]);
/*
* If a route is currently being processed, that means that the route being added are rendered from the parent
* routes callback, so we add them to the stack instead.
*/
if ($this->processingRoute === true) {
if ($this->isProcessingRoute === true) {
$this->routeStack[] = $route;
return $route;
} else {
$this->routes[] = $route;
}
$this->routes[] = $route;
return $route;
}
@@ -115,13 +174,14 @@ class Router
* @param IRoute $route
* @throws NotFoundHttpException
*/
protected function renderAndProcess(IRoute $route) {
protected function renderAndProcess(IRoute $route): void
{
$this->processingRoute = true;
$route->renderRoute($this->request);
$this->processingRoute = false;
$this->isProcessingRoute = true;
$route->renderRoute($this->request, $this);
$this->isProcessingRoute = false;
if (count($this->routeStack) !== 0) {
if (\count($this->routeStack) !== 0) {
/* Pop and grab the routes added when executing group callback earlier */
$stack = $this->routeStack;
@@ -139,21 +199,27 @@ class Router
* @param IGroupRoute|null $group
* @throws NotFoundHttpException
*/
protected function processRoutes(array $routes, IGroupRoute $group = null)
protected function processRoutes(array $routes, ?IGroupRoute $group = null): void
{
$this->debug('Processing routes');
// Loop through each route-request
$exceptionHandlers = [];
// Stop processing routes if no valid route is found.
if($this->request->getRewriteRoute() === null && $this->request->getUrl() === null) {
if ($this->request->getRewriteRoute() === null && $this->request->getUrl() === null) {
$this->debug('Halted route-processing as no valid route was found');
return;
}
$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUrl()->getPath();
$url = $this->request->getRewriteUrl() ?? $this->request->getUrl()->getPath();
/* @var $route IRoute */
foreach ($routes as $route) {
$this->debug('Processing route "%s"', \get_class($route));
if ($group !== null) {
/* Add the parent group */
$route->setGroup($group);
@@ -165,7 +231,7 @@ class Router
if ($route->matchRoute($url, $this->request) === true) {
/* Add exception handlers */
if (count($route->getExceptionHandlers()) !== 0) {
if (\count($route->getExceptionHandlers()) !== 0) {
/** @noinspection AdditionOperationOnArraysInspection */
$exceptionHandlers += $route->getExceptionHandlers();
}
@@ -199,81 +265,143 @@ class Router
* @throws NotFoundHttpException
* @return void
*/
public function loadRoutes()
public function loadRoutes(): void
{
$this->debug('Loading routes');
$this->fireEvents(EventHandler::EVENT_BOOT, [
'bootmanagers' => $this->bootManagers,
]);
/* Initialize boot-managers */
/* @var $manager IRouterBootManager */
foreach ($this->bootManagers as $manager) {
$manager->boot($this->request);
$className = \get_class($manager);
$this->debug('Rendering bootmanager "%s"', $className);
$this->fireEvents(EventHandler::EVENT_RENDER_BOOTMANAGER, [
'bootmanagers' => $this->bootManagers,
'bootmanager' => $manager,
]);
/* Render bootmanager */
$manager->boot($this, $this->request);
$this->debug('Finished rendering bootmanager "%s"', $className);
}
$this->fireEvents(EventHandler::EVENT_LOAD_ROUTES, [
'routes' => $this->routes,
]);
/* Loop through each route-request */
$this->processRoutes($this->routes);
$this->debug('Finished loading routes');
}
/**
* Start the routing
*
* @return string|null
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
* @throws \Pecee\Http\Middleware\Exceptions\TokenMismatchException
* @throws HttpException
* @throws \Exception
*/
public function start(): ?string
{
$this->debug('Router starting');
$this->fireEvents(EventHandler::EVENT_INIT);
$this->loadRoutes();
if ($this->csrfVerifier !== null) {
$this->fireEvents(EventHandler::EVENT_RENDER_CSRF, [
'csrfVerifier' => $this->csrfVerifier,
]);
/* Verify csrf token for request */
$this->csrfVerifier->handle($this->request);
}
$output = $this->routeRequest();
$this->fireEvents(EventHandler::EVENT_LOAD, [
'loadedRoutes' => $this->getRequest()->getLoadedRoutes(),
]);
$this->debug('Routing complete');
return $output;
}
/**
* Routes the request
*
* @param bool $rewrite
* @return string|mixed
* @return string|null
* @throws HttpException
* @throws \Exception
*/
public function routeRequest($rewrite = false)
public function routeRequest(): ?string
{
$routeNotAllowed = false;
$this->debug('Routing request');
$methodNotAllowed = false;
try {
if ($rewrite === false) {
$this->loadRoutes();
if ($this->csrfVerifier !== null) {
/* Verify csrf token for request */
$this->csrfVerifier->handle($this->request);
}
} else {
$this->request->setHasRewrite(false);
}
$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUrl()->getPath();
$url = $this->request->getRewriteUrl() ?? $this->request->getUrl()->getPath();
/* @var $route ILoadableRoute */
foreach ($this->processedRoutes as $key => $route) {
$this->debug('Matching route "%s"', \get_class($route));
/* If the route matches */
if ($route->matchRoute($url, $this->request) === true) {
$this->fireEvents(EventHandler::EVENT_MATCH_ROUTE, [
'route' => $route,
]);
/* Check if request method matches */
if (count($route->getRequestMethods()) !== 0 && in_array($this->request->getMethod(), $route->getRequestMethods(), false) === false) {
$routeNotAllowed = true;
if (\count($route->getRequestMethods()) !== 0 && \in_array($this->request->getMethod(), $route->getRequestMethods(), true) === false) {
$this->debug('Method "%s" not allowed', $this->request->getMethod());
$methodNotAllowed = true;
continue;
}
$route->loadMiddleware($this->request);
$this->fireEvents(EventHandler::EVENT_RENDER_MIDDLEWARES, [
'route' => $route,
'middlewares' => $route->getMiddlewares(),
]);
if ($this->hasRewrite($url) === true) {
unset($this->processedRoutes[$key]);
return $this->routeRequest(true);
}
/* Render route */
$routeNotAllowed = false;
$this->request->setLoadedRoute($route);
$output = $route->renderRoute($this->request);
$route->loadMiddleware($this->request, $this);
$output = $this->handleRouteRewrite($key, $url);
if ($output !== null) {
return $output;
}
if ($this->hasRewrite($url) === true) {
unset($this->processedRoutes[$key]);
$methodNotAllowed = false;
return $this->routeRequest(true);
$this->request->addLoadedRoute($route);
$this->fireEvents(EventHandler::EVENT_RENDER_ROUTE, [
'route' => $route,
]);
$output = $route->renderRoute($this->request, $this);
if ($output !== null) {
return $output;
}
$output = $this->handleRouteRewrite($key, $url);
if ($output !== null) {
return $output;
}
}
}
@@ -282,12 +410,12 @@ class Router
$this->handleException($e);
}
if ($routeNotAllowed === true) {
if ($methodNotAllowed === true) {
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
$this->handleException(new HttpException($message, 403));
$this->handleException(new NotFoundHttpException($message, 403));
}
if ($this->request->getLoadedRoute() === null) {
if (\count($this->request->getLoadedRoutes()) === 0) {
$rewriteUrl = $this->request->getRewriteUrl();
@@ -297,136 +425,186 @@ class Router
$message = sprintf('Route not found: "%s"', $this->request->getUrl()->getPath());
}
$this->handleException(new NotFoundHttpException($message, 404));
$this->debug($message);
return $this->handleException(new NotFoundHttpException($message, 404));
}
return null;
}
protected function hasRewrite($url)
/**
* Handle route-rewrite
*
* @param string $key
* @param string $url
* @return string|null
* @throws HttpException
* @throws \Exception
*/
protected function handleRouteRewrite($key, string $url): ?string
{
/* If the request has changed */
if ($this->request->hasRewrite() === true) {
if ($this->request->getRewriteRoute() !== null) {
/* Render rewrite-route */
$this->processedRoutes[] = $this->request->getRewriteRoute();
return true;
}
if ($this->request->isRewrite($url) === false) {
/* Render rewrite-url */
$this->processedRoutes = array_values($this->processedRoutes);
return true;
}
if ($this->request->hasPendingRewrite() === false) {
return null;
}
return false;
$route = $this->request->getRewriteRoute();
if ($route !== null) {
/* Add rewrite route */
$this->processedRoutes[] = $route;
}
if ($this->request->getRewriteUrl() !== $url) {
unset($this->processedRoutes[$key]);
$this->request->setHasPendingRewrite(false);
$this->fireEvents(EventHandler::EVENT_REWRITE, [
'rewriteUrl' => $this->request->getRewriteUrl(),
'rewriteRoute' => $this->request->getRewriteRoute(),
]);
return $this->routeRequest();
}
return null;
}
/**
* @param \Exception $e
* @throws HttpException
* @throws \Exception
* @return string
* @return string|null
*/
protected function handleException(\Exception $e)
protected function handleException(\Exception $e): ?string
{
$this->debug('Starting exception handling for "%s"', \get_class($e));
$this->fireEvents(EventHandler::EVENT_LOAD_EXCEPTIONS, [
'exception' => $e,
'exceptionHandlers' => $this->exceptionHandlers,
]);
/* @var $handler IExceptionHandler */
foreach ($this->exceptionHandlers as $key => $handler) {
if (is_object($handler) === false) {
if (\is_object($handler) === false) {
$handler = new $handler();
}
$this->fireEvents(EventHandler::EVENT_RENDER_EXCEPTION, [
'exception' => $e,
'exceptionHandler' => $handler,
'exceptionHandlers' => $this->exceptionHandlers,
]);
$this->debug('Processing exception-handler "%s"', \get_class($handler));
if (($handler instanceof IExceptionHandler) === false) {
throw new HttpException('Exception handler must implement the IExceptionHandler interface.', 500);
}
try {
$this->debug('Start rendering exception handler');
$handler->handleError($this->request, $e);
$this->debug('Finished rendering exception-handler');
if ($this->request->hasRewrite() === true) {
unset($this->exceptionHandlers[$key]);
$this->exceptionHandlers = array_values($this->exceptionHandlers);
if (isset($this->loadedExceptionHandlers[$key]) === false && $this->request->hasPendingRewrite() === true) {
return $this->routeRequest(true);
$this->loadedExceptionHandlers[$key] = $handler;
$this->debug('Exception handler contains rewrite, reloading routes');
$this->fireEvents(EventHandler::EVENT_REWRITE, [
'rewriteUrl' => $this->request->getRewriteUrl(),
'rewriteRoute' => $this->request->getRewriteRoute(),
]);
if ($this->request->getRewriteRoute() !== null) {
$this->processedRoutes[] = $this->request->getRewriteRoute();
}
return $this->routeRequest();
}
} catch (\Exception $e) {
}
$this->debug('Finished processing');
}
$this->debug('Finished exception handling - exception not handled, throwing');
throw $e;
}
public function arrayToParams(array $getParams = [], $includeEmpty = true)
{
if (count($getParams) !== 0) {
if ($includeEmpty === false) {
$getParams = array_filter($getParams, function ($item) {
return (trim($item) !== '');
});
}
return '?' . http_build_query($getParams);
}
return '';
}
/**
* Find route by alias, class, callback or method.
*
* @param string $name
* @return ILoadableRoute|null
*/
public function findRoute($name)
public function findRoute(string $name): ?ILoadableRoute
{
$this->debug('Finding route by name "%s"', $name);
$this->fireEvents(EventHandler::EVENT_FIND_ROUTE, [
'name' => $name,
]);
/* @var $route ILoadableRoute */
foreach ($this->processedRoutes as $route) {
/* Check if the name matches with a name on the route. Should match either router alias or controller alias. */
if ($route->hasName($name)) {
if ($route->hasName($name) === true) {
$this->debug('Found route "%s" by name "%s"', $route->getUrl(), $name);
return $route;
}
/* Direct match to controller */
if ($route instanceof IControllerRoute && strtolower($route->getController()) === strtolower($name)) {
if ($route instanceof IControllerRoute && strtoupper($route->getController()) === strtoupper($name)) {
$this->debug('Found route "%s" by controller "%s"', $route->getUrl(), $name);
return $route;
}
/* Using @ is most definitely a controller@method or alias@method */
if (is_string($name) === true && strpos($name, '@') !== false) {
list($controller, $method) = array_map('strtolower', explode('@', $name));
if (\is_string($name) === true && strpos($name, '@') !== false) {
[$controller, $method] = array_map('strtolower', explode('@', $name));
if ($controller === strtolower($route->getClass()) && $method === strtolower($route->getMethod())) {
$this->debug('Found route "%s" by controller "%s" and method "%s"', $route->getUrl(), $controller, $method);
return $route;
}
}
/* Check if callback matches (if it's not a function) */
if (is_string($name) === true && is_string($route->getCallback()) && strpos($name, '@') !== false && strpos($route->getCallback(), '@') !== false && is_callable($route->getCallback()) === false) {
$callback = $route->getCallback();
if (\is_string($name) === true && \is_string($callback) === true && strpos($name, '@') !== false && strpos($callback, '@') !== false && \is_callable($callback) === false) {
/* Check if the entire callback is matching */
if (strpos($route->getCallback(), $name) === 0 || strtolower($route->getCallback()) === strtolower($name)) {
if (strpos($callback, $name) === 0 || strtolower($callback) === strtolower($name)) {
$this->debug('Found route "%s" by callback "%s"', $route->getUrl(), $name);
return $route;
}
/* Check if the class part of the callback matches (class@method) */
if (strtolower($name) === strtolower($route->getClass())) {
$this->debug('Found route "%s" by class "%s"', $route->getUrl(), $name);
return $route;
}
}
}
$this->debug('Route not found');
return null;
}
@@ -445,48 +623,61 @@ class Router
* @param string|null $name
* @param string|array|null $parameters
* @param array|null $getParams
* @return Url
* @throws InvalidArgumentException
* @return string
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public function getUrl($name = null, $parameters = null, $getParams = null)
public function getUrl(?string $name = null, $parameters = null, ?array $getParams = null): Url
{
if ($getParams !== null && is_array($getParams) === false) {
$this->debug('Finding url', \func_get_args());
$this->fireEvents(EventHandler::EVENT_GET_URL, [
'name' => $name,
'parameters' => $parameters,
'getParams' => $getParams,
]);
if ($getParams !== null && \is_array($getParams) === false) {
throw new InvalidArgumentException('Invalid type for getParams. Must be array or null');
}
if ($name === '' && $parameters === '') {
return '/';
return new Url('/');
}
/* Only merge $_GET when all parameters are null */
if ($name === null && $parameters === null && $getParams === null) {
$getParams = $_GET;
} else {
$getParams = (array)$getParams;
}
$getParams = ($name === null && $parameters === null && $getParams === null) ? $_GET : (array)$getParams;
/* Return current route if no options has been specified */
if ($name === null && $parameters === null) {
return $this->request->getUrl()->getPath() . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setParams($getParams);
}
$loadedRoute = $this->request->getLoadedRoute();
/* If nothing is defined and a route is loaded we use that */
if ($name === null && $loadedRoute !== null) {
return $loadedRoute->findUrl($loadedRoute->getMethod(), $parameters, $name) . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setPath($loadedRoute->findUrl($loadedRoute->getMethod(), $parameters, $name))
->setParams($getParams);
}
/* We try to find a match on the given name */
$route = $this->findRoute($name);
if ($route !== null) {
return $route->findUrl($route->getMethod(), $parameters, $name) . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setPath($route->findUrl($route->getMethod(), $parameters, $name))
->setParams($getParams);
}
/* Using @ is most definitely a controller@method or alias@method */
if (is_string($name) === true && strpos($name, '@') !== false) {
list($controller, $method) = explode('@', $name);
if (\is_string($name) === true && strpos($name, '@') !== false) {
[$controller, $method] = explode('@', $name);
/* Loop through all the routes to see if we can find a match */
@@ -495,12 +686,18 @@ class Router
/* Check if the route contains the name/alias */
if ($route->hasName($controller) === true) {
return $route->findUrl($method, $parameters, $name) . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setPath($route->findUrl($method, $parameters, $name))
->setParams($getParams);
}
/* Check if the route controller is equal to the name */
if ($route instanceof IControllerRoute && strtolower($route->getController()) === strtolower($controller)) {
return $route->findUrl($method, $parameters, $name) . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setPath($route->findUrl($method, $parameters, $name))
->setParams($getParams);
}
}
@@ -508,35 +705,47 @@ class Router
/* No result so we assume that someone is using a hardcoded url and join everything together. */
$url = trim(implode('/', array_merge((array)$name, (array)$parameters)), '/');
$url = (($url === '') ? '/' : '/' . $url . '/');
return (($url === '') ? '/' : '/' . $url . '/') . $this->arrayToParams($getParams);
return $this->request
->getUrlCopy()
->setPath($url)
->setParams($getParams);
}
/**
* Get bootmanagers
* Get BootManagers
* @return array
*/
public function getBootManagers()
public function getBootManagers(): array
{
return $this->bootManagers;
}
/**
* Set bootmanagers
* Set BootManagers
*
* @param array $bootManagers
* @return static
*/
public function setBootManagers(array $bootManagers)
public function setBootManagers(array $bootManagers): self
{
$this->bootManagers = $bootManagers;
return $this;
}
/**
* Add bootmanager
* Add BootManager
*
* @param IRouterBootManager $bootManager
* @return static
*/
public function addBootManager(IRouterBootManager $bootManager)
public function addBootManager(IRouterBootManager $bootManager): self
{
$this->bootManagers[] = $bootManager;
return $this;
}
/**
@@ -544,7 +753,7 @@ class Router
*
* @return array
*/
public function getProcessedRoutes()
public function getProcessedRoutes(): array
{
return $this->processedRoutes;
}
@@ -552,7 +761,7 @@ class Router
/**
* @return array
*/
public function getRoutes()
public function getRoutes(): array
{
return $this->routes;
}
@@ -561,9 +770,9 @@ class Router
* Set routes
*
* @param array $routes
* @return static $this
* @return static
*/
public function setRoutes(array $routes)
public function setRoutes(array $routes): self
{
$this->routes = $routes;
@@ -575,7 +784,7 @@ class Router
*
* @return Request
*/
public function getRequest()
public function getRequest(): Request
{
return $this->request;
}
@@ -584,7 +793,7 @@ class Router
* Get csrf verifier class
* @return BaseCsrfVerifier
*/
public function getCsrfVerifier()
public function getCsrfVerifier(): ?BaseCsrfVerifier
{
return $this->csrfVerifier;
}
@@ -593,13 +802,110 @@ class Router
* Set csrf verifier class
*
* @param BaseCsrfVerifier $csrfVerifier
* @return static
*/
public function setCsrfVerifier(BaseCsrfVerifier $csrfVerifier)
public function setCsrfVerifier(BaseCsrfVerifier $csrfVerifier): void
{
$this->csrfVerifier = $csrfVerifier;
}
/**
* Set class loader
*
* @param IClassLoader $loader
*/
public function setClassLoader(IClassLoader $loader): void
{
$this->classLoader = $loader;
}
/**
* Get class loader
*
* @return ClassLoader
*/
public function getClassLoader(): IClassLoader
{
return $this->classLoader;
}
/**
* Register event handler
*
* @param IEventHandler $handler
*/
public function addEventHandler(IEventHandler $handler): void
{
$this->eventHandlers[] = $handler;
}
/**
* Get registered event-handler.
*
* @return array
*/
public function getEventHandlers(): array
{
return $this->eventHandlers;
}
/**
* Fire event in event-handler.
*
* @param string $name
* @param array $arguments
*/
protected function fireEvents($name, array $arguments = []): void
{
if (\count($this->eventHandlers) === 0) {
return;
}
/* @var IEventHandler $eventHandler */
foreach ($this->eventHandlers as $eventHandler) {
$eventHandler->fireEvents($this, $name, $arguments);
}
}
/**
* Add new debug message
* @param string $message
* @param array $args
*/
public function debug(string $message, ...$args): void
{
if ($this->debugEnabled === false) {
return;
}
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$this->debugList[] = [
'message' => vsprintf($message, $args),
'time' => number_format(microtime(true) - $this->debugStartTime, 10),
'trace' => end($trace),
];
}
/**
* Enable or disables debugging
*
* @param bool $enabled
* @return static
*/
public function setDebugEnabled(bool $enabled): self
{
$this->debugEnabled = $enabled;
return $this;
}
/**
* Get the list containing all debug messages.
*
* @return array
*/
public function getDebugLog(): array
{
return $this->debugList;
}
}
+157 -71
View File
@@ -10,15 +10,23 @@
namespace Pecee\SimpleRouter;
use DI\Container;
use Pecee\Exceptions\InvalidArgumentException;
use Pecee\Handlers\CallbackExceptionHandler;
use Pecee\Http\Exceptions\MalformedUrlException;
use Pecee\Http\Middleware\BaseCsrfVerifier;
use Pecee\Http\Request;
use Pecee\Http\Response;
use Pecee\Http\Url;
use Pecee\SimpleRouter\ClassLoader\IClassLoader;
use Pecee\SimpleRouter\Exceptions\HttpException;
use Pecee\SimpleRouter\Handlers\CallbackExceptionHandler;
use Pecee\SimpleRouter\Handlers\IEventHandler;
use Pecee\SimpleRouter\Route\IGroupRoute;
use Pecee\SimpleRouter\Route\IPartialGroupRoute;
use Pecee\SimpleRouter\Route\IRoute;
use Pecee\SimpleRouter\Route\RoutePartialGroup;
use Pecee\SimpleRouter\Route\RouteController;
use Pecee\SimpleRouter\Route\RouteGroup;
use Pecee\SimpleRouter\Route\RoutePartialGroup;
use Pecee\SimpleRouter\Route\RouteResource;
use Pecee\SimpleRouter\Route\RouteUrl;
@@ -26,7 +34,7 @@ class SimpleRouter
{
/**
* Default namespace added to all routes
* @var string
* @var string|null
*/
protected static $defaultNamespace;
@@ -43,13 +51,71 @@ class SimpleRouter
protected static $router;
/**
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* Start routing
*
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
* @throws \Pecee\Http\Middleware\Exceptions\TokenMismatchException
* @throws HttpException
* @throws \Exception
*/
public static function start()
public static function start(): void
{
echo static::router()->routeRequest();
echo static::router()->start();
}
/**
* Start the routing an return array with debugging-information
*
* @return array
*/
public static function startDebug(): array
{
$routerOutput = null;
try {
ob_start();
static::router()->setDebugEnabled(true)->start();
$routerOutput = ob_get_contents();
ob_end_clean();
} catch (\Exception $e) {
}
// Try to parse library version
$composerFile = \dirname(__DIR__, 3) . '/composer.lock';
$version = false;
if (is_file($composerFile) === true) {
$composerInfo = json_decode(file_get_contents($composerFile), true);
if (isset($composerInfo['packages']) === true && \is_array($composerInfo['packages']) === true) {
foreach ($composerInfo['packages'] as $package) {
if (isset($package['name']) === true && strtolower($package['name']) === 'pecee/simple-router') {
$version = $package['version'];
break;
}
}
}
}
$request = static::request();
$router = static::router();
return [
'url' => $request->getUrl(),
'method' => $request->getMethod(),
'host' => $request->getHost(),
'loaded_routes' => $request->getLoadedRoutes(),
'all_routes' => $router->getRoutes(),
'boot_managers' => $router->getBootManagers(),
'csrf_verifier' => $router->getCsrfVerifier(),
'log' => $router->getDebugLog(),
'event_handlers' => $router->getEventHandlers(),
'router_output' => $routerOutput,
'library_version' => $version,
'php_version' => PHP_VERSION,
'server_params' => $request->getHeaders(),
];
}
/**
@@ -57,7 +123,7 @@ class SimpleRouter
*
* @param string $defaultNamespace
*/
public static function setDefaultNamespace($defaultNamespace)
public static function setDefaultNamespace(string $defaultNamespace): void
{
static::$defaultNamespace = $defaultNamespace;
}
@@ -66,25 +132,48 @@ class SimpleRouter
* Base CSRF verifier
*
* @param BaseCsrfVerifier $baseCsrfVerifier
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function csrfVerifier(BaseCsrfVerifier $baseCsrfVerifier)
public static function csrfVerifier(BaseCsrfVerifier $baseCsrfVerifier): void
{
static::router()->setCsrfVerifier($baseCsrfVerifier);
}
/**
* Add new event handler to the router
*
* @param IEventHandler $eventHandler
*/
public static function addEventHandler(IEventHandler $eventHandler): void
{
static::router()->addEventHandler($eventHandler);
}
/**
* Boot managers allows you to alter the routes before the routing occurs.
* Perfect if you want to load pretty-urls from a file or database.
*
* @param IRouterBootManager $bootManager
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function addBootManager(IRouterBootManager $bootManager)
public static function addBootManager(IRouterBootManager $bootManager): void
{
static::router()->addBootManager($bootManager);
}
/**
* Redirect to when route matches.
*
* @param string $where
* @param string $to
* @param int $httpCode
* @return IRoute
*/
public static function redirect($where, $to, $httpCode = 301): IRoute
{
return static::get($where, function () use ($to, $httpCode) {
static::response()->redirect($to, $httpCode);
});
}
/**
* Route the given url to your callback on GET request method.
*
@@ -93,9 +182,8 @@ class SimpleRouter
* @param array|null $settings
*
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function get($url, $callback, array $settings = null)
public static function get(string $url, $callback, array $settings = null): IRoute
{
return static::match(['get'], $url, $callback, $settings);
}
@@ -107,9 +195,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function post($url, $callback, array $settings = null)
public static function post(string $url, $callback, array $settings = null): IRoute
{
return static::match(['post'], $url, $callback, $settings);
}
@@ -121,9 +208,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function put($url, $callback, array $settings = null)
public static function put(string $url, $callback, array $settings = null): IRoute
{
return static::match(['put'], $url, $callback, $settings);
}
@@ -135,9 +221,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function patch($url, $callback, array $settings = null)
public static function patch(string $url, $callback, array $settings = null): IRoute
{
return static::match(['patch'], $url, $callback, $settings);
}
@@ -149,9 +234,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function options($url, $callback, array $settings = null)
public static function options(string $url, $callback, array $settings = null): IRoute
{
return static::match(['options'], $url, $callback, $settings);
}
@@ -163,9 +247,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function delete($url, $callback, array $settings = null)
public static function delete(string $url, $callback, array $settings = null): IRoute
{
return static::match(['delete'], $url, $callback, $settings);
}
@@ -176,12 +259,11 @@ class SimpleRouter
* @param array $settings
* @param \Closure $callback
* @return RouteGroup
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* @throws InvalidArgumentException
*/
public static function group(array $settings = [], \Closure $callback)
public static function group(array $settings = [], \Closure $callback): IGroupRoute
{
if (is_callable($callback) === false) {
if (\is_callable($callback) === false) {
throw new InvalidArgumentException('Invalid callback provided. Only functions or methods supported');
}
@@ -202,12 +284,11 @@ class SimpleRouter
* @param \Closure $callback
* @param array $settings
* @return RoutePartialGroup
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* @throws InvalidArgumentException
*/
public static function partialGroup($url, \Closure $callback, array $settings = [])
public static function partialGroup(string $url, \Closure $callback, array $settings = []): IPartialGroupRoute
{
if (is_callable($callback) === false) {
if (\is_callable($callback) === false) {
throw new InvalidArgumentException('Invalid callback provided. Only functions or methods supported');
}
@@ -230,9 +311,8 @@ class SimpleRouter
* @param array|null $settings
* @see SimpleRouter::form
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function basic($url, $callback, array $settings = null)
public static function basic(string $url, $callback, array $settings = null): IRoute
{
return static::match(['get', 'post'], $url, $callback, $settings);
}
@@ -246,9 +326,8 @@ class SimpleRouter
* @param array|null $settings
* @see SimpleRouter::form
* @return RouteUrl
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function form($url, $callback, array $settings = null)
public static function form(string $url, $callback, array $settings = null): IRoute
{
return static::match(['get', 'post'], $url, $callback, $settings);
}
@@ -261,9 +340,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl|IRoute
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function match(array $requestMethods, $url, $callback, array $settings = null)
public static function match(array $requestMethods, string $url, $callback, array $settings = null)
{
$route = new RouteUrl($url, $callback);
$route->setRequestMethods($requestMethods);
@@ -273,9 +351,7 @@ class SimpleRouter
$route->setSettings($settings);
}
static::router()->addRoute($route);
return $route;
return static::router()->addRoute($route);
}
/**
@@ -285,9 +361,8 @@ class SimpleRouter
* @param string|\Closure $callback
* @param array|null $settings
* @return RouteUrl|IRoute
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function all($url, $callback, array $settings = null)
public static function all(string $url, $callback, array $settings = null)
{
$route = new RouteUrl($url, $callback);
$route = static::addDefaultNamespace($route);
@@ -296,9 +371,7 @@ class SimpleRouter
$route->setSettings($settings);
}
static::router()->addRoute($route);
return $route;
return static::router()->addRoute($route);
}
/**
@@ -308,9 +381,8 @@ class SimpleRouter
* @param string $controller
* @param array|null $settings
* @return RouteController|IRoute
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function controller($url, $controller, array $settings = null)
public static function controller(string $url, $controller, array $settings = null)
{
$route = new RouteController($url, $controller);
$route = static::addDefaultNamespace($route);
@@ -319,9 +391,7 @@ class SimpleRouter
$route->setSettings($settings);
}
static::router()->addRoute($route);
return $route;
return static::router()->addRoute($route);
}
/**
@@ -331,9 +401,8 @@ class SimpleRouter
* @param string $controller
* @param array|null $settings
* @return RouteResource|IRoute
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function resource($url, $controller, array $settings = null)
public static function resource(string $url, $controller, array $settings = null)
{
$route = new RouteResource($url, $controller);
$route = static::addDefaultNamespace($route);
@@ -342,9 +411,7 @@ class SimpleRouter
$route->setSettings($settings);
}
static::router()->addRoute($route);
return $route;
return static::router()->addRoute($route);
}
/**
@@ -352,9 +419,8 @@ class SimpleRouter
*
* @param \Closure $callback
* @return CallbackExceptionHandler $callbackHandler
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function error(\Closure $callback)
public static function error(\Closure $callback): CallbackExceptionHandler
{
$routes = static::router()->getRoutes();
@@ -385,22 +451,30 @@ class SimpleRouter
* @param string|null $name
* @param string|array|null $parameters
* @param array|null $getParams
* @throws \Pecee\Exceptions\InvalidArgumentException
* @return string
* @throws \Pecee\Http\Exceptions\MalformedUrlException
* @return Url
*/
public static function getUrl($name = null, $parameters = null, $getParams = null)
public static function getUrl(?string $name = null, $parameters = null, ?array $getParams = null): Url
{
return static::router()->getUrl($name, $parameters, $getParams);
try {
return static::router()->getUrl($name, $parameters, $getParams);
} catch (\Exception $e) {
try {
return new Url('/');
} catch (MalformedUrlException $e) {
}
}
// This will never happen...
return null;
}
/**
* Get the request
*
* @return \Pecee\Http\Request
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function request()
public static function request(): Request
{
return static::router()->getRequest();
}
@@ -409,9 +483,8 @@ class SimpleRouter
* Get the response object
*
* @return Response
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function response()
public static function response(): Response
{
if (static::$response === null) {
static::$response = new Response(static::request());
@@ -424,9 +497,8 @@ class SimpleRouter
* Returns the router instance
*
* @return Router
* @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public static function router()
public static function router(): Router
{
if (static::$router === null) {
static::$router = new Router();
@@ -441,14 +513,14 @@ class SimpleRouter
* @param IRoute $route
* @return IRoute
*/
public static function addDefaultNamespace(IRoute $route)
public static function addDefaultNamespace(IRoute $route): IRoute
{
if (static::$defaultNamespace !== null) {
$callback = $route->getCallback();
/* Only add default namespace on relative callbacks */
if ($callback === null || (is_string($callback) === true && $callback[0] !== '\\')) {
if ($callback === null || (\is_string($callback) === true && $callback[0] !== '\\')) {
$namespace = static::$defaultNamespace;
@@ -467,10 +539,24 @@ class SimpleRouter
}
/**
* Get default namespace
* @return string
* Enable or disable dependency injection
*
* @param Container $container
* @return IClassLoader
*/
public static function getDefaultNamespace()
public static function enableDependencyInjection(Container $container): IClassLoader
{
return static::router()
->getClassLoader()
->useDependencyInjection(true)
->setContainer($container);
}
/**
* Get default namespace
* @return string|null
*/
public static function getDefaultNamespace(): ?string
{
return static::$defaultNamespace;
}
@@ -1,14 +0,0 @@
<?php
class ExceptionHandlerFirst implements \Pecee\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error)
{
global $stack;
$stack[] = static::class;
$request->setUrl('/');
return $request;
}
}
@@ -1,14 +0,0 @@
<?php
class ExceptionHandlerSecond implements \Pecee\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error)
{
global $stack;
$stack[] = static::class;
$request->setUrl('/');
return $request;
}
}
-39
View File
@@ -1,39 +0,0 @@
<?php
class ResourceController implements \Pecee\Controllers\IResourceController
{
public function index()
{
echo 'index';
}
public function show($id)
{
echo 'show ' . $id;
}
public function store()
{
echo 'store';
}
public function create()
{
echo 'create';
}
public function edit($id)
{
echo 'edit ' . $id;
}
public function update($id)
{
echo 'update ' . $id;
}
public function destroy($id)
{
echo 'destroy ' . $id;
}
}
@@ -0,0 +1,53 @@
<?php
require_once 'Dummy/DummyMiddleware.php';
class DependencyInjectionTest extends \PHPUnit\Framework\TestCase
{
public function testDependencyInjectionDevelopment()
{
$builder = new \DI\ContainerBuilder();
$container = $builder
->useAutowiring(true)
->ignorePhpDocErrors(true)
->build();
TestRouter::enableDependencyInjection($container);
$className = null;
TestRouter::get('/', function (DummyMiddleware $url) use (&$className) {
$className = \get_class($url);
});
TestRouter::debug('/');
$this->assertEquals(DummyMiddleware::class, $className);
}
public function testDependencyInjectionProduction()
{
$cacheDir = dirname(__DIR__, 2) . '/tmp';
$builder = new \DI\ContainerBuilder();
$builder
->enableCompilation($cacheDir)
->writeProxiesToFile(true, $cacheDir . '/proxies')
->ignorePhpDocErrors(true)
->useAutowiring(true);
$container = $builder->build();
TestRouter::enableDependencyInjection($container);
$className = null;
TestRouter::get('/', function (DummyMiddleware $url) use (&$className) {
$className = \get_class($url);
});
TestRouter::debug('/');
$this->assertEquals(DummyMiddleware::class, $className);
}
}
@@ -1,11 +1,11 @@
<?php
require_once 'Exceptions/MiddlewareLoadedException.php';
require_once 'Exception/MiddlewareLoadedException.php';
use Pecee\Http\Request;
class DummyMiddleware implements \Pecee\Http\Middleware\IMiddleware
{
public function handle(Request $request)
public function handle(Request $request) : void
{
throw new MiddlewareLoadedException('Middleware loaded!');
}
@@ -1,4 +1,5 @@
<?php
class ExceptionHandlerException extends \Exception
{
}
@@ -1,8 +1,8 @@
<?php
class ExceptionHandler implements \Pecee\Handlers\IExceptionHandler
class ExceptionHandler implements \Pecee\SimpleRouter\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error)
public function handleError(\Pecee\Http\Request $request, \Exception $error) : void
{
echo $error->getMessage();
}
@@ -0,0 +1,13 @@
<?php
class ExceptionHandlerFirst implements \Pecee\SimpleRouter\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error) : void
{
global $stack;
$stack[] = static::class;
$request->setUrl(new \Pecee\Http\Url('/'));
}
}
@@ -0,0 +1,13 @@
<?php
class ExceptionHandlerSecond implements \Pecee\SimpleRouter\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error) : void
{
global $stack;
$stack[] = static::class;
$request->setUrl(new \Pecee\Http\Url('/'));
}
}
@@ -1,8 +1,8 @@
<?php
class ExceptionHandlerThird implements \Pecee\Handlers\IExceptionHandler
class ExceptionHandlerThird implements \Pecee\SimpleRouter\Handlers\IExceptionHandler
{
public function handleError(\Pecee\Http\Request $request, \Exception $error)
public function handleError(\Pecee\Http\Request $request, \Exception $error) : void
{
global $stack;
$stack[] = static::class;
@@ -0,0 +1,32 @@
<?php
class TestBootManager implements \Pecee\SimpleRouter\IRouterBootManager
{
protected $routes;
protected $aliasUrl;
public function __construct(array $routes, string $aliasUrl)
{
$this->routes = $routes;
$this->aliasUrl = $aliasUrl;
}
/**
* Called when router loads it's routes
*
* @param \Pecee\SimpleRouter\Router $router
* @param \Pecee\Http\Request $request
*/
public function boot(\Pecee\SimpleRouter\Router $router, \Pecee\Http\Request $request): void
{
foreach ($this->routes as $url) {
// If the current url matches the rewrite url, we use our custom route
if ($request->getUrl()->contains($url) === true) {
$request->setRewriteUrl($this->aliasUrl);
}
}
}
}
@@ -5,7 +5,7 @@ use Pecee\Http\Request;
class RewriteMiddleware implements IMiddleware {
public function handle(Request $request) {
public function handle(Request $request) : void {
$request->setRewriteCallback(function() {
return 'ok';
@@ -0,0 +1,46 @@
<?php
class ResourceController implements \Pecee\Controllers\IResourceController
{
public function index() : ?string
{
echo 'index';
return null;
}
public function show($id) : ?string
{
echo 'show ' . $id;
return null;
}
public function store() : ?string
{
echo 'store';
return null;
}
public function create() : ?string
{
echo 'create';
return null;
}
public function edit($id) : ?string
{
echo 'edit ' . $id;
return null;
}
public function update($id) : ?string
{
echo 'update ' . $id;
return null;
}
public function destroy($id) : ?string
{
echo 'destroy ' . $id;
return null;
}
}
@@ -0,0 +1,41 @@
<?php
class SilentTokenProvider implements \Pecee\Http\Security\ITokenProvider {
protected $token;
public function __construct()
{
$this->refresh();
}
/**
* Refresh existing token
*/
public function refresh(): void
{
$this->token = uniqid('', false);
}
/**
* Validate valid CSRF token
*
* @param string $token
* @return bool
*/
public function validate(string $token): bool
{
return ($token === $this->token);
}
/**
* Get token token
*
* @param string|null $defaultValue
* @return string|null
*/
public function getToken(?string $defaultValue = null): ?string
{
return $this->token ?? $defaultValue;
}
}
@@ -0,0 +1,107 @@
<?php
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
require_once 'Dummy/Security/SilentTokenProvider.php';
require_once 'Dummy/Managers/TestBootManager.php';
use Pecee\SimpleRouter\Event\EventArgument;
use Pecee\SimpleRouter\Handlers\EventHandler;
class EventHandlerTest extends \PHPUnit\Framework\TestCase
{
public function testAllEventTriggered()
{
$events = EventHandler::$events;
// Remove the all event
unset($events[\array_search(EventHandler::EVENT_ALL, $events, true)]);
$eventHandler = new EventHandler();
$eventHandler->register(EventHandler::EVENT_ALL, function (EventArgument $arg) use (&$events) {
$key = \array_search($arg->getEventName(), $events, true);
unset($events[$key]);
});
TestRouter::addEventHandler($eventHandler);
// Add rewrite
TestRouter::error(function (\Pecee\Http\Request $request, \Exception $error) {
// Trigger rewrite
$request->setRewriteUrl('/');
});
TestRouter::get('/', 'DummyController@method1')->name('home');
// Trigger findRoute
TestRouter::router()->findRoute('home');
// Trigger getUrl
TestRouter::router()->getUrl('home');
// Add csrf-verifier
$csrfVerifier = new \Pecee\Http\Middleware\BaseCsrfVerifier();
$csrfVerifier->setTokenProvider(new SilentTokenProvider());
TestRouter::csrfVerifier($csrfVerifier);
// Add boot-manager
TestRouter::addBootManager(new TestBootManager([
'/test',
], '/'));
// Start router
TestRouter::debug('/non-existing');
$this->assertEquals($events, []);
}
public function testAllEvent()
{
$status = false;
$eventHandler = new EventHandler();
$eventHandler->register(EventHandler::EVENT_ALL, function (EventArgument $arg) use (&$status) {
$status = true;
});
TestRouter::addEventHandler($eventHandler);
TestRouter::get('/', 'DummyController@method1');
TestRouter::debug('/');
// All event should fire for each other event
$this->assertEquals(true, $status);
}
public function testPrefixEvent()
{
$eventHandler = new EventHandler();
$eventHandler->register(EventHandler::EVENT_ADD_ROUTE, function (EventArgument $arg) use (&$status) {
if ($arg->route instanceof \Pecee\SimpleRouter\Route\LoadableRoute) {
$arg->route->prependUrl('/local-path');
}
});
TestRouter::addEventHandler($eventHandler);
$status = false;
TestRouter::get('/', function () use (&$status) {
$status = true;
});
TestRouter::debug('/local-path');
$this->assertTrue($status);
}
}
@@ -2,18 +2,16 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Helpers/TestRouter.php';
class GroupTest extends PHPUnit_Framework_TestCase
class GroupTest extends \PHPUnit\Framework\TestCase
{
protected $result;
public function testGroupLoad()
{
$this->result = false;
$result = false;
TestRouter::group(['prefix' => '/group'], function () {
$this->result = true;
TestRouter::group(['prefix' => '/group'], function () use(&$result) {
$result = true;
});
try {
@@ -21,7 +19,7 @@ class GroupTest extends PHPUnit_Framework_TestCase
} catch(\Exception $e) {
}
$this->assertTrue($this->result);
$this->assertTrue($result);
}
public function testNestedGroup()
@@ -37,6 +35,7 @@ class GroupTest extends PHPUnit_Framework_TestCase
TestRouter::debug('/api/v1/test', 'get');
$this->assertTrue(true);
}
public function testMultipleRoutes()
@@ -61,6 +60,8 @@ class GroupTest extends PHPUnit_Framework_TestCase
});
TestRouter::debug('/my/match', 'get');
$this->assertTrue(true);
}
public function testUrls()
@@ -0,0 +1,125 @@
<?php
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
class InputHandlerTest extends \PHPUnit\Framework\TestCase
{
public function testPost()
{
global $_POST;
$names = [
'Lester',
'Michael',
'Franklin',
'Trevor',
];
$day = 'monday';
$_POST = [
'names' => $names,
'day' => $day,
];
$router = TestRouter::router();
$router->reset();
$router->getRequest()->setMethod('post');
$handler = TestRouter::request()->getInputHandler();
$this->assertEquals($names, $handler->value('names'));
$this->assertEquals($names, $handler->all(['names'])['names']);
$this->assertEquals($day, $handler->value('day'));
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $handler->find('day'));
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $handler->post('day'));
// Check non-existing and wrong request-type
$this->assertEmpty($handler->all(['non-existing']));
$this->assertNull($handler->value('non-existing'));
$this->assertNull($handler->find('non-existing'));
$this->assertNull($handler->value('names', null, 'get'));
$this->assertNull($handler->find('names', 'get'));
$objects = $handler->find('names');
$this->assertCount(4, $objects);
/* @var $object \Pecee\Http\Input\InputItem */
foreach($objects as $i => $object) {
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $object);
$this->assertEquals($names[$i], $object->getValue());
}
$_POST = [];
}
public function testGet()
{
global $_GET;
$names = [
'Lester',
'Michael',
'Franklin',
'Trevor',
];
$day = 'monday';
$_GET = [
'names' => $names,
'day' => $day,
];
$router = TestRouter::router();
$router->reset();
$router->getRequest()->setMethod('get');
$handler = TestRouter::request()->getInputHandler();
$this->assertEquals($names, $handler->value('names'));
$this->assertEquals($names, $handler->all(['names'])['names']);
$this->assertEquals($day, $handler->value('day'));
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $handler->find('day'));
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $handler->get('day'));
// Check non-existing and wrong request-type
$this->assertEmpty($handler->all(['non-existing']));
$this->assertNull($handler->value('non-existing'));
$this->assertNull($handler->find('non-existing'));
$this->assertNull($handler->value('names', null, 'post'));
$this->assertNull($handler->find('names', 'post'));
$objects = $handler->find('names');
$this->assertCount(4, $objects);
/* @var $object \Pecee\Http\Input\InputItem */
foreach($objects as $i => $object) {
$this->assertInstanceOf(\Pecee\Http\Input\InputItem::class, $object);
$this->assertEquals($names[$i], $object->getValue());
}
$_GET = [];
}
public function testFile()
{
$this->assertEquals(true, true);
}
public function testFiles()
{
$this->assertEquals(true, true);
}
public function testAll()
{
$this->assertEquals(true, true);
}
}
@@ -3,13 +3,12 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
require_once 'Helpers/TestRouter.php';
class MiddlewareTest extends PHPUnit_Framework_TestCase
class MiddlewareTest extends \PHPUnit\Framework\TestCase
{
public function testMiddlewareFound()
{
$this->setExpectedException(MiddlewareLoadedException::class);
$this->expectException(MiddlewareLoadedException::class);
TestRouter::group(['exceptionHandler' => 'ExceptionHandler'], function () {
TestRouter::get('/my/test/url', 'DummyController@method1', ['middleware' => 'DummyMiddleware']);
@@ -29,6 +28,8 @@ class MiddlewareTest extends PHPUnit_Framework_TestCase
TestRouter::get('/my/test/url', 'DummyController@method1');
TestRouter::debug('/my/test/url', 'get');
$this->assertTrue(true);
}
}
@@ -2,15 +2,14 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Exceptions/ExceptionHandlerException.php';
require_once 'Helpers/TestRouter.php';
require_once 'Dummy/Exception/ExceptionHandlerException.php';
class RouterCallbackExceptionHandlerTest extends PHPUnit_Framework_TestCase
class RouterCallbackExceptionHandlerTest extends \PHPUnit\Framework\TestCase
{
public function testCallbackExceptionHandler()
{
$this->setExpectedException(ExceptionHandlerException::class);
$this->expectException(ExceptionHandlerException::class);
// Match normal route on alias
TestRouter::get('/my-new-url', 'DummyController@method2');
@@ -22,6 +21,8 @@ class RouterCallbackExceptionHandlerTest extends PHPUnit_Framework_TestCase
TestRouter::debugNoReset('/404-url', 'get');
TestRouter::router()->reset();
$this->assertTrue(true);
}
}
@@ -1,9 +1,8 @@
<?php
require_once 'Dummy/DummyController.php';
require_once 'Helpers/TestRouter.php';
class RouterControllerTest extends PHPUnit_Framework_TestCase
class RouterControllerTest extends \PHPUnit\Framework\TestCase
{
public function testGet()
@@ -3,9 +3,8 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
require_once 'Helpers/TestRouter.php';
class RouterPartialGroupTest extends PHPUnit_Framework_TestCase
class RouterPartialGroupTest extends \PHPUnit\Framework\TestCase
{
public function testParameters()
@@ -1,9 +1,8 @@
<?php
require_once 'Dummy/ResourceController.php';
require_once 'Helpers/TestRouter.php';
class RouterResourceTest extends PHPUnit_Framework_TestCase
class RouterResourceTest extends \PHPUnit\Framework\TestCase
{
public function testResourceStore()
@@ -1,13 +1,12 @@
<?php
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Exceptions/ResponseException.php';
require_once 'Dummy/Exception/ResponseException.php';
require_once 'Dummy/Handler/ExceptionHandlerFirst.php';
require_once 'Dummy/Handler/ExceptionHandlerSecond.php';
require_once 'Dummy/Handler/ExceptionHandlerThird.php';
require_once 'Helpers/TestRouter.php';
require_once 'Dummy/Middlewares/RewriteMiddleware.php';
require_once 'Dummy/Middleware/RewriteMiddleware.php';
class RouteRewriteTest extends PHPUnit_Framework_TestCase
class RouteRewriteTest extends \PHPUnit\Framework\TestCase
{
/**
@@ -61,7 +60,7 @@ class RouteRewriteTest extends PHPUnit_Framework_TestCase
public function testRewriteExceptionMessage()
{
$this->setExpectedException(\Pecee\SimpleRouter\Exceptions\NotFoundHttpException::class);
$this->expectException(\Pecee\SimpleRouter\Exceptions\NotFoundHttpException::class);
TestRouter::error(function (\Pecee\Http\Request $request, \Exception $error) {
@@ -2,32 +2,30 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Exceptions/ExceptionHandlerException.php';
require_once 'Helpers/TestRouter.php';
require_once 'Dummy/Exception/ExceptionHandlerException.php';
class RouterRouteTest extends PHPUnit_Framework_TestCase
class RouterRouteTest extends \PHPUnit\Framework\TestCase
{
protected $result = false;
public function testMultiParam()
{
TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) {
$result = false;
TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) use(&$result) {
if ($param1 === 'param1' && $param2 === 'param2') {
$this->result = true;
$result = true;
}
});
TestRouter::debug('/test-param1-param2', 'get');
$this->assertTrue($this->result);
$this->assertTrue($result);
}
public function testNotFound()
{
$this->setExpectedException('\Pecee\SimpleRouter\Exceptions\NotFoundHttpException');
$this->expectException('\Pecee\SimpleRouter\Exceptions\NotFoundHttpException');
TestRouter::get('/non-existing-path', 'DummyController@method1');
TestRouter::debug('/test-param1-param2', 'post');
}
@@ -36,24 +34,32 @@ class RouterRouteTest extends PHPUnit_Framework_TestCase
{
TestRouter::get('/my/test/url', 'DummyController@method1');
TestRouter::debug('/my/test/url', 'get');
$this->assertTrue(true);
}
public function testPost()
{
TestRouter::post('/my/test/url', 'DummyController@method1');
TestRouter::debug('/my/test/url', 'post');
$this->assertTrue(true);
}
public function testPut()
{
TestRouter::put('/my/test/url', 'DummyController@method1');
TestRouter::debug('/my/test/url', 'put');
$this->assertTrue(true);
}
public function testDelete()
{
TestRouter::delete('/my/test/url', 'DummyController@method1');
TestRouter::debug('/my/test/url', 'delete');
$this->assertTrue(true);
}
public function testMethodNotAllowed()
@@ -85,37 +91,37 @@ class RouterRouteTest extends PHPUnit_Framework_TestCase
public function testDomainAllowedRoute()
{
$this->result = false;
$result = false;
TestRouter::request()->setHost('hello.world.com');
TestRouter::group(['domain' => '{subdomain}.world.com'], function () {
TestRouter::get('/test', function ($subdomain = null) {
$this->result = ($subdomain === 'hello');
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
TestRouter::get('/test', function ($subdomain = null) use(&$result) {
$result = ($subdomain === 'hello');
});
});
TestRouter::request()->setHost('hello.world.com');
TestRouter::debug('/test', 'get');
$this->assertTrue($this->result);
$this->assertTrue($result);
}
public function testDomainNotAllowedRoute()
{
$this->result = false;
TestRouter::request()->setHost('other.world.com');
TestRouter::group(['domain' => '{subdomain}.world.com'], function () {
TestRouter::get('/test', function ($subdomain = null) {
$this->result = ($subdomain === 'hello');
$result = false;
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
TestRouter::get('/test', function ($subdomain = null) use(&$result) {
$result = ($subdomain === 'hello');
});
});
TestRouter::request()->setHost('other.world.com');
TestRouter::debug('/test', 'get');
$this->assertFalse($this->result);
$this->assertFalse($result);
}
@@ -123,6 +129,8 @@ class RouterRouteTest extends PHPUnit_Framework_TestCase
{
TestRouter::get('/my/{path}', 'DummyController@method1')->where(['path' => '[a-zA-Z\-]+']);
TestRouter::debug('/my/custom-path', 'get');
$this->assertTrue(true);
}
public function testParameterDefaultValue() {
@@ -3,9 +3,8 @@
require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
require_once 'Helpers/TestRouter.php';
class RouterUrlTest extends PHPUnit_Framework_TestCase
class RouterUrlTest extends \PHPUnit\Framework\TestCase
{
public function testIssue253()
@@ -32,21 +31,22 @@ class RouterUrlTest extends PHPUnit_Framework_TestCase
{
// Test spanish characters
TestRouter::get('/cursos/listado/{listado?}/{category?}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s-]+']);
TestRouter::get('/test/{param}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s-\í]+']);
TestRouter::debugNoReset('/cursos/listado/especialidad/cirugía local', 'get');
$this->assertEquals('/cursos/listado/{listado?}/{category?}/', TestRouter::router()->getRequest()->getLoadedRoute()->getUrl());
TestRouter::debugNoReset('/test/Dermatología');
$parameters = TestRouter::request()->getLoadedRoute()->getParameters();
$this->assertEquals('Dermatología', $parameters['param']);
// Test danish characters
TestRouter::get('/kategori/økse', 'DummyController@method1', ['defaultParameterRegex' => '[\w\ø]+']);
TestRouter::debugNoReset('/kategori/økse', 'get');
$this->assertEquals('/kategori/økse/', TestRouter::router()->getRequest()->getLoadedRoute()->getUrl());
TestRouter::get('/test/{param}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s-\í]+']);
TestRouter::debugNoReset('/test/Dermatología');
$parameters = TestRouter::request()->getLoadedRoute()->getParameters();
$this->assertEquals('Dermatología', $parameters['param']);
TestRouter::router()->reset();
}
@@ -5,8 +5,10 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
public static function debugNoReset($testUrl, $testMethod = 'get')
{
static::request()->setUrl($testUrl);
static::request()->setMethod($testMethod);
$request = static::request();
$request->setUrl((new \Pecee\Http\Url($testUrl))->setHost('local.unitTest'));
$request->setMethod($testMethod);
static::start();
}
+4
View File
@@ -0,0 +1,4 @@
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once 'TestRouter.php';
+9
View File
@@ -0,0 +1,9 @@
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use \Pecee\SimpleRouter\SimpleRouter;
SimpleRouter::get('/user/{name}', 'UserController@show')->where(['name' => '[\w]+']);
$debugInfo = SimpleRouter::startDebug();
echo sprintf('<pre>%s</pre>', var_export($debugInfo, true));
exit;