Reworked app

This commit is contained in:
R. Eric Wheeler 2016-07-03 20:54:55 -07:00
parent f183f8d609
commit 4871c64681
92 changed files with 1951 additions and 8463 deletions

3
.bowerrc Normal file
View File

@ -0,0 +1,3 @@
{
"directory": "vendor/bower"
}

1
.gitignore vendored
View File

@ -2,4 +2,5 @@
/build
*~
.*~
.idea/

View File

@ -42,12 +42,12 @@
<orderEntry type="module-library">
<library name="PHARS">
<CLASSES>
<root url="phar://$MODULE_DIR$/vendor/symfony/dependency-injection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar/" />
<root url="phar://$MODULE_DIR$/vendor/webmozart/json/tests/Fixtures/schema.phar/" />
<root url="phar://$MODULE_DIR$/build/composer.phar/" />
</CLASSES>
<SOURCES>
<root url="phar://$MODULE_DIR$/vendor/symfony/dependency-injection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar/" />
<root url="phar://$MODULE_DIR$/vendor/webmozart/json/tests/Fixtures/schema.phar/" />
<root url="phar://$MODULE_DIR$/build/composer.phar/" />
</SOURCES>
</library>
</orderEntry>

View File

@ -2,16 +2,88 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="cf1e275f-fbc1-41d4-a421-0f55447b6367" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/config/config.yml" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/resume.schema.json" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Config.php" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Sikofitt/Config/YamlFileLoader.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/yaml.yml" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/deployment.xml" afterPath="$PROJECT_DIR$/.idea/deployment.xml" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/app/views/base.html.twig" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/app/views/hidden.html.twig" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/app/views/recaptcha.html.twig" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/app/views/resume.html.twig" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Command/SchemaValidationCommand.php" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Config/ConfigServiceProvider.php" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Config/ConfigTrait.php" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Sikofitt/Json/ResumeBuilder.php" />
<change type="DELETED" beforePath="$PROJECT_DIR$/bin/build" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/bin/skeleton/fat_composer.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/bin/skeleton/index.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/bin/skeleton/slim_composer.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/config/config.yml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Sikofitt/Config.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Api/BootableProviderInterface.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Api/ControllerProviderInterface.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Api/EventListenerProviderInterface.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Api/LICENSE" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Api/composer.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/AppArgumentValueResolver.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/FormTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/MonologTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/SecurityTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/SwiftmailerTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/TranslationTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/TwigTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Application/UrlGeneratorTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/CallbackResolver.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Controller.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ControllerCollection.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ControllerResolver.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/EventListener/ConverterListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/EventListener/LogListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/EventListener/MiddlewareListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/EventListener/StringToResponseListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Exception/ControllerFrozenException.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ExceptionHandler.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ExceptionListenerWrapper.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/AssetServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/CsrfServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/DoctrineServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/ExceptionHandlerServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Form/SilexFormExtension.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/FormServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/HttpCache/HttpCache.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/HttpCacheServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/HttpFragmentServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/HttpKernelServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/LICENSE" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Locale/LocaleListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/LocaleServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/MonologServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/RememberMeServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Routing/LazyRequestMatcher.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Routing/RedirectableUrlMatcher.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/RoutingServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/SecurityServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/SerializerServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/ServiceControllerServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Session/SessionListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Session/TestSessionListener.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/SessionServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/SwiftmailerServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/TranslationServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/TwigServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/Validator/ConstraintValidatorFactory.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/ValidatorServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/VarDumperServiceProvider.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Provider/composer.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Route.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/Route/SecurityTrait.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ServiceControllerResolver.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/ViewListenerWrapper.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/src/Silex/WebTestCase.php" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/views/base.html.twig" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/resume.iml" afterPath="$PROJECT_DIR$/.idea/resume.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/bin/console" afterPath="$PROJECT_DIR$/bin/console" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/composer.json" afterPath="$PROJECT_DIR$/composer.json" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/composer.lock" afterPath="$PROJECT_DIR$/composer.lock" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/resume.json" afterPath="$PROJECT_DIR$/resume.json" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/web/index.php" afterPath="$PROJECT_DIR$/web/index.php" />
</list>
<ignored path="resume.iws" />
@ -24,7 +96,6 @@
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
<component name="CreatePatchCommitExecutor">
<option name="PATCH_PATH" value="" />
</component>
@ -33,55 +104,76 @@
<favorites_list name="resume" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="index.php" pinned="false" current-in-tab="true">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="index.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/web/index.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="407">
<caret line="39" column="32" selection-start-line="39" selection-start-column="32" selection-end-line="39" selection-end-column="32" />
<state relative-caret-position="579">
<caret line="48" column="29" selection-start-line="48" selection-start-column="29" selection-end-line="48" selection-end-column="29" />
<folding>
<element signature="e#8#47#0#PHP" expanded="true" />
<element signature="e#8#40#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="config.yml" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/config/config.yml">
<file leaf-file-name="ResumeBuilder.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Json/ResumeBuilder.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="22">
<caret line="1" column="15" selection-start-line="1" selection-start-column="15" selection-end-line="1" selection-end-column="15" />
<folding />
<state relative-caret-position="396">
<caret line="27" column="17" selection-start-line="27" selection-start-column="17" selection-end-line="27" selection-end-column="17" />
<folding>
<element signature="e#114#145#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ConfigLoader.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php">
<file leaf-file-name="App.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/App.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="24" column="1" selection-start-line="24" selection-start-column="1" selection-end-line="24" selection-end-column="1" />
<folding />
<state relative-caret-position="306">
<caret line="17" column="25" selection-start-line="17" selection-start-column="25" selection-end-line="17" selection-end-column="25" />
<folding>
<element signature="e#7#39#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Config.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config.php">
<file leaf-file-name="console" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bin/console">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="19" column="32" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="32" />
<folding />
<state relative-caret-position="432">
<caret line="24" column="66" selection-start-line="24" selection-start-column="66" selection-end-line="24" selection-end-column="66" />
<folding>
<element signature="e#26#71#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="resume.json" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/resume.json">
<file leaf-file-name="ConfigServiceProvider.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigServiceProvider.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="50" column="30" selection-start-line="50" selection-start-column="30" selection-end-line="50" selection-end-column="30" />
<folding />
<state relative-caret-position="432">
<caret line="24" column="39" selection-start-line="24" selection-start-column="39" selection-end-line="24" selection-end-column="39" />
<folding>
<element signature="e#6#16#0#PHP" expanded="true" />
<element signature="e#46#67#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ConfigTrait.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigTrait.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="14" column="30" selection-start-line="14" selection-start-column="30" selection-end-line="14" selection-end-column="30" />
<folding>
<element signature="e#6#16#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -94,14 +186,25 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/bin/console" />
<option value="$PROJECT_DIR$/resume.json" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config/YamlFileLoader.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config.php" />
<option value="$PROJECT_DIR$/config/yaml.yml" />
<option value="$PROJECT_DIR$/config/config.yml" />
<option value="$PROJECT_DIR$/package.json" />
<option value="$PROJECT_DIR$/Gruntfile.js" />
<option value="$PROJECT_DIR$/bower.json" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Json/JsonDecoder.php" />
<option value="$PROJECT_DIR$/app/App.php" />
<option value="$PROJECT_DIR$/web/index.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config/ConfigServiceProvider.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Config/ConfigTrait.php" />
<option value="$PROJECT_DIR$/src/Sikofitt/Json/ResumeBuilder.php" />
<option value="$PROJECT_DIR$/composer.json" />
<option value="$PROJECT_DIR$/src/Sikofitt/Command/TestCommand.php" />
<option value="$PROJECT_DIR$/bin/console" />
<option value="$PROJECT_DIR$/src/Sikofitt/Command/SchemaValidationCommand.php" />
</list>
</option>
</component>
@ -113,10 +216,10 @@
</component>
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
<component name="ProjectFrameBounds">
<option name="x" value="227" />
<option name="y" value="78" />
<option name="x" value="146" />
<option name="y" value="31" />
<option name="width" value="1701" />
<option name="height" value="893" />
<option name="height" value="1011" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
@ -143,6 +246,7 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<PATH>
@ -171,7 +275,7 @@
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemId" value="vendor" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
@ -193,6 +297,28 @@
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="Sikofitt" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="Json" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
@ -225,37 +351,59 @@
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="config" />
<option name="myItemId" value="src" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="Sikofitt" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="Command" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="bin" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="resume" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="app" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
<pane id="Scope" />
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="true" />
<property name="js-jscs-nodeInterpreter" value="C:\Program Files\nodejs\node.exe" />
<property name="settings.editor.selected.configurable" value="com.neon.intellij.plugins.gitlab.configurable" />
<property name="settings.editor.splitter.proportion" value="0.2" />
<property name="nodejs_interpreter_path" value="/usr/local/bin/node" />
</component>
<component name="RunManager">
<configuration default="true" type="#PerlConfigurationType" factoryName="Perl">
<option name="SCRIPT_PATH" />
<option name="PROGRAM_PARAMETERS" />
<option name="PERL_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="CHARSET" />
<option name="USE_ALTERNATIVE_SDK" value="false" />
<option name="ALTERNATIVE_SDK_PATH" />
<option name="scriptCharset" value="utf8" />
<option name="startMode" value="RUN" />
<option name="isNonInteractiveModeEnabled" value="false" />
<option name="isCompileTimeBreakpointsEnabled" value="false" />
<option name="initCode" value="" />
<method />
</configuration>
<configuration default="true" type="BashConfigurationType" factoryName="Bash">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="" />
@ -285,6 +433,12 @@
<method />
</configuration>
<configuration default="true" type="js.build_tools.gulp" factoryName="Gulp.js">
<node-interpreter>project</node-interpreter>
<node-options />
<gulpfile />
<tasks />
<arguments />
<envs />
<method />
</configuration>
<configuration default="true" type="js.build_tools.npm" factoryName="npm">
@ -319,32 +473,38 @@
<option name="presentableId" value="Default" />
<updated>1467508860123</updated>
<workItem from="1467508862642" duration="6948000" />
<workItem from="1467586347559" duration="14724000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="6948000" />
<option name="totallyTimeSpent" value="21672000" />
</component>
<component name="ToolWindowManager">
<frame x="227" y="78" width="1701" height="893" extended-state="0" />
<frame x="146" y="31" width="1701" height="1011" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Remote Host" 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="1" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24953903" sideWeight="0.5" order="1" 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.33" sideWeight="0.5" order="9" 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.33" sideWeight="0.5" order="0" 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="0" side_tool="false" content_ui="tabs" />
<window_info id="DB Browser" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="DB Execution Console" 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="-1" side_tool="false" content_ui="tabs" />
<window_info id="Regex Tester" 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="-1" 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.32919955" sideWeight="0.41894352" order="0" side_tool="true" content_ui="tabs" />
<window_info id="GitLabIntegration" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32919955" sideWeight="0.5810565" order="-1" 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.33" sideWeight="0.5" order="1" 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.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="hashGenerator" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32919955" 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="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Remote Host" 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="1" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25258046" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<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="0" 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.25" sideWeight="0.5" order="2" 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.33" sideWeight="0.5" order="0" 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="7" 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="4" side_tool="false" content_ui="combo" />
<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="3" 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="2" 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.33" sideWeight="0.5" order="4" 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="8" 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.33" 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="4" side_tool="false" content_ui="combo" />
<window_info id="Find" 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="4" 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="3" 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="6" side_tool="false" content_ui="tabs" />
</layout>
@ -369,6 +529,14 @@
<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="6" side_tool="false" content_ui="tabs" />
</layout-to-restore>
</component>
<component name="Vcs.Log.UiProperties">
<option name="RECENTLY_FILTERED_USER_GROUPS">
<collection />
</option>
<option name="RECENTLY_FILTERED_BRANCH_GROUPS">
<collection />
</option>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
@ -377,60 +545,181 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/bin/console">
<entry file="file://$PROJECT_DIR$/web/index.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="110">
<caret line="5" column="27" selection-start-line="5" selection-start-column="27" selection-end-line="5" selection-end-column="27" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/resume.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="50" column="30" selection-start-line="50" selection-start-column="30" selection-end-line="50" selection-end-column="30" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/YamlFileLoader.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="20" column="27" selection-start-line="20" selection-start-column="27" selection-end-line="20" selection-end-column="27" />
<folding />
<state relative-caret-position="0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#8#40#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.yml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="22">
<state relative-caret-position="18">
<caret line="1" column="15" selection-start-line="1" selection-start-column="15" selection-end-line="1" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="19" column="32" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="32" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<state relative-caret-position="342">
<caret line="24" column="1" selection-start-line="24" selection-start-column="1" selection-end-line="24" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="19" column="32" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="32" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/resume.json" />
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/YamlFileLoader.php" />
<entry file="file://$PROJECT_DIR$/config/config.yml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="18">
<caret line="1" column="15" selection-start-line="1" selection-start-column="15" selection-end-line="1" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bower.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="576">
<caret line="32" column="28" selection-start-line="32" selection-start-column="28" selection-end-line="32" selection-end-column="28" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="36">
<caret line="7" column="0" selection-start-line="7" selection-start-column="0" selection-end-line="7" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigLoader.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="342">
<caret line="24" column="1" selection-start-line="24" selection-start-column="1" selection-end-line="24" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/Gruntfile.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="7" column="41" selection-start-line="7" selection-start-column="41" selection-end-line="7" selection-end-column="41" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/package.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="11" column="33" selection-start-line="11" selection-start-column="33" selection-end-line="11" selection-end-column="33" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/vendor/groovey/config/src/Providers/ConfigServiceProvider.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="25" column="45" selection-start-line="25" selection-start-column="45" selection-end-line="25" selection-end-column="45" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/vendor/groovey/config/src/Traits/Config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="56" selection-start-line="8" selection-start-column="56" selection-end-line="8" selection-end-column="56" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Json/ResumeBuilder.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="27" column="17" selection-start-line="27" selection-start-column="17" selection-end-line="27" selection-end-column="17" />
<folding>
<element signature="e#114#145#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/composer.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="237">
<caret line="29" column="39" selection-start-line="29" selection-start-column="39" selection-end-line="29" selection-end-column="39" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/App.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="17" column="25" selection-start-line="17" selection-start-column="25" selection-end-line="17" selection-end-column="25" />
<folding>
<element signature="e#7#39#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/web/index.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="407">
<caret line="39" column="32" selection-start-line="39" selection-start-column="32" selection-end-line="39" selection-end-column="32" />
<state relative-caret-position="579">
<caret line="48" column="29" selection-start-line="48" selection-start-column="29" selection-end-line="48" selection-end-column="29" />
<folding>
<element signature="e#8#47#0#PHP" expanded="true" />
<element signature="e#8#40#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Command/SchemaValidationCommand.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="327">
<caret line="50" column="0" selection-start-line="50" selection-start-column="0" selection-end-line="50" selection-end-column="0" />
<folding>
<element signature="e#116#162#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bin/console">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="432">
<caret line="24" column="66" selection-start-line="24" selection-start-column="66" selection-end-line="24" selection-end-column="66" />
<folding>
<element signature="e#26#71#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigServiceProvider.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="432">
<caret line="24" column="39" selection-start-line="24" selection-start-column="39" selection-end-line="24" selection-end-column="39" />
<folding>
<element signature="e#6#16#0#PHP" expanded="true" />
<element signature="e#46#67#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Sikofitt/Config/ConfigTrait.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="14" column="30" selection-start-line="14" selection-start-column="30" selection-end-line="14" selection-end-column="30" />
<folding>
<element signature="e#6#16#0#PHP" expanded="true" />
</folding>
</state>
</provider>

46
Gruntfile.js Normal file
View File

@ -0,0 +1,46 @@
module.exports = function (grunt) {
grunt.initConfig({
bower: {
dist: {
dest: 'web/js/vendor',
options: {
checkExistence: false,
debugging: true,
paths: {
bowerDirectory: 'vendor/bower',
bowerrc: '.bowerrc',
bowerJson: 'bower.json'
}
}
}
},
less: {
build: {
options: {
plugins: [new (require('less-plugin-autoprefix'))({browsers: ["last 3 versions"]}),],
paths: [
'vendor/bower/uikit/less',
'src/Sikofitt/less'
],
strictImports: true,
compress: true
},
files: {
'web/css/resume.min.css': 'src/Sikofitt/less/resume.less'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('main-bower-files');
grunt.loadNpmTasks('grunt-phpunit');
grunt.registerTask('dist', ['bower', 'less']);
grunt.registerTask('default', 'dist');
};

73
app/App.php Normal file
View File

@ -0,0 +1,73 @@
<?php
use Sikofitt\Config\ConfigTrait;
use Silex\Application;
require '../vendor/autoload.php';
/**
* Class App
*/
class App extends Application {
use ConfigTrait;
public $conf;
/**
* Returns the application directory.
*
* @return string
* The main application directory.
*/
public function getAppDirectory() {
$r = new ReflectionClass($this);
return dirname($r->getFileName());
}
/**
* Returns the root directory of the application.
*
* @return string
* The root directory of the application.
*/
public function getRootDirectory() {
return dirname($this->getAppDirectory());
}
/**
* @return string
*/
public function getConfDirectory() {
return $this->getAppDirectory() . '/config';
}
/**
* @return string
*/
public function getDataDirectory() {
return $this->getRootDirectory() . '/data';
}
/**
* @return string
*/
public function getResumeJson() {
return $this->getDataDirectory() . '/resume.json';
}
/**
* @return string
*/
public function getResumeSchema() {
return $this->getDataDirectory() . '/resume.schema.json';
}
/**
* @return \Noodlehaus\Config
*/
public function conf2() {
return Noodlehaus\Config::load($this->getConfDirectory());
}
}

View File

@ -0,0 +1,5 @@
<?php
return [
'app' => 'neat',
];

View File

View File

View File

View File

@ -1,67 +0,0 @@
#!/bin/sh
PHP=`which php`
GIT=`which git`
DIR=`$PHP -r "echo dirname(dirname(realpath('$0')));"`
if [ ! -d "$DIR/build" ]; then
mkdir -p $DIR/build
fi
cd $DIR/build
if [ ! -f "composer.phar" ]; then
curl -s http://getcomposer.org/installer 2>/dev/null | $PHP >/dev/null 2>/dev/null
else
$PHP composer.phar self-update >/dev/null 2>/dev/null
fi
for TYPE in slim fat
do
if [ -d "$DIR/build/skeleton" ]; then
rm -rf $DIR/build/skeleton
fi
mkdir -p $DIR/build/skeleton
cd "$DIR/build/skeleton"
mkdir -p web/
COMPOSER=$TYPE"_composer.json"
cp $DIR/bin/skeleton/$COMPOSER composer.json
cp $DIR/bin/skeleton/index.php web/index.php
$PHP ../composer.phar install -q
if [ -d "$DIR/build/tmp/silex" ]; then
rm -rf $DIR/build/tmp/silex
fi
mkdir -p $DIR/build/tmp/silex
cd "$DIR/build/tmp/silex"
cp -r ../../skeleton/* .
find . -name .DS_Store | xargs rm -rf -
find . -name .git | xargs rm -rf -
find . -name phpunit.xml.* | xargs rm -rf -
find . -type d -name Tests | xargs rm -rf -
find . -type d -name test* | xargs rm -rf -
find . -type d -name doc | xargs rm -rf -
find . -type d -name ext | xargs rm -rf -
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true
export COPYFILE_DISABLE=true
cd "$DIR/build/tmp"
if [ "slim" = "$TYPE" ]; then
NAME="silex"
else
NAME="silex_fat"
fi
rm -f "$DIR/build/$NAME.*"
tar zcpf "$DIR/build/$NAME.tgz" silex
zip -rq "$DIR/build/$NAME.zip" silex
rm -rf "$DIR/build/tmp"
rm -rf "$DIR/build/skeleton"
done

12
bin/console Normal file → Executable file
View File

@ -1,10 +1,13 @@
#!/usr/bin/env php
<?php
//use Symfony\Bundle\FrameworkBundle\Console\Application;
use Sikofitt\Command\SchemaValidationCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Console\Application;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
@ -14,7 +17,8 @@ set_time_limit(0);
/**
* @var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../app/autoload.php';
require_once __DIR__. '/../vendor/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
@ -26,5 +30,5 @@ if ($debug) {
//$kernel = new AppKernel($env, $debug);
$application = new Application();
$application->add(new \Symfony\Bundle\FrameworkBundle\Command\ServerRunCommand());
$application->add(new SchemaValidationCommand());
$application->run($input);

View File

@ -1,23 +0,0 @@
{
"require": {
"silex/silex": "~1.1",
"symfony/browser-kit": "~2.3",
"symfony/console": "~2.3",
"symfony/config": "~2.3",
"symfony/css-selector": "~2.3",
"symfony/dom-crawler": "~2.3",
"symfony/filesystem": "~2.3",
"symfony/finder": "~2.3",
"symfony/form": "~2.3",
"symfony/locale": "~2.3",
"symfony/process": "~2.3",
"symfony/security": "~2.3",
"symfony/serializer": "~2.3",
"symfony/translation": "~2.3",
"symfony/validator": "~2.3",
"symfony/monolog-bridge": "~2.3",
"symfony/twig-bridge": "~2.3",
"doctrine/dbal": ">=2.2.0,<2.4.0-dev",
"swiftmailer/swiftmailer": "5.*"
}
}

View File

@ -1,11 +0,0 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello', function () {
return 'Hello!';
});
$app->run();

View File

@ -1,5 +0,0 @@
{
"require": {
"silex/silex": "~1.1"
}
}

52
bower.json Normal file
View File

@ -0,0 +1,52 @@
{
"name": "resume",
"authors": [
"sikofitt <sikofitt@gmail.com>"
],
"description": "PHP implementation of resume.json",
"main": "",
"license": "GPL-3.0",
"homepage": "code.reric.me",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"vendor/bower",
"test",
"tests"
],
"dependencies": {
"uikit": "^2.26.3",
"html5shiv": "^3.7.3",
"respond": "^1.4.2"
},
"overrides": {
"uikit": {
"main": [
"**/uikit.min.js",
"**/tooltip.min.js",
"**/lightbox.min.js",
"**/smooth-scroll.min.js",
"**/scrollspy.min.js",
"**/parallax.min.js",
"**/offcanvas.min.js"
]
},
"jquery": {
"main": [
"**/jquery.min.js"
]
},
"respond": {
"main": [
"**/respond.min.js"
]
},
"html5shiv": {
"main": [
"**/html5shiv.min.js"
]
}
}
}

View File

@ -1,81 +1,56 @@
{
"name": "silex/silex",
"description": "The PHP micro-framework based on the Symfony Components",
"keywords": ["microframework"],
"homepage": "http://silex.sensiolabs.org",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.5.9",
"pimple/pimple": "~3.0",
"symfony/event-dispatcher": "~2.8|^3.0",
"symfony/http-foundation": "~2.8|^3.0",
"symfony/http-kernel": "~2.8|^3.0",
"symfony/routing": "~2.8|^3.0",
"knplabs/knp-snappy": "^0.4.3",
"h4cc/wkhtmltopdf-amd64": "0.12.x",
"h4cc/wkhtmltoimage-amd64": "0.12.x",
"webmozart/json": "^1.2",
"symfony/yaml": "^3.1",
"monolog/monolog": "^1.20",
"symfony/monolog-bridge": "^3.1",
"google/recaptcha": "^1.1",
"hassankhan/config": "^0.10.0",
"groovey/config": "dev-master"
},
"require-dev": {
"symfony/asset": "~2.8|^3.0",
"symfony/expression-language": "~2.8|^3.0",
"symfony/security": "~2.8|^3.0",
"symfony/form": "~2.8|^3.0",
"symfony/browser-kit": "~2.8|^3.0",
"symfony/css-selector": "~2.8|^3.0",
"symfony/debug": "~2.8|^3.0",
"symfony/dom-crawler": "~2.8|^3.0",
"symfony/finder": "~2.8|^3.0",
"symfony/intl": "~2.8|^3.0",
"symfony/doctrine-bridge": "~2.8|^3.0",
"symfony/options-resolver": "~2.8|^3.0",
"symfony/phpunit-bridge": "~2.8|^3.0",
"symfony/process": "~2.8|^3.0",
"symfony/serializer": "~2.8|^3.0",
"symfony/translation": "~2.8|^3.0",
"symfony/twig-bridge": "~2.8|^3.0",
"symfony/validator": "~2.8|^3.0",
"symfony/var-dumper": "^3.1",
"twig/twig": "~1.8|~2.0",
"doctrine/dbal": "~2.2",
"swiftmailer/swiftmailer": "~5",
"symfony/console": "^3.1",
"texthtml/whoops-silex": "^1.0",
"symfony/framework-bundle": "^3.1"
},
"replace": {
"silex/api": "v2.0.2",
"silex/providers": "v2.0.2"
},
"autoload": {
"psr-4": {
"Silex\\": "src/Silex",
"Sikofitt\\": "src/Sikofitt"
}
},
"autoload-dev" : {
"psr-4": { "Silex\\Tests\\" : "tests/Silex/Tests" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"minimum-stability": "dev"
"name": "sikofitt/resumejson",
"description": "PHP implementation of resume.json",
"keywords": [
"resume.json",
"resume",
"resume.json",
"php",
"silex"
],
"homepage": "http://resume.reric.me/about/resume",
"license": "GPL-3.0",
"authors": [
{
"name": "R. Eric Wheeler",
"email": "sikofitt@gmail.com",
"homepage": "https://code.reric.me"
}
],
"require": {
"php": ">=5.6.0",
"silex/silex": "~2.0",
"symfony/form": "~2.8|^3.0",
"symfony/validator": "~2.8|^3.0",
"symfony/intl": "~2.8|^3.0",
"symfony/asset": "~2.8|^3.0",
"symfony/translation": "~2.8|^3.0",
"symfony/yaml": "^3.1",
"twig/twig": "~1.8|~2.0",
"symfony/twig-bridge": "~2.8|^3.0",
"swiftmailer/swiftmailer": "~5",
"symfony/swiftmailer-bridge": "~2.1",
"knplabs/knp-snappy": "^0.4.3",
"h4cc/wkhtmltopdf-amd64": "0.12.x",
"h4cc/wkhtmltoimage-amd64": "0.12.x",
"webmozart/json": "^1.2",
"monolog/monolog": "^1.20",
"symfony/monolog-bridge": "^3.1",
"google/recaptcha": "^1.1",
"hassankhan/config": "^0.10.0"
},
"require-dev": {
"symfony/debug": "~2.8|^3.0",
"symfony/phpunit-bridge": "~2.8|^3.0",
"symfony/process": "~2.8|^3.0",
"symfony/serializer": "~2.8|^3.0",
"symfony/var-dumper": "^3.1",
"symfony/console": "^3.1",
"texthtml/whoops-silex": "^1.0"
},
"autoload": {
"psr-4": {
"Sikofitt\\": "src/Sikofitt"
}
}
}

3780
composer.lock generated

File diff suppressed because it is too large Load Diff

1
data/bad.schema.json Normal file
View File

@ -0,0 +1 @@
{"array":"neat"}

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "resume.php",
"author": "R. Eric Wheeler <sikofitt@gmail.com>",
"private": true,
"homepage": "https://code.reric.me",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-less": "^1.3.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-phpunit": "^0.3.6",
"less-plugin-autoprefix": "^1.5.1",
"main-bower-files": "^2.13.1"
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* Created by PhpStorm.
* User: eric
* Date: 7/3/16
* Time: 7:37 PM
*/
namespace Sikofitt\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Webmozart\Json\JsonDecoder;
use Webmozart\Json\JsonValidator;
/**
* Class TestCommand
* @package Sikofitt\Command
*/
class SchemaValidationCommand extends Command
{
private $file;
private $schema;
/**
* Configures the command.
*
*/
public function configure ()
{
$this->setName ('resume:schema:validate')
->setDescription ('Validates resume.json schema')
->setProcessTitle ('Validating Schema');
}
/**
* Unset parameters that we need to possibly get.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
public function interact (InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this->file = $io->ask('Path to file? ');
$this->schema = $io->ask('Path to schema? ');
}
/**
* Command execute logic.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
*/
public function execute (InputInterface $input, OutputInterface $output)
{
$validator = new JsonValidator();
$decoder = new JsonDecoder();
$io = new SymfonyStyle($input, $output);
$dataDir = dirname(dirname(dirname(__DIR__))) . '/data/';
try {
$decoded = $decoder->decodeFile($dataDir . $this->file);
$errors = $validator->validate ($decoded, $dataDir . $this->schema);
} catch(\Exception $e) {
$class = new \ReflectionClass($e);
$io->block([$class->getName(), $e->getMessage()], 'Exception', 'error');
exit(255);
}
if(isset($errors) && !empty($errors)) {
$io->block($errors, 'Error', 'error');
} else {
$io->block([$this->file, 'There were no errors reported.'], 'Valid Schema', 'fg=black;bg=green');
}
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Eric
* Date: 07/03/2016
* Time: 8:34 AM
*/
namespace Sikofitt;
use Noodlehaus\AbstractConfig;
class Config extends AbstractConfig
{
public function getDefaults()
{
return [
'app' => [
'debug' => true,
'base_dir' => dirname(dirname(__DIR__)),
],
];
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Eric
* Date: 07/02/2016
* Time: 8:03 PM
*/
namespace Sikofitt\Config;
use Sikofitt\Config\YamlFileLoader;
class ConfigLoader
{
private $testing;
public function __construct()
{
$r = new \ReflectionClass($this);
$this->testing = explode("\\", $r->getName());
$this->testing[] = __DIR__;
return $this->testing;
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
*
*/
namespace Sikofitt\Config;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Application;
use Noodlehaus\Config;
/**
* Class ConfigServiceProvider
* @package Sikofitt\Config
*/
class ConfigServiceProvider implements ServiceProviderInterface
{
/**
* @param Container $app
*/
public function register (Container $app)
{
$app['config'] = function($app) {
$config = Config::load($app['config.path']);
return $config;
};
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
*
*/
namespace Sikofitt\Config;
trait ConfigTrait
{
/**
* @param $name
* @param null $value
* @return mixed
*/
public function config($name, $value = null) {
if(null === $value) {
return $this['config']->get ($name);
} else {
$this['config']->set($name, $value);
}
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* Created by PhpStorm.
* User: eric
* Date: 7/3/16
* Time: 5:55 PM
*/
namespace Sikofitt\Json;
use Webmozart\Json\JsonDecoder;
use Webmozart\Json\JsonEncoder;
use Webmozart\Json\DecodingFailedException;
use Webmozart\Json\EncodingFailedException;
use Webmozart\Json\JsonValidator;
use Webmozart\Json\ValidationFailedException;
use Webmozart\Json\FileNotFoundException;
use Webmozart\Json\IOException;
use App;
/**
* Class ResumeBuilder
* @package Sikofitt\Json
*/
class ResumeBuilder
{
private $app;
public function __construct (App $app)
{
$this->app = $app;
}
public function toJson ($resumeArray, array $options = array ())
{
$encoder = new JsonEncoder();
$validator = new JsonValidator();
if(!isset($options['file'])) {
throw new \InvalidArgumentException('file is a required argument.');
}
$errors = $validator->validate((object)$resumeArray, $options['app']->getResumeSchema());
dump($errors);
try {
// $encoder->encodeFile ($resumeArray, 'test.json');
} catch (\Exception $e) {
$r = new \ReflectionClass($e);
$exceptionClass = $r->getName();
return new $exceptionClass($e->getMessage());
}
}
public function fromJson ($resumeJson, array $options = array ())
{
$decoder = new JsonDecoder();
$resumeObject = $decoder->decodeFile($this->app->getResumeJson(), $this->app->getResumeSchema());
return $resumeObject;
}
}

View File

@ -0,0 +1 @@
@import 'uikit.less';

View File

@ -1,33 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Api;
use Silex\Application;
/**
* Interface for bootable service providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface BootableProviderInterface
{
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*
* @param Application $app
*/
public function boot(Application $app);
}

View File

@ -1,32 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Api;
use Silex\Application;
use Silex\ControllerCollection;
/**
* Interface for controller providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface ControllerProviderInterface
{
/**
* Returns routes to connect to the given application.
*
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app);
}

View File

@ -1,25 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Api;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Pimple\Container;
/**
* Interface for event listener providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface EventListenerProviderInterface
{
public function subscribe(Container $app, EventDispatcherInterface $dispatcher);
}

View File

@ -1,19 +0,0 @@
Copyright (c) 2010-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,34 +0,0 @@
{
"minimum-stability": "dev",
"name": "silex/api",
"description": "The Silex interfaces",
"keywords": ["microframework"],
"homepage": "http://silex.sensiolabs.org",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.5.9",
"pimple/pimple": "~3.0"
},
"suggest": {
"symfony/event-dispatcher": "For EventListenerProviderInterface",
"silex/silex": "For BootableProviderInterface and ControllerProviderInterface"
},
"autoload": {
"psr-4": { "Silex\\Api\\": "" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}

View File

@ -1,47 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
/**
* HttpKernel Argument Resolver for Silex.
*
* @author Romain Neutron <imprec@gmail.com>
*/
class AppArgumentValueResolver implements ArgumentValueResolverInterface
{
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* {@inheritdoc}
*/
public function supports(Request $request, ArgumentMetadata $argument)
{
return $argument->getType() === Application::class || (null !== $argument->getType() && in_array(Application::class, class_parents($argument->getType()), true));
}
/**
* {@inheritdoc}
*/
public function resolve(Request $request, ArgumentMetadata $argument)
{
yield $this->app;
}
}

View File

@ -1,506 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Silex\Api\BootableProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Provider\ExceptionHandlerServiceProvider;
use Silex\Provider\RoutingServiceProvider;
use Silex\Provider\HttpKernelServiceProvider;
/**
* The Silex framework class.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Application extends Container implements HttpKernelInterface, TerminableInterface
{
const VERSION = '2.0.2';
const EARLY_EVENT = 512;
const LATE_EVENT = -512;
protected $providers = array();
protected $booted = false;
/**
* Instantiate a new Application.
*
* Objects and parameters can be passed as argument to the constructor.
*
* @param array $values The parameters or objects.
*/
public function __construct(array $values = array())
{
parent::__construct();
$this['request.http_port'] = 80;
$this['request.https_port'] = 443;
$this['debug'] = false;
$this['charset'] = 'UTF-8';
$this['logger'] = null;
$this->register(new HttpKernelServiceProvider());
$this->register(new RoutingServiceProvider());
$this->register(new ExceptionHandlerServiceProvider());
foreach ($values as $key => $value) {
$this[$key] = $value;
}
}
/**
* Registers a service provider.
*
* @param ServiceProviderInterface $provider A ServiceProviderInterface instance
* @param array $values An array of values that customizes the provider
*
* @return Application
*/
public function register(ServiceProviderInterface $provider, array $values = array())
{
$this->providers[] = $provider;
parent::register($provider, $values);
return $this;
}
/**
* Boots all service providers.
*
* This method is automatically called by handle(), but you can use it
* to boot all service providers when not handling a request.
*/
public function boot()
{
if ($this->booted) {
return;
}
$this->booted = true;
foreach ($this->providers as $provider) {
if ($provider instanceof EventListenerProviderInterface) {
$provider->subscribe($this, $this['dispatcher']);
}
if ($provider instanceof BootableProviderInterface) {
$provider->boot($this);
}
}
}
/**
* Maps a pattern to a callable.
*
* You can optionally specify HTTP methods that should be matched.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function match($pattern, $to = null)
{
return $this['controllers']->match($pattern, $to);
}
/**
* Maps a GET request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function get($pattern, $to = null)
{
return $this['controllers']->get($pattern, $to);
}
/**
* Maps a POST request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function post($pattern, $to = null)
{
return $this['controllers']->post($pattern, $to);
}
/**
* Maps a PUT request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function put($pattern, $to = null)
{
return $this['controllers']->put($pattern, $to);
}
/**
* Maps a DELETE request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function delete($pattern, $to = null)
{
return $this['controllers']->delete($pattern, $to);
}
/**
* Maps an OPTIONS request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function options($pattern, $to = null)
{
return $this['controllers']->options($pattern, $to);
}
/**
* Maps a PATCH request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function patch($pattern, $to = null)
{
return $this['controllers']->patch($pattern, $to);
}
/**
* Adds an event listener that listens on the specified events.
*
* @param string $eventName The event to listen on
* @param callable $callback The listener
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function on($eventName, $callback, $priority = 0)
{
if ($this->booted) {
$this['dispatcher']->addListener($eventName, $this['callback_resolver']->resolveCallback($callback), $priority);
return;
}
$this->extend('dispatcher', function (EventDispatcherInterface $dispatcher, $app) use ($callback, $priority, $eventName) {
$dispatcher->addListener($eventName, $app['callback_resolver']->resolveCallback($callback), $priority);
return $dispatcher;
});
}
/**
* Registers a before filter.
*
* Before filters are run before any route has been matched.
*
* @param mixed $callback Before filter callback
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function before($callback, $priority = 0)
{
$app = $this;
$this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($callback, $app) {
if (!$event->isMasterRequest()) {
return;
}
$ret = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $app);
if ($ret instanceof Response) {
$event->setResponse($ret);
}
}, $priority);
}
/**
* Registers an after filter.
*
* After filters are run after the controller has been executed.
*
* @param mixed $callback After filter callback
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function after($callback, $priority = 0)
{
$app = $this;
$this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($callback, $app) {
if (!$event->isMasterRequest()) {
return;
}
$response = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app);
if ($response instanceof Response) {
$event->setResponse($response);
} elseif (null !== $response) {
throw new \RuntimeException('An after middleware returned an invalid response value. Must return null or an instance of Response.');
}
}, $priority);
}
/**
* Registers a finish filter.
*
* Finish filters are run after the response has been sent.
*
* @param mixed $callback Finish filter callback
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function finish($callback, $priority = 0)
{
$app = $this;
$this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($callback, $app) {
call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app);
}, $priority);
}
/**
* Aborts the current request by sending a proper HTTP error.
*
* @param int $statusCode The HTTP status code
* @param string $message The status message
* @param array $headers An array of HTTP headers
*/
public function abort($statusCode, $message = '', array $headers = array())
{
throw new HttpException($statusCode, $message, null, $headers);
}
/**
* Registers an error handler.
*
* Error handlers are simple callables which take a single Exception
* as an argument. If a controller throws an exception, an error handler
* can return a specific response.
*
* When an exception occurs, all handlers will be called, until one returns
* something (a string or a Response object), at which point that will be
* returned to the client.
*
* For this reason you should add logging handlers before output handlers.
*
* @param mixed $callback Error handler callback, takes an Exception argument
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to -8)
*/
public function error($callback, $priority = -8)
{
$this->on(KernelEvents::EXCEPTION, new ExceptionListenerWrapper($this, $callback), $priority);
}
/**
* Registers a view handler.
*
* View handlers are simple callables which take a controller result and the
* request as arguments, whenever a controller returns a value that is not
* an instance of Response. When this occurs, all suitable handlers will be
* called, until one returns a Response object.
*
* @param mixed $callback View handler callback
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function view($callback, $priority = 0)
{
$this->on(KernelEvents::VIEW, new ViewListenerWrapper($this, $callback), $priority);
}
/**
* Flushes the controller collection.
*/
public function flush()
{
$this['routes']->addCollection($this['controllers']->flush());
}
/**
* Redirects the user to another URL.
*
* @param string $url The URL to redirect to
* @param int $status The status code (302 by default)
*
* @return RedirectResponse
*/
public function redirect($url, $status = 302)
{
return new RedirectResponse($url, $status);
}
/**
* Creates a streaming response.
*
* @param mixed $callback A valid PHP callback
* @param int $status The response status code
* @param array $headers An array of response headers
*
* @return StreamedResponse
*/
public function stream($callback = null, $status = 200, array $headers = array())
{
return new StreamedResponse($callback, $status, $headers);
}
/**
* Escapes a text for HTML.
*
* @param string $text The input text to be escaped
* @param int $flags The flags (@see htmlspecialchars)
* @param string $charset The charset
* @param bool $doubleEncode Whether to try to avoid double escaping or not
*
* @return string Escaped text
*/
public function escape($text, $flags = ENT_COMPAT, $charset = null, $doubleEncode = true)
{
return htmlspecialchars($text, $flags, $charset ?: $this['charset'], $doubleEncode);
}
/**
* Convert some data into a JSON response.
*
* @param mixed $data The response data
* @param int $status The response status code
* @param array $headers An array of response headers
*
* @return JsonResponse
*/
public function json($data = array(), $status = 200, array $headers = array())
{
return new JsonResponse($data, $status, $headers);
}
/**
* Sends a file.
*
* @param \SplFileInfo|string $file The file to stream
* @param int $status The response status code
* @param array $headers An array of response headers
* @param null|string $contentDisposition The type of Content-Disposition to set automatically with the filename
*
* @return BinaryFileResponse
*/
public function sendFile($file, $status = 200, array $headers = array(), $contentDisposition = null)
{
return new BinaryFileResponse($file, $status, $headers, true, $contentDisposition);
}
/**
* Mounts controllers under the given route prefix.
*
* @param string $prefix The route prefix
* @param ControllerCollection|callable|ControllerProviderInterface $controllers A ControllerCollection, a callable, or a ControllerProviderInterface instance
*
* @return Application
*
* @throws \LogicException
*/
public function mount($prefix, $controllers)
{
if ($controllers instanceof ControllerProviderInterface) {
$connectedControllers = $controllers->connect($this);
if (!$connectedControllers instanceof ControllerCollection) {
throw new \LogicException(sprintf('The method "%s::connect" must return a "ControllerCollection" instance. Got: "%s"', get_class($controllers), is_object($connectedControllers) ? get_class($connectedControllers) : gettype($connectedControllers)));
}
$controllers = $connectedControllers;
} elseif (!$controllers instanceof ControllerCollection && !is_callable($controllers)) {
throw new \LogicException('The "mount" method takes either a "ControllerCollection" instance, "ControllerProviderInterface" instance, or a callable.');
}
$this['controllers']->mount($prefix, $controllers);
return $this;
}
/**
* Handles the request and delivers the response.
*
* @param Request|null $request Request to process
*/
public function run(Request $request = null)
{
if (null === $request) {
$request = Request::createFromGlobals();
}
$response = $this->handle($request);
$response->send();
$this->terminate($request, $response);
}
/**
* {@inheritdoc}
*
* If you call this method directly instead of run(), you must call the
* terminate() method yourself if you want the finish filters to be run.
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
if (!$this->booted) {
$this->boot();
}
$this->flush();
return $this['kernel']->handle($request, $type, $catch);
}
/**
* {@inheritdoc}
*/
public function terminate(Request $request, Response $response)
{
$this['kernel']->terminate($request, $response);
}
}

View File

@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
use Symfony\Component\Form;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\OptionsResolver\OptionsResolver\FormTypeInterface;
/**
* Form trait.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author David Berlioz <berliozdavid@gmail.com>
*/
trait FormTrait
{
/**
* Creates and returns a form builder instance.
*
* @param mixed $data The initial data for the form
* @param array $options Options for the form
* @param string|FormTypeInterface $type Type of the form
*
* @return FormBuilder
*/
public function form($data = null, array $options = array(), $type = null)
{
return $this['form.factory']->createBuilder($type ?: FormType::class, $data, $options);
}
/**
* Creates and returns a named form builder instance.
*
* @param string $name
* @param mixed $data The initial data for the form
* @param array $options Options for the form
* @param string|FormTypeInterface $type Type of the form
*
* @return FormBuilder
*/
public function namedForm($name, $data = null, array $options = array(), $type = null)
{
return $this['form.factory']->createNamedBuilder($name, $type ?: FormType::class, $data, $options);
}
}

View File

@ -1,36 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
use Monolog\Logger;
/**
* Monolog trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait MonologTrait
{
/**
* Adds a log record.
*
* @param string $message The log message
* @param array $context The log context
* @param int $level The logging level
*
* @return bool Whether the record has been processed
*/
public function log($message, array $context = array(), $level = Logger::INFO)
{
return $this['monolog']->addRecord($level, $message, $context);
}
}

View File

@ -1,53 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Security trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait SecurityTrait
{
/**
* Encodes the raw password.
*
* @param UserInterface $user A UserInterface instance
* @param string $password The password to encode
*
* @return string The encoded password
*
* @throws \RuntimeException when no password encoder could be found for the user
*/
public function encodePassword(UserInterface $user, $password)
{
return $this['security.encoder_factory']->getEncoder($user)->encodePassword($password, $user->getSalt());
}
/**
* Checks if the attributes are granted against the current authentication token and optionally supplied object.
*
* @param mixed $attributes
* @param mixed $object
*
* @return bool
*
* @throws AuthenticationCredentialsNotFoundException when the token storage has no authentication token.
*/
public function isGranted($attributes, $object = null)
{
return $this['security.authorization_checker']->isGranted($attributes, $object);
}
}

View File

@ -1,33 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
/**
* Swiftmailer trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait SwiftmailerTrait
{
/**
* Sends an email.
*
* @param \Swift_Message $message A \Swift_Message instance
* @param array $failedRecipients An array of failures by-reference
*
* @return int The number of sent messages
*/
public function mail(\Swift_Message $message, &$failedRecipients = null)
{
return $this['mailer']->send($message, $failedRecipients);
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
/**
* Translation trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait TranslationTrait
{
/**
* Translates the given message.
*
* @param string $id The message id
* @param array $parameters An array of parameters for the message
* @param string $domain The domain for the message
* @param string $locale The locale
*
* @return string The translated string
*/
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
{
return $this['translator']->trans($id, $parameters, $domain, $locale);
}
/**
* Translates the given choice message by choosing a translation according to a number.
*
* @param string $id The message id
* @param int $number The number to use to find the indice of the message
* @param array $parameters An array of parameters for the message
* @param string $domain The domain for the message
* @param string $locale The locale
*
* @return string The translated string
*/
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
return $this['translator']->transChoice($id, $number, $parameters, $domain, $locale);
}
}

View File

@ -1,65 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* Twig trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait TwigTrait
{
/**
* Renders a view and returns a Response.
*
* To stream a view, pass an instance of StreamedResponse as a third argument.
*
* @param string $view The view name
* @param array $parameters An array of parameters to pass to the view
* @param Response $response A Response instance
*
* @return Response A Response instance
*/
public function render($view, array $parameters = array(), Response $response = null)
{
$twig = $this['twig'];
if ($response instanceof StreamedResponse) {
$response->setCallback(function () use ($twig, $view, $parameters) {
$twig->display($view, $parameters);
});
} else {
if (null === $response) {
$response = new Response();
}
$response->setContent($twig->render($view, $parameters));
}
return $response;
}
/**
* Renders a view.
*
* @param string $view The view name
* @param array $parameters An array of parameters to pass to the view
*
* @return string The rendered view
*/
public function renderView($view, array $parameters = array())
{
return $this['twig']->render($view, $parameters);
}
}

View File

@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Application;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* UrlGenerator trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait UrlGeneratorTrait
{
/**
* Generates a path from the given parameters.
*
* @param string $route The name of the route
* @param mixed $parameters An array of parameters
*
* @return string The generated path
*/
public function path($route, $parameters = array())
{
return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
}
/**
* Generates an absolute URL from the given parameters.
*
* @param string $route The name of the route
* @param mixed $parameters An array of parameters
*
* @return string The generated URL
*/
public function url($route, $parameters = array())
{
return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
}
}

View File

@ -1,78 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Pimple\Container;
class CallbackResolver
{
const SERVICE_PATTERN = "/[A-Za-z0-9\._\-]+:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/";
private $app;
public function __construct(Container $app)
{
$this->app = $app;
}
/**
* Returns true if the string is a valid service method representation.
*
* @param string $name
*
* @return bool
*/
public function isValid($name)
{
return is_string($name) && (preg_match(static::SERVICE_PATTERN, $name) || isset($this->app[$name]));
}
/**
* Returns a callable given its string representation.
*
* @param string $name
*
* @return callable
*
* @throws \InvalidArgumentException In case the method does not exist.
*/
public function convertCallback($name)
{
if (preg_match(static::SERVICE_PATTERN, $name)) {
list($service, $method) = explode(':', $name, 2);
$callback = array($this->app[$service], $method);
} else {
$service = $name;
$callback = $this->app[$name];
}
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('Service "%s" is not callable.', $service));
}
return $callback;
}
/**
* Returns a callable given its string representation if it is a valid service method.
*
* @param string $name
*
* @return string|callable A callable value or the string passed in
*
* @throws \InvalidArgumentException In case the method does not exist.
*/
public function resolveCallback($name)
{
return $this->isValid($name) ? $this->convertCallback($name) : $name;
}
}

View File

@ -1,122 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Silex\Exception\ControllerFrozenException;
/**
* A wrapper for a controller, mapped to a route.
*
* __call() forwards method-calls to Route, but returns instance of Controller
* listing Route's methods below, so that IDEs know they are valid
*
* @method Controller assert(string $variable, string $regexp)
* @method Controller value(string $variable, mixed $default)
* @method Controller convert(string $variable, mixed $callback)
* @method Controller method(string $method)
* @method Controller requireHttp()
* @method Controller requireHttps()
* @method Controller before(mixed $callback)
* @method Controller after(mixed $callback)
* @method Controller when(string $condition)
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class Controller
{
private $route;
private $routeName;
private $isFrozen = false;
/**
* Constructor.
*
* @param Route $route
*/
public function __construct(Route $route)
{
$this->route = $route;
}
/**
* Gets the controller's route.
*
* @return Route
*/
public function getRoute()
{
return $this->route;
}
/**
* Gets the controller's route name.
*
* @return string
*/
public function getRouteName()
{
return $this->routeName;
}
/**
* Sets the controller's route.
*
* @param string $routeName
*
* @return Controller $this The current Controller instance
*/
public function bind($routeName)
{
if ($this->isFrozen) {
throw new ControllerFrozenException(sprintf('Calling %s on frozen %s instance.', __METHOD__, __CLASS__));
}
$this->routeName = $routeName;
return $this;
}
public function __call($method, $arguments)
{
if (!method_exists($this->route, $method)) {
throw new \BadMethodCallException(sprintf('Method "%s::%s" does not exist.', get_class($this->route), $method));
}
call_user_func_array(array($this->route, $method), $arguments);
return $this;
}
/**
* Freezes the controller.
*
* Once the controller is frozen, you can no longer change the route name
*/
public function freeze()
{
$this->isFrozen = true;
}
public function generateRouteName($prefix)
{
$methods = implode('_', $this->route->getMethods()).'_';
$routeName = $methods.$prefix.$this->route->getPath();
$routeName = str_replace(array('/', ':', '|', '-'), '_', $routeName);
$routeName = preg_replace('/[^a-z0-9A-Z_.]+/', '', $routeName);
// Collapse consecutive underscores down into a single underscore.
$routeName = preg_replace('/_+/', '_', $routeName);
return $routeName;
}
}

View File

@ -1,239 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds Silex controllers.
*
* It acts as a staging area for routes. You are able to set the route name
* until flush() is called, at which point all controllers are frozen and
* converted to a RouteCollection.
*
* __call() forwards method-calls to Route, but returns instance of ControllerCollection
* listing Route's methods below, so that IDEs know they are valid
*
* @method ControllerCollection assert(string $variable, string $regexp)
* @method ControllerCollection value(string $variable, mixed $default)
* @method ControllerCollection convert(string $variable, mixed $callback)
* @method ControllerCollection method(string $method)
* @method ControllerCollection requireHttp()
* @method ControllerCollection requireHttps()
* @method ControllerCollection before(mixed $callback)
* @method ControllerCollection after(mixed $callback)
* @method ControllerCollection when(string $condition)
*
* @author Igor Wiedler <igor@wiedler.ch>
* @author Fabien Potencier <fabien@symfony.com>
*/
class ControllerCollection
{
protected $controllers = array();
protected $defaultRoute;
protected $defaultController;
protected $prefix;
protected $routesFactory;
protected $controllersFactory;
public function __construct(Route $defaultRoute, RouteCollection $routesFactory = null, $controllersFactory = null)
{
$this->defaultRoute = $defaultRoute;
$this->routesFactory = $routesFactory;
$this->controllersFactory = $controllersFactory;
$this->defaultController = function (Request $request) {
throw new \LogicException(sprintf('The "%s" route must have code to run when it matches.', $request->attributes->get('_route')));
};
}
/**
* Mounts controllers under the given route prefix.
*
* @param string $prefix The route prefix
* @param ControllerCollection|callable $controllers A ControllerCollection instance or a callable for defining routes
*
* @throws \LogicException
*/
public function mount($prefix, $controllers)
{
if (is_callable($controllers)) {
$collection = $this->controllersFactory ? call_user_func($this->controllersFactory) : new static(new Route(), new RouteCollection());
call_user_func($controllers, $collection);
$controllers = $collection;
} elseif (!$controllers instanceof self) {
throw new \LogicException('The "mount" method takes either a "ControllerCollection" instance or callable.');
}
$controllers->prefix = $prefix;
$this->controllers[] = $controllers;
}
/**
* Maps a pattern to a callable.
*
* You can optionally specify HTTP methods that should be matched.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function match($pattern, $to = null)
{
$route = clone $this->defaultRoute;
$route->setPath($pattern);
$this->controllers[] = $controller = new Controller($route);
$route->setDefault('_controller', null === $to ? $this->defaultController : $to);
return $controller;
}
/**
* Maps a GET request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function get($pattern, $to = null)
{
return $this->match($pattern, $to)->method('GET');
}
/**
* Maps a POST request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function post($pattern, $to = null)
{
return $this->match($pattern, $to)->method('POST');
}
/**
* Maps a PUT request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function put($pattern, $to = null)
{
return $this->match($pattern, $to)->method('PUT');
}
/**
* Maps a DELETE request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function delete($pattern, $to = null)
{
return $this->match($pattern, $to)->method('DELETE');
}
/**
* Maps an OPTIONS request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function options($pattern, $to = null)
{
return $this->match($pattern, $to)->method('OPTIONS');
}
/**
* Maps a PATCH request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function patch($pattern, $to = null)
{
return $this->match($pattern, $to)->method('PATCH');
}
public function __call($method, $arguments)
{
if (!method_exists($this->defaultRoute, $method)) {
throw new \BadMethodCallException(sprintf('Method "%s::%s" does not exist.', get_class($this->defaultRoute), $method));
}
call_user_func_array(array($this->defaultRoute, $method), $arguments);
foreach ($this->controllers as $controller) {
call_user_func_array(array($controller, $method), $arguments);
}
return $this;
}
/**
* Persists and freezes staged controllers.
*
* @return RouteCollection A RouteCollection instance
*/
public function flush()
{
if (null === $this->routesFactory) {
$routes = new RouteCollection();
} else {
$routes = $this->routesFactory;
}
return $this->doFlush('', $routes);
}
private function doFlush($prefix, RouteCollection $routes)
{
if ($prefix !== '') {
$prefix = '/'.trim(trim($prefix), '/');
}
foreach ($this->controllers as $controller) {
if ($controller instanceof Controller) {
$controller->getRoute()->setPath($prefix.$controller->getRoute()->getPath());
if (!$name = $controller->getRouteName()) {
$name = $base = $controller->generateRouteName('');
$i = 0;
while ($routes->get($name)) {
$name = $base.'_'.++$i;
}
$controller->bind($name);
}
$routes->add($name, $controller->getRoute());
$controller->freeze();
} else {
$controller->doFlush($prefix.$controller->prefix, $routes);
}
}
$this->controllers = array();
return $routes;
}
}

View File

@ -1,54 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver;
use Symfony\Component\HttpFoundation\Request;
/**
* Adds Application as a valid argument for controllers.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated This class can be dropped once Symfony 3.0 is not supported anymore.
*/
class ControllerResolver extends BaseControllerResolver
{
protected $app;
/**
* Constructor.
*
* @param Application $app An Application instance
* @param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct(Application $app, LoggerInterface $logger = null)
{
$this->app = $app;
parent::__construct($logger);
}
protected function doGetArguments(Request $request, $controller, array $parameters)
{
foreach ($parameters as $param) {
if ($param->getClass() && $param->getClass()->isInstance($this->app)) {
$request->attributes->set($param->getName(), $this->app);
break;
}
}
return parent::doGetArguments($request, $controller, $parameters);
}
}

View File

@ -1,66 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\EventListener;
use Silex\CallbackResolver;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouteCollection;
/**
* Handles converters.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ConverterListener implements EventSubscriberInterface
{
protected $routes;
protected $callbackResolver;
/**
* Constructor.
*
* @param RouteCollection $routes A RouteCollection instance
* @param CallbackResolver $callbackResolver A CallbackResolver instance
*/
public function __construct(RouteCollection $routes, CallbackResolver $callbackResolver)
{
$this->routes = $routes;
$this->callbackResolver = $callbackResolver;
}
/**
* Handles converters.
*
* @param FilterControllerEvent $event The event to handle
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $converters = $route->getOption('_converters')) {
foreach ($converters as $name => $callback) {
$callback = $this->callbackResolver->resolveCallback($callback);
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
}
}
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::CONTROLLER => 'onKernelController',
);
}
}

View File

@ -1,134 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\EventListener;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Logs request, response, and exceptions.
*/
class LogListener implements EventSubscriberInterface
{
protected $logger;
protected $exceptionLogFilter;
public function __construct(LoggerInterface $logger, $exceptionLogFilter = null)
{
$this->logger = $logger;
if (null === $exceptionLogFilter) {
$exceptionLogFilter = function (\Exception $e) {
if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
return LogLevel::ERROR;
}
return LogLevel::CRITICAL;
};
}
$this->exceptionLogFilter = $exceptionLogFilter;
}
/**
* Logs master requests on event KernelEvents::REQUEST.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logRequest($event->getRequest());
}
/**
* Logs master response on event KernelEvents::RESPONSE.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logResponse($event->getResponse());
}
/**
* Logs uncaught exceptions on event KernelEvents::EXCEPTION.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$this->logException($event->getException());
}
/**
* Logs a request.
*
* @param Request $request
*/
protected function logRequest(Request $request)
{
$this->logger->log(LogLevel::DEBUG, '> '.$request->getMethod().' '.$request->getRequestUri());
}
/**
* Logs a response.
*
* @param Response $response
*/
protected function logResponse(Response $response)
{
$message = '< '.$response->getStatusCode();
if ($response instanceof RedirectResponse) {
$message .= ' '.$response->getTargetUrl();
}
$this->logger->log(LogLevel::DEBUG, $message);
}
/**
* Logs an exception.
*/
protected function logException(\Exception $e)
{
$this->logger->log(call_user_func($this->exceptionLogFilter, $e), sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), array('exception' => $e));
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array('onKernelRequest', 0),
KernelEvents::RESPONSE => array('onKernelResponse', 0),
/*
* Priority -4 is used to come after those from SecurityServiceProvider (0)
* but before the error handlers added with Silex\Application::error (defaults to -8)
*/
KernelEvents::EXCEPTION => array('onKernelException', -4),
);
}
}

View File

@ -1,96 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\EventListener;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Silex\Application;
/**
* Manages the route middlewares.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class MiddlewareListener implements EventSubscriberInterface
{
protected $app;
/**
* Constructor.
*
* @param Application $app An Application instance
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Runs before filters.
*
* @param GetResponseEvent $event The event to handle
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$routeName = $request->attributes->get('_route');
if (!$route = $this->app['routes']->get($routeName)) {
return;
}
foreach ((array) $route->getOption('_before_middlewares') as $callback) {
$ret = call_user_func($this->app['callback_resolver']->resolveCallback($callback), $request, $this->app);
if ($ret instanceof Response) {
$event->setResponse($ret);
return;
} elseif (null !== $ret) {
throw new \RuntimeException(sprintf('A before middleware for route "%s" returned an invalid response value. Must return null or an instance of Response.', $routeName));
}
}
}
/**
* Runs after filters.
*
* @param FilterResponseEvent $event The event to handle
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$routeName = $request->attributes->get('_route');
if (!$route = $this->app['routes']->get($routeName)) {
return;
}
foreach ((array) $route->getOption('_after_middlewares') as $callback) {
$response = call_user_func($this->app['callback_resolver']->resolveCallback($callback), $request, $event->getResponse(), $this->app);
if ($response instanceof Response) {
$event->setResponse($response);
} elseif (null !== $response) {
throw new \RuntimeException(sprintf('An after middleware for route "%s" returned an invalid response value. Must return null or an instance of Response.', $routeName));
}
}
}
public static function getSubscribedEvents()
{
return array(
// this must be executed after the late events defined with before() (and their priority is -512)
KernelEvents::REQUEST => array('onKernelRequest', -1024),
KernelEvents::RESPONSE => array('onKernelResponse', 128),
);
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\EventListener;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* Converts string responses to proper Response instances.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class StringToResponseListener implements EventSubscriberInterface
{
/**
* Handles string responses.
*
* @param GetResponseForControllerResultEvent $event The event to handle
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$response = $event->getControllerResult();
if (!(
null === $response
|| is_array($response)
|| $response instanceof Response
|| (is_object($response) && !method_exists($response, '__toString'))
)) {
$event->setResponse(new Response((string) $response));
}
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::VIEW => array('onKernelView', -10),
);
}
}

View File

@ -1,21 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Exception;
/**
* Exception, is thrown when a frozen controller is modified.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class ControllerFrozenException extends \RuntimeException
{
}

View File

@ -1,56 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Debug\ExceptionHandler as DebugExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Default exception handler.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ExceptionHandler implements EventSubscriberInterface
{
protected $debug;
public function __construct($debug)
{
$this->debug = $debug;
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
$handler = new DebugExceptionHandler($this->debug);
$exception = $event->getException();
if (!$exception instanceof FlattenException) {
$exception = FlattenException::create($exception);
}
$response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset'));
$event->setResponse($response);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(KernelEvents::EXCEPTION => array('onSilexError', -255));
}
}

View File

@ -1,93 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
/**
* Wraps exception listeners.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ExceptionListenerWrapper
{
protected $app;
protected $callback;
/**
* Constructor.
*
* @param Application $app An Application instance
* @param callable $callback
*/
public function __construct(Application $app, $callback)
{
$this->app = $app;
$this->callback = $callback;
}
public function __invoke(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$this->callback = $this->app['callback_resolver']->resolveCallback($this->callback);
if (!$this->shouldRun($exception)) {
return;
}
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$response = call_user_func($this->callback, $exception, $event->getRequest(), $code);
$this->ensureResponse($response, $event);
}
protected function shouldRun(\Exception $exception)
{
if (is_array($this->callback)) {
$callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]);
} elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($this->callback);
$callbackReflection = $callbackReflection->getMethod('__invoke');
} else {
$callbackReflection = new \ReflectionFunction($this->callback);
}
if ($callbackReflection->getNumberOfParameters() > 0) {
$parameters = $callbackReflection->getParameters();
$expectedException = $parameters[0];
if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) {
return false;
}
}
return true;
}
protected function ensureResponse($response, GetResponseForExceptionEvent $event)
{
if ($response instanceof Response) {
$event->setResponse($response);
} else {
$viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response);
$this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent);
if ($viewEvent->hasResponse()) {
$event->setResponse($viewEvent->getResponse());
}
}
}
}

View File

@ -1,83 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\UrlPackage;
use Symfony\Component\Asset\Context\RequestStackContext;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
/**
* Symfony Asset component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class AssetServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['assets.packages'] = function ($app) {
$packages = array();
foreach ($app['assets.named_packages'] as $name => $package) {
$version = $app['assets.strategy_factory'](isset($package['version']) ? $package['version'] : '', isset($package['version_format']) ? $package['version_format'] : null);
$packages[$name] = $app['assets.package_factory'](isset($package['base_path']) ? $package['base_path'] : '', isset($package['base_urls']) ? $package['base_urls'] : array(), $version, $name);
}
return new Packages($app['assets.default_package'], $packages);
};
$app['assets.default_package'] = function ($app) {
$version = $app['assets.strategy_factory']($app['assets.version'], $app['assets.version_format']);
return $app['assets.package_factory']($app['assets.base_path'], $app['assets.base_urls'], $version, 'default');
};
$app['assets.context'] = function ($app) {
return new RequestStackContext($app['request_stack']);
};
$app['assets.base_path'] = '';
$app['assets.base_urls'] = array();
$app['assets.version'] = null;
$app['assets.version_format'] = null;
$app['assets.named_packages'] = array();
// prototypes
$app['assets.strategy_factory'] = $app->protect(function ($version, $format) use ($app) {
if (!$version) {
return new EmptyVersionStrategy();
}
return new StaticVersionStrategy($version, $format);
});
$app['assets.package_factory'] = $app->protect(function ($basePath, $baseUrls, $version, $name) use ($app) {
if ($basePath && $baseUrls) {
throw new \LogicException(sprintf('Asset package "%s" cannot have base URLs and base paths.', $name));
}
if (!$baseUrls) {
return new PathPackage($basePath, $version, $app['assets.context']);
}
return new UrlPackage($baseUrls, $version, $app['assets.context']);
});
}
}

View File

@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage;
/**
* Symfony CSRF Security component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class CsrfServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['csrf.token_manager'] = function ($app) {
return new CsrfTokenManager($app['csrf.token_generator'], $app['csrf.token_storage']);
};
$app['csrf.token_storage'] = function ($app) {
if (isset($app['session'])) {
return new SessionTokenStorage($app['session'], $app['csrf.session_namespace']);
}
return new NativeSessionTokenStorage($app['csrf.session_namespace']);
};
$app['csrf.token_generator'] = function ($app) {
return new UriSafeTokenGenerator();
};
$app['csrf.session_namespace'] = '_csrf';
}
}

View File

@ -1,129 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
/**
* Doctrine DBAL Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class DoctrineServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['db.default_options'] = array(
'driver' => 'pdo_mysql',
'dbname' => null,
'host' => 'localhost',
'user' => 'root',
'password' => null,
);
$app['dbs.options.initializer'] = $app->protect(function () use ($app) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($app['dbs.options'])) {
$app['dbs.options'] = array('default' => isset($app['db.options']) ? $app['db.options'] : array());
}
$tmp = $app['dbs.options'];
foreach ($tmp as $name => &$options) {
$options = array_replace($app['db.default_options'], $options);
if (!isset($app['dbs.default'])) {
$app['dbs.default'] = $name;
}
}
$app['dbs.options'] = $tmp;
});
$app['dbs'] = function ($app) {
$app['dbs.options.initializer']();
$dbs = new Container();
foreach ($app['dbs.options'] as $name => $options) {
if ($app['dbs.default'] === $name) {
// we use shortcuts here in case the default has been overridden
$config = $app['db.config'];
$manager = $app['db.event_manager'];
} else {
$config = $app['dbs.config'][$name];
$manager = $app['dbs.event_manager'][$name];
}
$dbs[$name] = function ($dbs) use ($options, $config, $manager) {
return DriverManager::getConnection($options, $config, $manager);
};
}
return $dbs;
};
$app['dbs.config'] = function ($app) {
$app['dbs.options.initializer']();
$configs = new Container();
$addLogger = isset($app['logger']) && null !== $app['logger'] && class_exists('Symfony\Bridge\Doctrine\Logger\DbalLogger');
foreach ($app['dbs.options'] as $name => $options) {
$configs[$name] = new Configuration();
if ($addLogger) {
$configs[$name]->setSQLLogger(new DbalLogger($app['logger'], isset($app['stopwatch']) ? $app['stopwatch'] : null));
}
}
return $configs;
};
$app['dbs.event_manager'] = function ($app) {
$app['dbs.options.initializer']();
$managers = new Container();
foreach ($app['dbs.options'] as $name => $options) {
$managers[$name] = new EventManager();
}
return $managers;
};
// shortcuts for the "first" DB
$app['db'] = function ($app) {
$dbs = $app['dbs'];
return $dbs[$app['dbs.default']];
};
$app['db.config'] = function ($app) {
$dbs = $app['dbs.config'];
return $dbs[$app['dbs.default']];
};
$app['db.event_manager'] = function ($app) {
$dbs = $app['dbs.event_manager'];
return $dbs[$app['dbs.default']];
};
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ExceptionHandlerServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['exception_handler'] = function ($app) {
return new ExceptionHandler($app['debug']);
};
}
/**
* {@inheritdoc}
*/
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
}
}

View File

@ -1,122 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Form;
use Pimple\Container;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormTypeGuesserChain;
class SilexFormExtension implements FormExtensionInterface
{
private $app;
private $types;
private $typeExtensions;
private $guessers;
private $guesserLoaded = false;
private $guesser;
public function __construct(Container $app, array $types, array $typeExtensions, array $guessers)
{
$this->app = $app;
$this->setTypes($types);
$this->setTypeExtensions($typeExtensions);
$this->setGuessers($guessers);
}
public function getType($name)
{
if (!isset($this->types[$name])) {
throw new InvalidArgumentException(sprintf('The type "%s" is not the name of a registered form type.', $name));
}
if (!is_object($this->types[$name])) {
$this->types[$name] = $this->app[$this->types[$name]];
}
return $this->types[$name];
}
public function hasType($name)
{
return isset($this->types[$name]);
}
public function getTypeExtensions($name)
{
return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : [];
}
public function hasTypeExtensions($name)
{
return isset($this->typeExtensions[$name]);
}
public function getTypeGuesser()
{
if (!$this->guesserLoaded) {
$this->guesserLoaded = true;
if ($this->guessers) {
$guessers = [];
foreach ($this->guessers as $guesser) {
if (!is_object($guesser)) {
$guesser = $this->app[$guesser];
}
$guessers[] = $guesser;
}
$this->guesser = new FormTypeGuesserChain($guessers);
}
}
return $this->guesser;
}
private function setTypes(array $types)
{
$this->types = [];
foreach ($types as $type) {
if (!is_object($type)) {
if (!isset($this->app[$type])) {
throw new InvalidArgumentException(sprintf('Invalid form type. The silex service "%s" does not exist.', $type));
}
$this->types[$type] = $type;
} else {
$this->types[get_class($type)] = $type;
}
}
}
private function setTypeExtensions(array $typeExtensions)
{
$this->typeExtensions = [];
foreach ($typeExtensions as $extension) {
if (!is_object($extension)) {
if (!isset($this->app[$extension])) {
throw new InvalidArgumentException(sprintf('Invalid form type extension. The silex service "%s" does not exist.', $extension));
}
$extension = $this->app[$extension];
}
$this->typeExtensions[$extension->getExtendedType()][] = $extension;
}
}
private function setGuessers(array $guessers)
{
$this->guessers = [];
foreach ($guessers as $guesser) {
if (!is_object($guesser) && !isset($this->app[$guesser])) {
throw new InvalidArgumentException(sprintf('Invalid form type guesser. The silex service "%s" does not exist.', $guesser));
}
$this->guessers[] = $guesser;
}
}
}

View File

@ -1,88 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension as FormValidatorExtension;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\ResolvedFormTypeFactory;
/**
* Symfony Form component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class FormServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
if (!class_exists('Locale')) {
throw new \RuntimeException('You must either install the PHP intl extension or the Symfony Intl Component to use the Form extension.');
}
$app['form.types'] = function ($app) {
return array();
};
$app['form.type.extensions'] = function ($app) {
return array();
};
$app['form.type.guessers'] = function ($app) {
return array();
};
$app['form.extension.csrf'] = function ($app) {
if (isset($app['translator'])) {
return new CsrfExtension($app['csrf.token_manager'], $app['translator']);
}
return new CsrfExtension($app['csrf.token_manager']);
};
$app['form.extension.silex'] = function ($app) {
return new Form\SilexFormExtension($app, $app['form.types'], $app['form.type.extensions'], $app['form.type.guessers']);
};
$app['form.extensions'] = function ($app) {
$extensions = array(
new HttpFoundationExtension(),
);
if (isset($app['csrf.token_manager'])) {
$extensions[] = $app['form.extension.csrf'];
}
if (isset($app['validator'])) {
$extensions[] = new FormValidatorExtension($app['validator']);
}
$extensions[] = $app['form.extension.silex'];
return $extensions;
};
$app['form.factory'] = function ($app) {
return Forms::createFormFactoryBuilder()
->addExtensions($app['form.extensions'])
->setResolvedTypeFactory($app['form.resolved_type_factory'])
->getFormFactory()
;
};
$app['form.resolved_type_factory'] = function ($app) {
return new ResolvedFormTypeFactory();
};
}
}

View File

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
use Symfony\Component\HttpFoundation\Request;
/**
* HTTP Cache extension to allow using the run() shortcut.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpCache extends BaseHttpCache
{
/**
* Handles the Request and delivers the Response.
*
* @param Request $request The Request object
*/
public function run(Request $request = null)
{
if (null === $request) {
$request = Request::createFromGlobals();
}
$response = $this->handle($request);
$response->send();
$this->terminate($request, $response);
}
}

View File

@ -1,61 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Provider\HttpCache\HttpCache;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpKernel\EventListener\SurrogateListener;
/**
* Symfony HttpKernel component Provider for HTTP cache.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpCacheServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['http_cache'] = function ($app) {
$app['http_cache.options'] = array_replace(
array(
'debug' => $app['debug'],
), $app['http_cache.options']
);
return new HttpCache($app, $app['http_cache.store'], $app['http_cache.esi'], $app['http_cache.options']);
};
$app['http_cache.esi'] = function ($app) {
return new Esi();
};
$app['http_cache.store'] = function ($app) {
return new Store($app['http_cache.cache_dir']);
};
$app['http_cache.esi_listener'] = function ($app) {
return new SurrogateListener($app['http_cache.esi']);
};
$app['http_cache.options'] = array();
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['http_cache.esi_listener']);
}
}

View File

@ -1,86 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer;
use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer;
use Symfony\Component\HttpKernel\EventListener\FragmentListener;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\UriSigner;
/**
* HttpKernel Fragment integration for Silex.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpFragmentServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['fragment.handler'] = function ($app) {
return new FragmentHandler($app['request_stack'], $app['fragment.renderers'], $app['debug']);
};
$app['fragment.renderer.inline'] = function ($app) {
$renderer = new InlineFragmentRenderer($app['kernel'], $app['dispatcher']);
$renderer->setFragmentPath($app['fragment.path']);
return $renderer;
};
$app['fragment.renderer.hinclude'] = function ($app) {
$renderer = new HIncludeFragmentRenderer(null, $app['uri_signer'], $app['fragment.renderer.hinclude.global_template'], $app['charset']);
$renderer->setFragmentPath($app['fragment.path']);
return $renderer;
};
$app['fragment.renderer.esi'] = function ($app) {
$renderer = new EsiFragmentRenderer($app['http_cache.esi'], $app['fragment.renderer.inline']);
$renderer->setFragmentPath($app['fragment.path']);
return $renderer;
};
$app['fragment.listener'] = function ($app) {
return new FragmentListener($app['uri_signer'], $app['fragment.path']);
};
$app['uri_signer'] = function ($app) {
return new UriSigner($app['uri_signer.secret']);
};
$app['uri_signer.secret'] = md5(__DIR__);
$app['fragment.path'] = '/_fragment';
$app['fragment.renderer.hinclude.global_template'] = null;
$app['fragment.renderers'] = function ($app) {
$renderers = array($app['fragment.renderer.inline'], $app['fragment.renderer.hinclude']);
if (isset($app['http_cache.esi'])) {
$renderers[] = $app['fragment.renderer.esi'];
}
return $renderers;
};
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['fragment.listener']);
}
}

View File

@ -1,95 +0,0 @@
<?php
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\AppArgumentValueResolver;
use Silex\CallbackResolver;
use Silex\ControllerResolver;
use Silex\EventListener\ConverterListener;
use Silex\EventListener\MiddlewareListener;
use Silex\EventListener\StringToResponseListener;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\VariadicValueResolver;
use Symfony\Component\HttpKernel\Controller\ControllerResolver as SfControllerResolver;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Kernel;
class HttpKernelServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['resolver'] = function ($app) {
if (Kernel::VERSION_ID >= 30100) {
return new SfControllerResolver($app['logger']);
}
return new ControllerResolver($app, $app['logger']);
};
if (Kernel::VERSION_ID >= 30100) {
$app['argument_metadata_factory'] = function ($app) {
return new ArgumentMetadataFactory();
};
$app['argument_value_resolvers'] = function ($app) {
if (Kernel::VERSION_ID < 30200) {
return array(
new AppArgumentValueResolver($app),
new RequestAttributeValueResolver(),
new RequestValueResolver(),
new DefaultValueResolver(),
new VariadicValueResolver(),
);
}
return array_merge(array(new AppArgumentValueResolver($app)), ArgumentResolver::getDefaultArgumentValueResolvers());
};
}
$app['argument_resolver'] = function ($app) {
if (Kernel::VERSION_ID >= 30100) {
return new ArgumentResolver($app['argument_metadata_factory'], $app['argument_value_resolvers']);
}
};
$app['kernel'] = function ($app) {
return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack'], $app['argument_resolver']);
};
$app['request_stack'] = function () {
return new RequestStack();
};
$app['dispatcher'] = function () {
return new EventDispatcher();
};
$app['callback_resolver'] = function ($app) {
return new CallbackResolver($app);
};
}
/**
* {@inheritdoc}
*/
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber(new ResponseListener($app['charset']));
$dispatcher->addSubscriber(new MiddlewareListener($app));
$dispatcher->addSubscriber(new ConverterListener($app['routes'], $app['callback_resolver']));
$dispatcher->addSubscriber(new StringToResponseListener());
}
}

View File

@ -1,19 +0,0 @@
Copyright (c) 2010-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,84 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Locale;
use Pimple\Container;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Initializes the locale based on the current request.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
class LocaleListener implements EventSubscriberInterface
{
private $app;
private $defaultLocale;
private $requestStack;
private $requestContext;
public function __construct(Container $app, $defaultLocale = 'en', RequestStack $requestStack, RequestContext $requestContext = null)
{
$this->app = $app;
$this->defaultLocale = $defaultLocale;
$this->requestStack = $requestStack;
$this->requestContext = $requestContext;
}
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$request->setDefaultLocale($this->defaultLocale);
$this->setLocale($request);
$this->setRouterContext($request);
$this->app['locale'] = $request->getLocale();
}
public function onKernelFinishRequest(FinishRequestEvent $event)
{
if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
$this->setRouterContext($parentRequest);
}
}
private function setLocale(Request $request)
{
if ($locale = $request->attributes->get('_locale')) {
$request->setLocale($locale);
}
}
private function setRouterContext(Request $request)
{
if (null !== $this->requestContext) {
$this->requestContext->setParameter('_locale', $request->getLocale());
}
}
public static function getSubscribedEvents()
{
return array(
// must be registered after the Router to have access to the _locale
KernelEvents::REQUEST => array(array('onKernelRequest', 16)),
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),
);
}
}

View File

@ -1,40 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Locale\LocaleListener;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Locale Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class LocaleServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['locale.listener'] = function ($app) {
return new LocaleListener($app, $app['locale'], $app['request_stack'], isset($app['request_context']) ? $app['request_context'] : null);
};
$app['locale'] = 'en';
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['locale.listener']);
}
}

View File

@ -1,139 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
use Monolog\Handler;
use Monolog\ErrorHandler;
use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Symfony\Bridge\Monolog\Handler\DebugHandler;
use Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy;
use Silex\EventListener\LogListener;
/**
* Monolog Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class MonologServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['logger'] = function () use ($app) {
return $app['monolog'];
};
if ($bridge = class_exists('Symfony\Bridge\Monolog\Logger')) {
$app['monolog.handler.debug'] = function () use ($app) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);
return new DebugHandler($level);
};
if (isset($app['request_stack'])) {
$app['monolog.not_found_activation_strategy'] = function () use ($app) {
return new NotFoundActivationStrategy($app['request_stack'], array('^/'), $app['monolog.level']);
};
}
}
$app['monolog.logger.class'] = $bridge ? 'Symfony\Bridge\Monolog\Logger' : 'Monolog\Logger';
$app['monolog'] = function ($app) {
$log = new $app['monolog.logger.class']($app['monolog.name']);
$handler = new Handler\GroupHandler($app['monolog.handlers']);
if (isset($app['monolog.not_found_activation_strategy'])) {
$handler = new Handler\FingersCrossedHandler($handler, $app['monolog.not_found_activation_strategy']);
}
$log->pushHandler($handler);
if ($app['debug'] && isset($app['monolog.handler.debug'])) {
$log->pushHandler($app['monolog.handler.debug']);
}
return $log;
};
$app['monolog.formatter'] = function () {
return new LineFormatter();
};
$app['monolog.handler'] = $defaultHandler = function () use ($app) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);
$handler = new Handler\StreamHandler($app['monolog.logfile'], $level, $app['monolog.bubble'], $app['monolog.permission']);
$handler->setFormatter($app['monolog.formatter']);
return $handler;
};
$app['monolog.handlers'] = function () use ($app, $defaultHandler) {
$handlers = array();
// enables the default handler if a logfile was set or the monolog.handler service was redefined
if ($app['monolog.logfile'] || $defaultHandler !== $app->raw('monolog.handler')) {
$handlers[] = $app['monolog.handler'];
}
return $handlers;
};
$app['monolog.level'] = function () {
return Logger::DEBUG;
};
$app['monolog.listener'] = function () use ($app) {
return new LogListener($app['logger'], $app['monolog.exception.logger_filter']);
};
$app['monolog.name'] = 'app';
$app['monolog.bubble'] = true;
$app['monolog.permission'] = null;
$app['monolog.exception.logger_filter'] = null;
$app['monolog.logfile'] = null;
$app['monolog.use_error_handler'] = !$app['debug'];
}
public function boot(Application $app)
{
if ($app['monolog.use_error_handler']) {
ErrorHandler::register($app['monolog']);
}
if (isset($app['monolog.listener'])) {
$app['dispatcher']->addSubscriber($app['monolog.listener']);
}
}
public static function translateLevel($name)
{
// level is already translated to logger constant, return as-is
if (is_int($name)) {
return $name;
}
$levels = Logger::getLevels();
$upper = strtoupper($name);
if (!isset($levels[$upper])) {
throw new \InvalidArgumentException("Provided logging level '$name' does not exist. Must be a valid monolog logging level.");
}
return $levels[$upper];
}
}

View File

@ -1,107 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
use Symfony\Component\Security\Http\Firewall\RememberMeListener;
use Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices;
use Symfony\Component\Security\Http\RememberMe\ResponseListener;
/**
* Remember-me authentication for the SecurityServiceProvider.
*
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
class RememberMeServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['security.remember_me.response_listener'] = function ($app) {
if (!isset($app['security.token_storage'])) {
throw new \LogicException('You must register the SecurityServiceProvider to use the RememberMeServiceProvider');
}
return new ResponseListener();
};
$app['security.authentication_listener.factory.remember_me'] = $app->protect(function ($name, $options) use ($app) {
if (empty($options['key'])) {
$options['key'] = $name;
}
if (!isset($app['security.remember_me.service.'.$name])) {
$app['security.remember_me.service.'.$name] = $app['security.remember_me.service._proto']($name, $options);
}
if (!isset($app['security.authentication_listener.'.$name.'.remember_me'])) {
$app['security.authentication_listener.'.$name.'.remember_me'] = $app['security.authentication_listener.remember_me._proto']($name, $options);
}
if (!isset($app['security.authentication_provider.'.$name.'.remember_me'])) {
$app['security.authentication_provider.'.$name.'.remember_me'] = $app['security.authentication_provider.remember_me._proto']($name, $options);
}
return array(
'security.authentication_provider.'.$name.'.remember_me',
'security.authentication_listener.'.$name.'.remember_me',
null, // entry point
'remember_me',
);
});
$app['security.remember_me.service._proto'] = $app->protect(function ($providerKey, $options) use ($app) {
return function () use ($providerKey, $options, $app) {
$options = array_replace(array(
'name' => 'REMEMBERME',
'lifetime' => 31536000,
'path' => '/',
'domain' => null,
'secure' => false,
'httponly' => true,
'always_remember_me' => false,
'remember_me_parameter' => '_remember_me',
), $options);
return new TokenBasedRememberMeServices(array($app['security.user_provider.'.$providerKey]), $options['key'], $providerKey, $options, $app['logger']);
};
});
$app['security.authentication_listener.remember_me._proto'] = $app->protect(function ($providerKey) use ($app) {
return function () use ($app, $providerKey) {
$listener = new RememberMeListener(
$app['security.token_storage'],
$app['security.remember_me.service.'.$providerKey],
$app['security.authentication_manager'],
$app['logger'],
$app['dispatcher']
);
return $listener;
};
});
$app['security.authentication_provider.remember_me._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($app, $name, $options) {
return new RememberMeAuthenticationProvider($app['security.user_checker'], $options['key'], $name);
};
});
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['security.remember_me.response_listener']);
}
}

View File

@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Routing;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
/**
* Implements a lazy UrlMatcher.
*
* @author Igor Wiedler <igor@wiedler.ch>
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
class LazyRequestMatcher implements RequestMatcherInterface
{
private $factory;
public function __construct(\Closure $factory)
{
$this->factory = $factory;
}
/**
* Returns the corresponding RequestMatcherInterface instance.
*
* @return UrlMatcherInterface
*/
public function getRequestMatcher()
{
$matcher = call_user_func($this->factory);
if (!$matcher instanceof RequestMatcherInterface) {
throw new \LogicException("Factory supplied to LazyRequestMatcher must return implementation of Symfony\Component\Routing\RequestMatcherInterface.");
}
return $matcher;
}
/**
* {@inheritdoc}
*/
public function matchRequest(Request $request)
{
return $this->getRequestMatcher()->matchRequest($request);
}
}

View File

@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Routing;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseRedirectableUrlMatcher;
/**
* Implements the RedirectableUrlMatcherInterface for Silex.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RedirectableUrlMatcher extends BaseRedirectableUrlMatcher
{
/**
* {@inheritdoc}
*/
public function redirect($path, $route, $scheme = null)
{
$url = $this->context->getBaseUrl().$path;
$query = $this->context->getQueryString() ?: '';
if ($query !== '') {
$url .= '?'.$query;
}
if ($this->context->getHost()) {
if ($scheme) {
$port = '';
if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
$port = ':'.$this->context->getHttpPort();
} elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
$port = ':'.$this->context->getHttpsPort();
}
$url = $scheme.'://'.$this->context->getHost().$port.$url;
}
}
return array(
'_controller' => function ($url) { return new RedirectResponse($url, 301); },
'_route' => null,
'url' => $url,
);
}
}

View File

@ -1,87 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\ControllerCollection;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Routing\RedirectableUrlMatcher;
use Silex\Provider\Routing\LazyRequestMatcher;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Symfony Routing component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RoutingServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['route_class'] = 'Silex\\Route';
$app['route_factory'] = $app->factory(function ($app) {
return new $app['route_class']();
});
$app['routes_factory'] = $app->factory(function () {
return new RouteCollection();
});
$app['routes'] = function ($app) {
return $app['routes_factory'];
};
$app['url_generator'] = function ($app) {
return new UrlGenerator($app['routes'], $app['request_context']);
};
$app['request_matcher'] = function ($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
};
$app['request_context'] = function ($app) {
$context = new RequestContext();
$context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
$context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
return $context;
};
$app['controllers'] = function ($app) {
return $app['controllers_factory'];
};
$controllers_factory = function () use ($app, &$controllers_factory) {
return new ControllerCollection($app['route_factory'], $app['routes_factory'], $controllers_factory);
};
$app['controllers_factory'] = $app->factory($controllers_factory);
$app['routing.listener'] = function ($app) {
$urlMatcher = new LazyRequestMatcher(function () use ($app) {
return $app['request_matcher'];
});
return new RouterListener($urlMatcher, $app['request_stack'], $app['request_context'], $app['logger']);
};
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['routing.listener']);
}
}

View File

@ -1,684 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestMatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserChecker;
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder;
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
use Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider;
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Authorization\Voter\RoleHierarchyVoter;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
use Symfony\Component\Security\Http\Firewall;
use Symfony\Component\Security\Http\FirewallMap;
use Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener;
use Symfony\Component\Security\Http\Firewall\AccessListener;
use Symfony\Component\Security\Http\Firewall\BasicAuthenticationListener;
use Symfony\Component\Security\Http\Firewall\LogoutListener;
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;
use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener;
use Symfony\Component\Security\Http\Firewall\ContextListener;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ChannelListener;
use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
use Symfony\Component\Security\Http\EntryPoint\BasicAuthenticationEntryPoint;
use Symfony\Component\Security\Http\EntryPoint\RetryAuthenticationEntryPoint;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
use Symfony\Component\Security\Http\Logout\SessionLogoutHandler;
use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler;
use Symfony\Component\Security\Http\AccessMap;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Guard\Firewall\GuardAuthenticationListener;
use Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider;
/**
* Symfony Security component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SecurityServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface, ControllerProviderInterface, BootableProviderInterface
{
protected $fakeRoutes;
public function register(Container $app)
{
// used to register routes for login_check and logout
$this->fakeRoutes = array();
$that = $this;
$app['security.role_hierarchy'] = array();
$app['security.access_rules'] = array();
$app['security.hide_user_not_found'] = true;
$app['security.encoder.bcrypt.cost'] = 13;
$app['security.authorization_checker'] = function ($app) {
return new AuthorizationChecker($app['security.token_storage'], $app['security.authentication_manager'], $app['security.access_manager']);
};
$app['security.token_storage'] = function ($app) {
return new TokenStorage();
};
$app['user'] = $app->factory(function ($app) {
if (null === $token = $app['security.token_storage']->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
return;
}
return $user;
});
$app['security.authentication_manager'] = function ($app) {
$manager = new AuthenticationProviderManager($app['security.authentication_providers']);
$manager->setEventDispatcher($app['dispatcher']);
return $manager;
};
// by default, all users use the digest encoder
$app['security.encoder_factory'] = function ($app) {
return new EncoderFactory(array(
'Symfony\Component\Security\Core\User\UserInterface' => $app['security.default_encoder'],
));
};
// by default, all users use the BCrypt encoder
$app['security.default_encoder'] = function ($app) {
return $app['security.encoder.bcrypt'];
};
$app['security.encoder.digest'] = function ($app) {
return new MessageDigestPasswordEncoder();
};
$app['security.encoder.bcrypt'] = function ($app) {
return new BCryptPasswordEncoder($app['security.encoder.bcrypt.cost']);
};
$app['security.encoder.pbkdf2'] = function ($app) {
return new Pbkdf2PasswordEncoder();
};
$app['security.user_checker'] = function ($app) {
return new UserChecker();
};
$app['security.access_manager'] = function ($app) {
return new AccessDecisionManager($app['security.voters']);
};
$app['security.voters'] = function ($app) {
return array(
new RoleHierarchyVoter(new RoleHierarchy($app['security.role_hierarchy'])),
new AuthenticatedVoter($app['security.trust_resolver']),
);
};
$app['security.firewall'] = function ($app) {
return new Firewall($app['security.firewall_map'], $app['dispatcher']);
};
$app['security.channel_listener'] = function ($app) {
return new ChannelListener(
$app['security.access_map'],
new RetryAuthenticationEntryPoint(
isset($app['request.http_port']) ? $app['request.http_port'] : 80,
isset($app['request.https_port']) ? $app['request.https_port'] : 443
),
$app['logger']
);
};
// generate the build-in authentication factories
foreach (array('logout', 'pre_auth', 'guard', 'form', 'http', 'remember_me', 'anonymous') as $type) {
$entryPoint = null;
if ('http' === $type) {
$entryPoint = 'http';
} elseif ('form' === $type) {
$entryPoint = 'form';
} elseif ('guard' === $type) {
$entryPoint = 'guard';
}
$app['security.authentication_listener.factory.'.$type] = $app->protect(function ($name, $options) use ($type, $app, $entryPoint) {
if ($entryPoint && !isset($app['security.entry_point.'.$name.'.'.$entryPoint])) {
$app['security.entry_point.'.$name.'.'.$entryPoint] = $app['security.entry_point.'.$entryPoint.'._proto']($name, $options);
}
if (!isset($app['security.authentication_listener.'.$name.'.'.$type])) {
$app['security.authentication_listener.'.$name.'.'.$type] = $app['security.authentication_listener.'.$type.'._proto']($name, $options);
}
$provider = 'dao';
if ('anonymous' === $type) {
$provider = 'anonymous';
} elseif ('guard' === $type) {
$provider = 'guard';
}
if (!isset($app['security.authentication_provider.'.$name.'.'.$provider])) {
$app['security.authentication_provider.'.$name.'.'.$provider] = $app['security.authentication_provider.'.$provider.'._proto']($name, $options);
}
return array(
'security.authentication_provider.'.$name.'.'.$provider,
'security.authentication_listener.'.$name.'.'.$type,
$entryPoint ? 'security.entry_point.'.$name.'.'.$entryPoint : null,
$type,
);
});
}
$app['security.firewall_map'] = function ($app) {
$positions = array('logout', 'pre_auth', 'guard', 'form', 'http', 'remember_me', 'anonymous');
$providers = array();
$configs = array();
foreach ($app['security.firewalls'] as $name => $firewall) {
$entryPoint = null;
$pattern = isset($firewall['pattern']) ? $firewall['pattern'] : null;
$users = isset($firewall['users']) ? $firewall['users'] : array();
$security = isset($firewall['security']) ? (bool) $firewall['security'] : true;
$stateless = isset($firewall['stateless']) ? (bool) $firewall['stateless'] : false;
$context = isset($firewall['context']) ? $firewall['context'] : $name;
unset($firewall['pattern'], $firewall['users'], $firewall['security'], $firewall['stateless'], $firewall['context']);
$protected = false === $security ? false : count($firewall);
$listeners = array('security.channel_listener');
if ($protected) {
if (!isset($app['security.context_listener.'.$name])) {
if (!isset($app['security.user_provider.'.$name])) {
$app['security.user_provider.'.$name] = is_array($users) ? $app['security.user_provider.inmemory._proto']($users) : $users;
}
$app['security.context_listener.'.$name] = $app['security.context_listener._proto']($name, array($app['security.user_provider.'.$name]));
}
if (false === $stateless) {
$listeners[] = 'security.context_listener.'.$context;
}
$factories = array();
foreach ($positions as $position) {
$factories[$position] = array();
}
foreach ($firewall as $type => $options) {
if ('switch_user' === $type) {
continue;
}
// normalize options
if (!is_array($options)) {
if (!$options) {
continue;
}
$options = array();
}
if (!isset($app['security.authentication_listener.factory.'.$type])) {
throw new \LogicException(sprintf('The "%s" authentication entry is not registered.', $type));
}
$options['stateless'] = $stateless;
list($providerId, $listenerId, $entryPointId, $position) = $app['security.authentication_listener.factory.'.$type]($name, $options);
if (null !== $entryPointId) {
$entryPoint = $entryPointId;
}
$factories[$position][] = $listenerId;
$providers[] = $providerId;
}
foreach ($positions as $position) {
foreach ($factories[$position] as $listener) {
$listeners[] = $listener;
}
}
$listeners[] = 'security.access_listener';
if (isset($firewall['switch_user'])) {
$app['security.switch_user.'.$name] = $app['security.authentication_listener.switch_user._proto']($name, $firewall['switch_user']);
$listeners[] = 'security.switch_user.'.$name;
}
if (!isset($app['security.exception_listener.'.$name])) {
if (null == $entryPoint) {
$app[$entryPoint = 'security.entry_point.'.$name.'.form'] = $app['security.entry_point.form._proto']($name, array());
}
$accessDeniedHandler = null;
if (isset($app['security.access_denied_handler.'.$name])) {
$accessDeniedHandler = $app['security.access_denied_handler.'.$name];
}
$app['security.exception_listener.'.$name] = $app['security.exception_listener._proto']($entryPoint, $name, $accessDeniedHandler);
}
}
$configs[$name] = array($pattern, $listeners, $protected);
}
$app['security.authentication_providers'] = array_map(function ($provider) use ($app) {
return $app[$provider];
}, array_unique($providers));
$map = new FirewallMap();
foreach ($configs as $name => $config) {
$map->add(
is_string($config[0]) ? new RequestMatcher($config[0]) : $config[0],
array_map(function ($listenerId) use ($app, $name) {
$listener = $app[$listenerId];
if (isset($app['security.remember_me.service.'.$name])) {
if ($listener instanceof AbstractAuthenticationListener || $listener instanceof GuardAuthenticationListener) {
$listener->setRememberMeServices($app['security.remember_me.service.'.$name]);
}
if ($listener instanceof LogoutListener) {
$listener->addHandler($app['security.remember_me.service.'.$name]);
}
}
return $listener;
}, $config[1]),
$config[2] ? $app['security.exception_listener.'.$name] : null
);
}
return $map;
};
$app['security.access_listener'] = function ($app) {
return new AccessListener(
$app['security.token_storage'],
$app['security.access_manager'],
$app['security.access_map'],
$app['security.authentication_manager'],
$app['logger']
);
};
$app['security.access_map'] = function ($app) {
$map = new AccessMap();
foreach ($app['security.access_rules'] as $rule) {
if (is_string($rule[0])) {
$rule[0] = new RequestMatcher($rule[0]);
} elseif (is_array($rule[0])) {
$rule[0] += [
'path' => null,
'host' => null,
'methods' => null,
'ips' => null,
'attributes' => array(),
'schemes' => null,
];
$rule[0] = new RequestMatcher($rule[0]['path'], $rule[0]['host'], $rule[0]['methods'], $rule[0]['ips'], $rule[0]['attributes'], $rule[0]['schemes']);
}
$map->add($rule[0], (array) $rule[1], isset($rule[2]) ? $rule[2] : null);
}
return $map;
};
$app['security.trust_resolver'] = function ($app) {
return new AuthenticationTrustResolver('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken');
};
$app['security.session_strategy'] = function ($app) {
return new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
};
$app['security.http_utils'] = function ($app) {
return new HttpUtils($app['url_generator'], $app['request_matcher']);
};
$app['security.last_error'] = $app->protect(function (Request $request) {
if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
return $request->attributes->get(Security::AUTHENTICATION_ERROR)->getMessage();
}
$session = $request->getSession();
if ($session && $session->has(Security::AUTHENTICATION_ERROR)) {
$message = $session->get(Security::AUTHENTICATION_ERROR)->getMessage();
$session->remove(Security::AUTHENTICATION_ERROR);
return $message;
}
});
// prototypes (used by the Firewall Map)
$app['security.context_listener._proto'] = $app->protect(function ($providerKey, $userProviders) use ($app) {
return function () use ($app, $userProviders, $providerKey) {
return new ContextListener(
$app['security.token_storage'],
$userProviders,
$providerKey,
$app['logger'],
$app['dispatcher']
);
};
});
$app['security.user_provider.inmemory._proto'] = $app->protect(function ($params) use ($app) {
return function () use ($app, $params) {
$users = array();
foreach ($params as $name => $user) {
$users[$name] = array('roles' => (array) $user[0], 'password' => $user[1]);
}
return new InMemoryUserProvider($users);
};
});
$app['security.exception_listener._proto'] = $app->protect(function ($entryPoint, $name, $accessDeniedHandler = null) use ($app) {
return function () use ($app, $entryPoint, $name, $accessDeniedHandler) {
return new ExceptionListener(
$app['security.token_storage'],
$app['security.trust_resolver'],
$app['security.http_utils'],
$name,
$app[$entryPoint],
null, // errorPage
$accessDeniedHandler,
$app['logger']
);
};
});
$app['security.authentication.success_handler._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($name, $options, $app) {
$handler = new DefaultAuthenticationSuccessHandler(
$app['security.http_utils'],
$options
);
$handler->setProviderKey($name);
return $handler;
};
});
$app['security.authentication.failure_handler._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($name, $options, $app) {
return new DefaultAuthenticationFailureHandler(
$app,
$app['security.http_utils'],
$options,
$app['logger']
);
};
});
$app['security.authentication_listener.guard._proto'] = $app->protect(function ($providerKey, $options) use ($app, $that) {
return function () use ($app, $providerKey, $options, $that) {
if (!isset($app['security.authentication.guard_handler'])) {
$app['security.authentication.guard_handler'] = new GuardAuthenticatorHandler($app['security.token_storage'], $app['dispatcher']);
}
$authenticators = array();
foreach ($options['authenticators'] as $authenticatorId) {
$authenticators[] = $app[$authenticatorId];
}
return new GuardAuthenticationListener(
$app['security.authentication.guard_handler'],
$app['security.authentication_manager'],
$providerKey,
$authenticators,
$app['logger']
);
};
});
$app['security.authentication_listener.form._proto'] = $app->protect(function ($name, $options) use ($app, $that) {
return function () use ($app, $name, $options, $that) {
$that->addFakeRoute(
'match',
$tmp = isset($options['check_path']) ? $options['check_path'] : '/login_check',
str_replace('/', '_', ltrim($tmp, '/'))
);
$class = isset($options['listener_class']) ? $options['listener_class'] : 'Symfony\\Component\\Security\\Http\\Firewall\\UsernamePasswordFormAuthenticationListener';
if (!isset($app['security.authentication.success_handler.'.$name])) {
$app['security.authentication.success_handler.'.$name] = $app['security.authentication.success_handler._proto']($name, $options);
}
if (!isset($app['security.authentication.failure_handler.'.$name])) {
$app['security.authentication.failure_handler.'.$name] = $app['security.authentication.failure_handler._proto']($name, $options);
}
return new $class(
$app['security.token_storage'],
$app['security.authentication_manager'],
isset($app['security.session_strategy.'.$name]) ? $app['security.session_strategy.'.$name] : $app['security.session_strategy'],
$app['security.http_utils'],
$name,
$app['security.authentication.success_handler.'.$name],
$app['security.authentication.failure_handler.'.$name],
$options,
$app['logger'],
$app['dispatcher'],
isset($options['with_csrf']) && $options['with_csrf'] && isset($app['csrf.token_manager']) ? $app['csrf.token_manager'] : null
);
};
});
$app['security.authentication_listener.http._proto'] = $app->protect(function ($providerKey, $options) use ($app) {
return function () use ($app, $providerKey, $options) {
return new BasicAuthenticationListener(
$app['security.token_storage'],
$app['security.authentication_manager'],
$providerKey,
$app['security.entry_point.'.$providerKey.'.http'],
$app['logger']
);
};
});
$app['security.authentication_listener.anonymous._proto'] = $app->protect(function ($providerKey, $options) use ($app) {
return function () use ($app, $providerKey, $options) {
return new AnonymousAuthenticationListener(
$app['security.token_storage'],
$providerKey,
$app['logger']
);
};
});
$app['security.authentication.logout_handler._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($name, $options, $app) {
return new DefaultLogoutSuccessHandler(
$app['security.http_utils'],
isset($options['target_url']) ? $options['target_url'] : '/'
);
};
});
$app['security.authentication_listener.logout._proto'] = $app->protect(function ($name, $options) use ($app, $that) {
return function () use ($app, $name, $options, $that) {
$that->addFakeRoute(
'get',
$tmp = isset($options['logout_path']) ? $options['logout_path'] : '/logout',
str_replace('/', '_', ltrim($tmp, '/'))
);
if (!isset($app['security.authentication.logout_handler.'.$name])) {
$app['security.authentication.logout_handler.'.$name] = $app['security.authentication.logout_handler._proto']($name, $options);
}
$listener = new LogoutListener(
$app['security.token_storage'],
$app['security.http_utils'],
$app['security.authentication.logout_handler.'.$name],
$options,
isset($options['with_csrf']) && $options['with_csrf'] && isset($app['csrf.token_manager']) ? $app['csrf.token_manager'] : null
);
$invalidateSession = isset($options['invalidate_session']) ? $options['invalidate_session'] : true;
if (true === $invalidateSession && false === $options['stateless']) {
$listener->addHandler(new SessionLogoutHandler());
}
return $listener;
};
});
$app['security.authentication_listener.switch_user._proto'] = $app->protect(function ($name, $options) use ($app, $that) {
return function () use ($app, $name, $options, $that) {
return new SwitchUserListener(
$app['security.token_storage'],
$app['security.user_provider.'.$name],
$app['security.user_checker'],
$name,
$app['security.access_manager'],
$app['logger'],
isset($options['parameter']) ? $options['parameter'] : '_switch_user',
isset($options['role']) ? $options['role'] : 'ROLE_ALLOWED_TO_SWITCH',
$app['dispatcher']
);
};
});
$app['security.entry_point.form._proto'] = $app->protect(function ($name, array $options) use ($app) {
return function () use ($app, $options) {
$loginPath = isset($options['login_path']) ? $options['login_path'] : '/login';
$useForward = isset($options['use_forward']) ? $options['use_forward'] : false;
return new FormAuthenticationEntryPoint($app, $app['security.http_utils'], $loginPath, $useForward);
};
});
$app['security.entry_point.http._proto'] = $app->protect(function ($name, array $options) use ($app) {
return function () use ($app, $name, $options) {
return new BasicAuthenticationEntryPoint(isset($options['real_name']) ? $options['real_name'] : 'Secured');
};
});
$app['security.entry_point.guard._proto'] = $app->protect(function ($name, array $options) use ($app) {
if (isset($options['entry_point'])) {
// if it's configured explicitly, use it!
return $app[$options['entry_point']];
}
$authenticatorIds = $options['authenticators'];
if (count($authenticatorIds) == 1) {
// if there is only one authenticator, use that as the entry point
return $app[reset($authenticatorIds)];
}
// we have multiple entry points - we must ask them to configure one
throw new \LogicException(sprintf(
'Because you have multiple guard configurators, you need to set the "guard.entry_point" key to one of you configurators (%s)',
implode(', ', $authenticatorIds)
));
});
$app['security.authentication_provider.dao._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($app, $name) {
return new DaoAuthenticationProvider(
$app['security.user_provider.'.$name],
$app['security.user_checker'],
$name,
$app['security.encoder_factory'],
$app['security.hide_user_not_found']
);
};
});
$app['security.authentication_provider.guard._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($app, $name, $options) {
$authenticators = array();
foreach ($options['authenticators'] as $authenticatorId) {
$authenticators[] = $app[$authenticatorId];
}
return new GuardAuthenticationProvider(
$authenticators,
$app['security.user_provider.'.$name],
$name,
$app['security.user_checker']
);
};
});
$app['security.authentication_provider.anonymous._proto'] = $app->protect(function ($name, $options) use ($app) {
return function () use ($app, $name) {
return new AnonymousAuthenticationProvider($name);
};
});
if (isset($app['validator'])) {
$app['security.validator.user_password_validator'] = function ($app) {
return new UserPasswordValidator($app['security.token_storage'], $app['security.encoder_factory']);
};
$app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], array('security.validator.user_password' => 'security.validator.user_password_validator'));
}
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['security.firewall']);
}
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
foreach ($this->fakeRoutes as $route) {
list($method, $pattern, $name) = $route;
$controllers->$method($pattern)->run(null)->bind($name);
}
return $controllers;
}
public function boot(Application $app)
{
$app->mount('/', $this->connect($app));
}
public function addFakeRoute($method, $pattern, $name)
{
$this->fakeRoutes[] = array($method, $pattern, $name);
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
/**
* Symfony Serializer component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Marijn Huizendveld <marijn@pink-tie.com>
*/
class SerializerServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*
* This method registers a serializer service. {@link http://api.symfony.com/master/Symfony/Component/Serializer/Serializer.html
* The service is provided by the Symfony Serializer component}.
*/
public function register(Container $app)
{
$app['serializer'] = function ($app) {
return new Serializer($app['serializer.normalizers'], $app['serializer.encoders']);
};
$app['serializer.encoders'] = function () {
return array(new JsonEncoder(), new XmlEncoder());
};
$app['serializer.normalizers'] = function () {
return array(new CustomNormalizer(), new GetSetMethodNormalizer());
};
}
}

View File

@ -1,26 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\ServiceControllerResolver;
class ServiceControllerServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app->extend('resolver', function ($resolver, $app) {
return new ServiceControllerResolver($resolver, $app['callback_resolver']);
});
}
}

View File

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Session;
use Pimple\Container;
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
/**
* Sets the session in the request.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SessionListener extends BaseSessionListener
{
private $app;
public function __construct(Container $app)
{
$this->app = $app;
}
protected function getSession()
{
if (!isset($this->app['session'])) {
return;
}
return $this->app['session'];
}
}

View File

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Session;
use Pimple\Container;
use Symfony\Component\HttpKernel\EventListener\TestSessionListener as BaseTestSessionListener;
/**
* Simulates sessions for testing purpose.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TestSessionListener extends BaseTestSessionListener
{
private $app;
public function __construct(Container $app)
{
$this->app = $app;
}
protected function getSession()
{
if (!isset($this->app['session'])) {
return;
}
return $this->app['session'];
}
}

View File

@ -1,86 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Session\SessionListener;
use Silex\Provider\Session\TestSessionListener;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* Symfony HttpFoundation component Provider for sessions.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SessionServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['session.test'] = false;
$app['session'] = function ($app) {
return new Session($app['session.storage'], $app['session.attribute_bag'], $app['session.flash_bag']);
};
$app['session.storage'] = function ($app) {
if ($app['session.test']) {
return $app['session.storage.test'];
}
return $app['session.storage.native'];
};
$app['session.storage.handler'] = function ($app) {
return new NativeFileSessionHandler($app['session.storage.save_path']);
};
$app['session.storage.native'] = function ($app) {
return new NativeSessionStorage(
$app['session.storage.options'],
$app['session.storage.handler']
);
};
$app['session.listener'] = function ($app) {
return new SessionListener($app);
};
$app['session.storage.test'] = function () {
return new MockFileSessionStorage();
};
$app['session.listener.test'] = function ($app) {
return new TestSessionListener($app);
};
$app['session.storage.options'] = array();
$app['session.default_locale'] = 'en';
$app['session.storage.save_path'] = null;
$app['session.attribute_bag'] = null;
$app['session.flash_bag'] = null;
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['session.listener']);
if ($app['session.test']) {
$app['dispatcher']->addSubscriber($app['session.listener.test']);
}
}
}

View File

@ -1,126 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
/**
* Swiftmailer Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['swiftmailer.options'] = array();
$app['swiftmailer.use_spool'] = true;
$app['mailer.initialized'] = false;
$app['mailer'] = function ($app) {
$app['mailer.initialized'] = true;
$transport = $app['swiftmailer.use_spool'] ? $app['swiftmailer.spooltransport'] : $app['swiftmailer.transport'];
return new \Swift_Mailer($transport);
};
$app['swiftmailer.spooltransport'] = function ($app) {
return new \Swift_Transport_SpoolTransport($app['swiftmailer.transport.eventdispatcher'], $app['swiftmailer.spool']);
};
$app['swiftmailer.spool'] = function ($app) {
return new \Swift_MemorySpool();
};
$app['swiftmailer.transport'] = function ($app) {
$transport = new \Swift_Transport_EsmtpTransport(
$app['swiftmailer.transport.buffer'],
array($app['swiftmailer.transport.authhandler']),
$app['swiftmailer.transport.eventdispatcher']
);
$options = $app['swiftmailer.options'] = array_replace(array(
'host' => 'localhost',
'port' => 25,
'username' => '',
'password' => '',
'encryption' => null,
'auth_mode' => null,
), $app['swiftmailer.options']);
$transport->setHost($options['host']);
$transport->setPort($options['port']);
$transport->setEncryption($options['encryption']);
$transport->setUsername($options['username']);
$transport->setPassword($options['password']);
$transport->setAuthMode($options['auth_mode']);
if (null !== $app['swiftmailer.sender_address']) {
$transport->registerPlugin(new \Swift_Plugins_ImpersonatePlugin($app['swiftmailer.sender_address']));
}
if (!empty($app['swiftmailer.delivery_addresses'])) {
$transport->registerPlugin(new \Swift_Plugins_RedirectingPlugin(
$app['swiftmailer.delivery_addresses'],
$app['swiftmailer.delivery_whitelist']
));
}
return $transport;
};
$app['swiftmailer.transport.buffer'] = function () {
return new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory());
};
$app['swiftmailer.transport.authhandler'] = function () {
return new \Swift_Transport_Esmtp_AuthHandler(array(
new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(),
new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(),
new \Swift_Transport_Esmtp_Auth_PlainAuthenticator(),
));
};
$app['swiftmailer.transport.eventdispatcher'] = function () {
return new \Swift_Events_SimpleEventDispatcher();
};
$app['swiftmailer.sender_address'] = null;
$app['swiftmailer.delivery_addresses'] = [];
$app['swiftmailer.delivery_whitelist'] = [];
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
// Event has no typehint as it can be either a PostResponseEvent or a ConsoleTerminateEvent
$onTerminate = function ($event) use ($app) {
// To speed things up (by avoiding Swift Mailer initialization), flush
// messages only if our mailer has been created (potentially used)
if ($app['mailer.initialized'] && $app['swiftmailer.use_spool'] && $app['swiftmailer.spooltransport'] instanceof \Swift_Transport_SpoolTransport) {
$app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
}
};
$dispatcher->addListener(KernelEvents::TERMINATE, $onTerminate);
if (class_exists('Symfony\Component\Console\ConsoleEvents')) {
$dispatcher->addListener(ConsoleEvents::TERMINATE, $onTerminate);
}
}
}

View File

@ -1,98 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Loader\XliffFileLoader;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\EventListener\TranslatorListener;
use Silex\Api\EventListenerProviderInterface;
/**
* Symfony Translation component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TranslationServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(Container $app)
{
$app['translator'] = function ($app) {
if (!isset($app['locale'])) {
throw new \LogicException('You must define \'locale\' parameter or register the LocaleServiceProvider to use the TranslationServiceProvider');
}
$translator = new Translator($app['locale'], $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
$translator->setFallbackLocales($app['locale_fallbacks']);
$translator->addLoader('array', new ArrayLoader());
$translator->addLoader('xliff', new XliffFileLoader());
if (isset($app['validator'])) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$translator->addResource('xliff', $file, $app['locale'], 'validators');
}
}
if (isset($app['form.factory'])) {
$r = new \ReflectionClass('Symfony\Component\Form\Form');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$translator->addResource('xliff', $file, $app['locale'], 'validators');
}
}
// Register default resources
foreach ($app['translator.resources'] as $resource) {
$translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
}
foreach ($app['translator.domains'] as $domain => $data) {
foreach ($data as $locale => $messages) {
$translator->addResource('array', $messages, $locale, $domain);
}
}
return $translator;
};
if (isset($app['request_stack'])) {
$app['translator.listener'] = function ($app) {
return new TranslatorListener($app['translator'], $app['request_stack']);
};
}
$app['translator.message_selector'] = function () {
return new MessageSelector();
};
$app['translator.resources'] = $app->protect(function ($app) {
return array();
});
$app['translator.domains'] = array();
$app['locale_fallbacks'] = array('en');
$app['translator.cache_dir'] = null;
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
if (isset($app['translator.listener'])) {
$dispatcher->addSubscriber($app['translator.listener']);
}
}
}

View File

@ -1,145 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Bridge\Twig\AppVariable;
use Symfony\Bridge\Twig\Extension\AssetExtension;
use Symfony\Bridge\Twig\Extension\DumpExtension;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\SecurityExtension;
use Symfony\Bridge\Twig\Extension\HttpFoundationExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Bridge\Twig\Form\TwigRenderer;
/**
* Twig integration for Silex.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TwigServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['twig.options'] = array();
$app['twig.form.templates'] = array('form_div_layout.html.twig');
$app['twig.path'] = array();
$app['twig.templates'] = array();
$app['twig.app_variable'] = function ($app) {
$var = new AppVariable();
if (isset($app['security.token_storage'])) {
$var->setTokenStorage($app['security.token_storage']);
}
if (isset($app['request_stack'])) {
$var->setRequestStack($app['request_stack']);
}
$var->setDebug($app['debug']);
return $var;
};
$app['twig'] = function ($app) {
$app['twig.options'] = array_replace(
array(
'charset' => $app['charset'],
'debug' => $app['debug'],
'strict_variables' => $app['debug'],
), $app['twig.options']
);
$twig = $app['twig.environment_factory']($app);
// registered for BC, but should not be used anymore
// deprecated and should probably be removed in Silex 3.0
$twig->addGlobal('app', $app);
if ($app['debug']) {
$twig->addExtension(new \Twig_Extension_Debug());
}
if (class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')) {
$twig->addGlobal('global', $app['twig.app_variable']);
if (isset($app['request_stack'])) {
$twig->addExtension(new HttpFoundationExtension($app['request_stack']));
$twig->addExtension(new RoutingExtension($app['url_generator']));
}
if (isset($app['translator'])) {
$twig->addExtension(new TranslationExtension($app['translator']));
}
if (isset($app['security.authorization_checker'])) {
$twig->addExtension(new SecurityExtension($app['security.authorization_checker']));
}
if (isset($app['fragment.handler'])) {
$app['fragment.renderer.hinclude']->setTemplating($twig);
$twig->addExtension(new HttpKernelExtension($app['fragment.handler']));
}
if (isset($app['assets.packages'])) {
$twig->addExtension(new AssetExtension($app['assets.packages']));
}
if (isset($app['form.factory'])) {
$app['twig.form.engine'] = function ($app) {
return new TwigRendererEngine($app['twig.form.templates']);
};
$app['twig.form.renderer'] = function ($app) {
$csrfTokenManager = isset($app['csrf.token_manager']) ? $app['csrf.token_manager'] : null;
return new TwigRenderer($app['twig.form.engine'], $csrfTokenManager);
};
$twig->addExtension(new FormExtension($app['twig.form.renderer']));
// add loader for Symfony built-in form templates
$reflected = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
$path = dirname($reflected->getFileName()).'/../Resources/views/Form';
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($path));
}
if (isset($app['var_dumper.cloner'])) {
$twig->addExtension(new DumpExtension($app['var_dumper.cloner']));
}
}
return $twig;
};
$app['twig.loader.filesystem'] = function ($app) {
return new \Twig_Loader_Filesystem($app['twig.path']);
};
$app['twig.loader.array'] = function ($app) {
return new \Twig_Loader_Array($app['twig.templates']);
};
$app['twig.loader'] = function ($app) {
return new \Twig_Loader_Chain(array(
$app['twig.loader.array'],
$app['twig.loader.filesystem'],
));
};
$app['twig.environment_factory'] = $app->protect(function ($app) {
return new \Twig_Environment($app['twig.loader'], $app['twig.options']);
});
}
}

View File

@ -1,63 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider\Validator;
use Pimple\Container;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidatorFactory as BaseConstraintValidatorFactory;
/**
* Uses a service container to create constraint validators with dependencies.
*
* @author Kris Wallsmith <kris@symfony.com>
* @author Alex Kalyvitis <alex.kalyvitis@gmail.com>
*/
class ConstraintValidatorFactory extends BaseConstraintValidatorFactory
{
/**
* @var Container
*/
protected $container;
/**
* @var array
*/
protected $serviceNames;
/**
* Constructor.
*
* @param Container $container DI container
* @param array $serviceNames Validator service names
*/
public function __construct(Container $container, array $serviceNames = array(), $propertyAccessor = null)
{
parent::__construct($propertyAccessor);
$this->container = $container;
$this->serviceNames = $serviceNames;
}
/**
* {@inheritdoc}
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (isset($this->serviceNames[$name])) {
return $this->container[$this->serviceNames[$name]];
}
return parent::getInstance($constraint);
}
}

View File

@ -1,62 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Provider\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
use Symfony\Component\Validator\Validation;
/**
* Symfony Validator component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ValidatorServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['validator'] = function ($app) {
return $app['validator.builder']->getValidator();
};
$app['validator.builder'] = function ($app) {
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory($app['validator.validator_factory']);
$builder->setTranslationDomain('validators');
$builder->addObjectInitializers($app['validator.object_initializers']);
$builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
if (isset($app['translator'])) {
$builder->setTranslator($app['translator']);
}
return $builder;
};
$app['validator.mapping.class_metadata_factory'] = function ($app) {
return new LazyLoadingMetadataFactory(new StaticMethodLoader());
};
$app['validator.validator_factory'] = function () use ($app) {
return new ConstraintValidatorFactory($app, $app['validator.validator_service_ids']);
};
$app['validator.object_initializers'] = function ($app) {
return array();
};
$app['validator.validator_service_ids'] = array();
}
}

View File

@ -1,58 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
/**
* Symfony Var Dumper component Provider.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class VarDumperServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['var_dumper.cli_dumper'] = function ($app) {
return new CliDumper($app['var_dumper.dump_destination'], $app['charset']);
};
$app['var_dumper.cloner'] = function ($app) {
return new VarCloner();
};
$app['var_dumper.dump_destination'] = null;
}
public function boot(Application $app)
{
if (!$app['debug']) {
return;
}
// This code is here to lazy load the dump stack. This default
// configuration for CLI mode is overridden in HTTP mode on
// 'kernel.request' event
VarDumper::setHandler(function ($var) use ($app) {
VarDumper::setHandler($handler = function ($var) use ($app) {
$app['var_dumper.cli_dumper']->dump($app['var_dumper.cloner']->cloneVar($var));
});
$handler($var);
});
}
}

View File

@ -1,31 +0,0 @@
{
"minimum-stability": "dev",
"name": "silex/providers",
"description": "The Silex providers",
"keywords": ["microframework"],
"homepage": "http://silex.sensiolabs.org",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.5.9",
"pimple/pimple": "~3.0",
"silex/api": "~2.0"
},
"autoload": {
"psr-4": { "Silex\\Provider\\": "" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}

View File

@ -1,202 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Routing\Route as BaseRoute;
/**
* A wrapper for a controller, mapped to a route.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Route extends BaseRoute
{
/**
* Constructor.
*
* Available options:
*
* * compiler_class: A class name able to compile this route instance (RouteCompiler by default)
*
* @param string $path The path pattern to match
* @param array $defaults An array of default parameter values
* @param array $requirements An array of requirements for parameters (regexes)
* @param array $options An array of options
* @param string $host The host pattern to match
* @param string|array $schemes A required URI scheme or an array of restricted schemes
* @param string|array $methods A required HTTP method or an array of restricted methods
*/
public function __construct($path = '/', array $defaults = array(), array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array())
{
// overridden constructor to make $path optional
parent::__construct($path, $defaults, $requirements, $options, $host, $schemes, $methods);
}
/**
* Sets the route code that should be executed when matched.
*
* @param callable $to PHP callback that returns the response when matched
*
* @return Route $this The current Route instance
*/
public function run($to)
{
$this->setDefault('_controller', $to);
return $this;
}
/**
* Sets the requirement for a route variable.
*
* @param string $variable The variable name
* @param string $regexp The regexp to apply
*
* @return Route $this The current route instance
*/
public function assert($variable, $regexp)
{
$this->setRequirement($variable, $regexp);
return $this;
}
/**
* Sets the default value for a route variable.
*
* @param string $variable The variable name
* @param mixed $default The default value
*
* @return Route $this The current Route instance
*/
public function value($variable, $default)
{
$this->setDefault($variable, $default);
return $this;
}
/**
* Sets a converter for a route variable.
*
* @param string $variable The variable name
* @param mixed $callback A PHP callback that converts the original value
*
* @return Route $this The current Route instance
*/
public function convert($variable, $callback)
{
$converters = $this->getOption('_converters');
$converters[$variable] = $callback;
$this->setOption('_converters', $converters);
return $this;
}
/**
* Sets the requirement for the HTTP method.
*
* @param string $method The HTTP method name. Multiple methods can be supplied, delimited by a pipe character '|', eg. 'GET|POST'
*
* @return Route $this The current Route instance
*/
public function method($method)
{
$this->setMethods(explode('|', $method));
return $this;
}
/**
* Sets the requirement of host on this Route.
*
* @param string $host The host for which this route should be enabled
*
* @return Route $this The current Route instance
*/
public function host($host)
{
$this->setHost($host);
return $this;
}
/**
* Sets the requirement of HTTP (no HTTPS) on this Route.
*
* @return Route $this The current Route instance
*/
public function requireHttp()
{
$this->setSchemes('http');
return $this;
}
/**
* Sets the requirement of HTTPS on this Route.
*
* @return Route $this The current Route instance
*/
public function requireHttps()
{
$this->setSchemes('https');
return $this;
}
/**
* Sets a callback to handle before triggering the route callback.
*
* @param mixed $callback A PHP callback to be triggered when the Route is matched, just before the route callback
*
* @return Route $this The current Route instance
*/
public function before($callback)
{
$callbacks = $this->getOption('_before_middlewares');
$callbacks[] = $callback;
$this->setOption('_before_middlewares', $callbacks);
return $this;
}
/**
* Sets a callback to handle after the route callback.
*
* @param mixed $callback A PHP callback to be triggered after the route callback
*
* @return Route $this The current Route instance
*/
public function after($callback)
{
$callbacks = $this->getOption('_after_middlewares');
$callbacks[] = $callback;
$this->setOption('_after_middlewares', $callbacks);
return $this;
}
/**
* Sets a condition for the route to match.
*
* @param string $condition The condition
*
* @return Route $this The current Route instance
*/
public function when($condition)
{
$this->setCondition($condition);
return $this;
}
}

View File

@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Security trait.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
trait SecurityTrait
{
public function secure($roles)
{
$this->before(function ($request, $app) use ($roles) {
if (!$app['security.authorization_checker']->isGranted($roles)) {
throw new AccessDeniedException();
}
});
}
}

View File

@ -1,60 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
/**
* Enables name_of_service:method_name syntax for declaring controllers.
*
* @link http://silex.sensiolabs.org/doc/providers/service_controller.html
*/
class ServiceControllerResolver implements ControllerResolverInterface
{
protected $controllerResolver;
protected $callbackResolver;
/**
* Constructor.
*
* @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance to delegate to
* @param CallbackResolver $callbackResolver A service resolver instance
*/
public function __construct(ControllerResolverInterface $controllerResolver, CallbackResolver $callbackResolver)
{
$this->controllerResolver = $controllerResolver;
$this->callbackResolver = $callbackResolver;
}
/**
* {@inheritdoc}
*/
public function getController(Request $request)
{
$controller = $request->attributes->get('_controller', null);
if (!$this->callbackResolver->isValid($controller)) {
return $this->controllerResolver->getController($request);
}
return $this->callbackResolver->convertCallback($controller);
}
/**
* {@inheritdoc}
*/
public function getArguments(Request $request, $controller)
{
return $this->controllerResolver->getArguments($request, $controller);
}
}

View File

@ -1,87 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
/**
* Wraps view listeners.
*
* @author Dave Marshall <dave@atst.io>
*/
class ViewListenerWrapper
{
private $app;
private $callback;
/**
* Constructor.
*
* @param Application $app An Application instance
* @param mixed $callback
*/
public function __construct(Application $app, $callback)
{
$this->app = $app;
$this->callback = $callback;
}
public function __invoke(GetResponseForControllerResultEvent $event)
{
$controllerResult = $event->getControllerResult();
$callback = $this->app['callback_resolver']->resolveCallback($this->callback);
if (!$this->shouldRun($callback, $controllerResult)) {
return;
}
$response = call_user_func($callback, $controllerResult, $event->getRequest());
if ($response instanceof Response) {
$event->setResponse($response);
} elseif (null !== $response) {
$event->setControllerResult($response);
}
}
private function shouldRun($callback, $controllerResult)
{
if (is_array($callback)) {
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($callback);
$callbackReflection = $callbackReflection->getMethod('__invoke');
} else {
$callbackReflection = new \ReflectionFunction($callback);
}
if ($callbackReflection->getNumberOfParameters() > 0) {
$parameters = $callbackReflection->getParameters();
$expectedControllerResult = $parameters[0];
if ($expectedControllerResult->getClass() && (!is_object($controllerResult) || !$expectedControllerResult->getClass()->isInstance($controllerResult))) {
return false;
}
if ($expectedControllerResult->isArray() && !is_array($controllerResult)) {
return false;
}
if (method_exists($expectedControllerResult, 'isCallable') && $expectedControllerResult->isCallable() && !is_callable($controllerResult)) {
return false;
}
}
return true;
}
}

View File

@ -1,64 +0,0 @@
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* WebTestCase is the base class for functional tests.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
abstract class WebTestCase extends \PHPUnit_Framework_TestCase
{
/**
* HttpKernelInterface instance.
*
* @var HttpKernelInterface
*/
protected $app;
/**
* PHPUnit setUp for setting up the application.
*
* Note: Child classes that define a setUp method must call
* parent::setUp().
*/
protected function setUp()
{
$this->app = $this->createApplication();
}
/**
* Creates the application.
*
* @return HttpKernelInterface
*/
abstract public function createApplication();
/**
* Creates a Client.
*
* @param array $server Server parameters
*
* @return Client A Client instance
*/
public function createClient(array $server = array())
{
if (!class_exists('Symfony\Component\BrowserKit\Client')) {
throw new \LogicException('Component "symfony/browser-kit" is required by WebTestCase.'.PHP_EOL.'Run composer require symfony/browser-kit');
}
return new Client($this->app, $server);
}
}

View File

@ -1,44 +1,57 @@
<?php
use Sikofitt\Json\ResumeBuilder;
use Webmozart\Json\FileNotFoundException;
use Webmozart\Json\ValidationFailedException;
use Silex\Provider\TwigServiceProvider;
use WhoopsSilex\WhoopsServiceProvider;
use Sikofitt\Config\YamlFileLoader;
use Symfony\Component\Config;
require_once __DIR__.'/../vendor/autoload.php';
use Webmozart\Json\DecodingFailedException;
use WhoopsSilex\WhoopsServiceProvider;
define('APP_ROOT', __DIR__ . '/../');
define('SCHEMA_URL', 'https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json');
$app = new Silex\Application();
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../app/App.php';
$app->register(new TwigServiceProvider(), [
'twig.path' => __DIR__.'/../views',
define ('APP_ROOT', __DIR__ . '/../');
define ('SCHEMA_URL', 'https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json');
$app = new App();
$app->register(new Sikofitt\Config\ConfigServiceProvider(), [
'config.path' => $app->getConfDirectory(),
]);
$app['config'] = function($app) {
$configFromFiles = \Noodlehaus\Config::load(APP_ROOT . 'config');
$defaultOptions = new \Sikofitt\Config($configFromFiles->all());
return $defaultOptions;
$app->register (new TwigServiceProvider(), [
'twig.path' => APP_ROOT . 'app/views',
]);
$app['conf'] = function ($app) {
};
$app->register(new WhoopsServiceProvider());
$app->register(new \Silex\Provider\AssetServiceProvider());
$app->register(new \Silex\Provider\MonologServiceProvider());
$app->register(new \Silex\Provider\VarDumperServiceProvider());
$app->register(new \Silex\Provider\HttpKernelServiceProvider());
$app['json.decoder'] = function($app) {
$app->register (new WhoopsServiceProvider());
$app->register (new \Silex\Provider\AssetServiceProvider());
$app->register (new \Silex\Provider\MonologServiceProvider());
$app->register (new \Silex\Provider\VarDumperServiceProvider());
$app->register (new \Silex\Provider\HttpKernelServiceProvider());
$app['json.decoder'] = function ($app) {
return new Webmozart\Json\JsonDecoder();
};
$app['json.encoder'] = function($app) {
$app['json.encoder'] = function ($app) {
return new Webmozart\Json\JsonEncoder();
};
$app['json.validator'] = function($app) {
$app['json.validator'] = function ($app) {
return new Webmozart\Json\JsonValidator();
};
$app->get('/', function() use($app) {
$app->get ('/', function () use ($app) {
$jsonErrors = [];
$resume = new ResumeBuilder($app);
$json = $resume->toJson(['array' => 'neat'], ['app' => $app, 'file' => 'resume.json']);
//$app['config']->set ('app.name', 'Groovey');
$decoded = $app['json.decoder']->decodeFile(APP_ROOT . 'resume.json', APP_ROOT . 'resume.schema.json');
dump($app['config']->get('app.debug'));
return $app['twig']->render('base.html.twig', ['resume' => $decoded]);
$decoded = [];
$app->config('app.value', 'myvalue');
dump($app->config('app'));
return $app['twig']->render ('base.html.twig', ['resume' => $decoded, 'errors' => $jsonErrors]);
});
$app->run();
$app->run ();

View File

@ -1,11 +0,0 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello', function () {
return 'Hello!';
});
$app->run();