Closed (fixed)
Project:
Examples for Developers
Version:
8.x-1.x-dev
Component:
File Example
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Dec 2015 at 06:26 UTC
Updated:
19 Jan 2017 at 04:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mile23The patch, pulled from #2102651-89: Port file_example module to Drupal 8
Comment #3
jkopel commentedNeed to add stream wrapper example menu item to tool bar in examples.module examples_toolbar().
Testing StreamWrapperTest failed in the UI
CLI phpunit test unable to find any tests
White space errors
Controller Class name should be StreamWrapperExampleController.
Comment #4
jkopel commentedPatch for #3
Comment #5
mile23Thanks, @jkopel
Quite a bit to do here, let's see who gets to it. :-)
The tests are still a bit funky, there are a bunch of coding standards issues, and maybe this will help the tests:
KernelTestBase gives us a $container which contains the test fixture container based on the fixture kernel, which we just told to enable stream_wrapper_example. Therefore, the existing $container should have done all the work.
There might be some subtle thing I'm missing, though.
Rename to testSessionScheme(). Dialtone is too obscure.
After all that with $container, we call \Drupal here? :-)
Comment #6
mile23Oh wait, I forgot. This issue passes green because of #2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-tests
Comment #7
mile23Need to add a @todo saying we should move this to the tests namespace after #2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits
Comment #8
mile23@todo: Eventually we need to update
Drupal\file_example\Form\FileExampleReadWriteForm::getSessionWrapper()to use this module.Like this:
Comment #9
Torenware commentedRerolling the patch to start work on it again; just a merge, no other changes.
Comment #10
Torenware commentedReintegrated the example with the file_example; fixed @Mile23 comments.
Comment #11
Torenware commentedAdded back the SessionWrapper wrangling code to the File Example.
Comment #12
mile23Very close now.... :-)
CS and docs stuff mostly. Run phpcs and see what else you find.
. When you read, write, delete or move that
+ file, the
publicscheme's stream wrapper class+ (
\Drupal\Core\StreamWrapper\PublicStream) is invoked to do the reading,+ writing, deletion or moving. PHP does this automatically for you, creating the wrapper
+ whenever some file operation needs to get done on a
public://file.+
+
+
To demonstrate how to implement a stream wrapper, this example module creates a
+
sessionwrapper scheme. It uses your session data (created when you+ log into Drupal) to create a nested array where the arrays represent directories,
+ and scalar values represent files. This is completely impractical, and frankly,
+ not terribly secure, so you should never enable this module on any site that's
+ open to the Internet. But without using any special libraries, our stream wrapper
+ class is able to create and delete directories, and read and write files.
+
+
+
If you want to play with
sessionfile URIs, we recommend also enabling+ the File Example (file_example.module), which will let you do the same things with
+ the "session" scheme that you can do with public, private or temporary files.
+
+
A longer description of what code is where can be found in
+
stream_wrapper_example.module. Definitely look through the code to see+ various implementation details.
+++ b/stream_wrapper_example/tests/src/Kernel/StreamWrapperTest.php
@@ -0,0 +1,162 @@
+ * it loads in background automatically as soon as the stream_wrapper_example module
...
+ // we use dependency injection (DI) to get that information to the class. But
+ // stream wrappers are unusual. They are created automatically by PHP itself
+ // when it calls one of the standard file functions, and for that reason, the
...
+ // which prevents us from using the stardard DI technique we use in Drupal 8.
Lots of 80 char wrap needed.
Also lots of not-wrapped-out-to-80 stuff, as well, but that's a better problem to have, and our phpcs config doesn't force it (yet). :-)
If these are part of the interface, they should say {@inheritdoc} instead of implements.
Documents @return bool, but never calls return.
First line of comment should be one line.
No . after $store.
We shouldn't have commented code. We should explain what's going on.
Comment #13
Torenware commentedThanks @Mile23.
Yeah, lots of CS issues. Most should be easy enough to fix.
One thing related to this. Stream Wrappers extend a standard PHP interface. This interface itself violates certain aspects of the standard Drupal specs, especially camel case for method names -- the interface uses underscores. Can't change this, since it's not our interface.
What I *can* do is explain that we're using this interface, and quiet the apparent coding errors using @codingStandardsIgnoreStart and @codingStandardsIgnoreEnd. It's that, or accept that there will be unfix errors on the relevant files. You've got an opinion on this one?
Comment #14
mile23The non-standard method names doesn't trigger the current phpcs config we have for Examples. So eventually we'll run up against that and fix it when the rule gets added.
Comment #15
Torenware commentedNo on that; I'm using the current rules, and the PublicMethod rule is applied, PITA though that is. So Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps is already in, and it bites me.
In any case, here's a version of the patch that fixes everything but that.
Comment #17
mile23I'm calling this done. :-)
Thanks @Torenware and @jkopel!