I understand how and why to structure a Symfony project. I just wonder if is there any preferred structure under the /src direcotry. Beside the Controller, DependencyInjection, Entity etc. how do you organize your source code?
Just crowd everything under Model? Group larger logical bulks into dirs like Service, Model, Job etc? Some group their files by functionality like:
Order, Product, PopupManager etc. What is the most useful?
There are many answers to this question. I think it highly depends on what your application involves. The following are some suggestion but keep in mind that you need to imagine the structure of your application by yourself.
Little project (less than 6months and a not too much of maintenance):
.
├── Controller
├── Entity
├── Factory
├── Provider
├── Repository
├── Security
└── YourCustomThing
Or if you prefer a domain approach (I do) you can have more something like this:
.
├── Product
│ ├── DTO
│ └── Model
└── User
├── Model
├── Provider
└── Security
If you have a more complex application, then you should probably learn about DDD or CQRS. Here is a little DDD example inspired by the DDD Cargo Sample (but there is a lot more to tell about DDD apps, as well as CQRS ones).
.
├── Application
│ ├── Booking
│ │ └── Dto
│ └── Exception
├── Http
│ └── Action
├── Infrastructure
│ ├── Persistence
│ └── Product
│ ├── ActionFactory
│ └── BookingFactory
└── Model
└── Shop
Hope it helps.
Related
I have a project with a proto files in a:
$ tree proto/
proto/
├── common
│ └── request.proto
├── file
│ ├── file.proto
│ └── file_service.proto
├── job
│ ├── job.proto
│ └── job_service.proto
├── pool
│ ├── pool.proto
│ └── pool_service.proto
└── worker
├── worker.proto
└── worker_service.proto
5 directories, 9 files
I want to generate a one single file from worker_service.proto but these file has imports from common.
Is there a option in grpc_tools.protoc to generate one single python file?
Or is there a tool to generate one proto file?
Based on the information, I guess by generate one Python file means: instead of generate one Python file for messages (*_pb2.py) and one Python file for services (*_pb2_grpc.py), you hope to concatenate both of them into one Python file. To take a look at the generated file content, here is the Helloworld example.
Combining the two output file is currently not supported by the gRPC Python ProtoBuf plugin (unlike Java/Go). You can post a feature request and add more detail about your use case: https://github.com/grpc/grpc/issues
To make Artifactory as self-service as possible for our users, giving permissions to users to deploy to parts of repositories using their personal or team accounts, I'm trying to figure out how to configure this.
For readable directory structure based repositories like anything in the java world, the Permission Targets work perfectly (https://www.jfrog.com/confluence/display/RTF/Managing+Permissions). But I can't find any docs on how to use this for non-human-predicatable/readable directory structures, like PIP, or the flat directory structure, like NPM.
In the java world, repositories have a nicely structured tree like:
~/.m2/repository$ tree org/ | head -20
org/
├── antlr
│ ├── antlr4-master
│ │ └── 4.7.1
│ │ ├── antlr4-master-4.7.1.pom
│ │ ├── antlr4-master-4.7.1.pom.sha1
│ │ └── _remote.repositories
│ └── antlr4-runtime
│ └── 4.7.1
│ ├── antlr4-runtime-4.7.1.jar
│ ├── antlr4-runtime-4.7.1.jar.sha1
│ ├── antlr4-runtime-4.7.1.pom
│ ├── antlr4-runtime-4.7.1.pom.sha1
│ └── _remote.repositories
├── apache
│ ├── ant
│ │ ├── ant
│ │ │ ├── 1.10.1
│ │ │ │ ├── ant-1.10.1.jar
│ │ │ │ ├── ant-1.10.1.jar.sha1
For example, to give teamantl permission to only read, annotate, and write to org/antlr/antlr4-master/**, the following json can be PUT to Artifactory REST API (PUT /api/security/permissions/{permissionTargetName})
{
"includesPattern": "org/antlr/antlr4-master/**",
"repositories": [
"libs-release-local",
"libs-snapshot-local"
],
"principals": {
"groups" : {
"teamantl": ["r","n","w"]
}
}
}
But for example a pip repo is completely hashed:
Which is completely useless in the permission target "includesPattern".
How should this (Permission Targets) work for repo's like PIP, and NPM?
Your screenshot shows a virtual PyPI repo, which is generated and thus hash-structured.
Normally, these are backed by physical repos, filled using twine upload and thus having a ‹pkg›/‹version›/‹file› structure – i.e. perfectly usable as permission targets with package granularity.
I'm using Spring Boot and I want to know how exactly we mention the path to static content in my JSP files?
I tried to make them in src/main/resources/static/css but it was not working, and in my JSP I called them by using:
<link href="<c:url value="/css/bootstrap.min.css" />" rel="stylesheet" type="text/css">
I have no special configuration in my SpringBoot Class just the call SpringApplication.run(...)
Thank you so much for the help!
you have to have configuration that extends WebMvcAutoConfigurationAdapter , it has registry implementation that has automatically scans for some default locations and adds them to classpath
/META-INF/resources/
/resources/
/static/
/public/
Just add,
#Configuration
#EnableWebMvc
#ComponentScan
public class ServerConfiguration extends WebMvcAutoConfiguration{
}
using springboot 1.5.6.RELEASE my folder structure looks like
~/repos/static-content-example/src > tree
.
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ ├── DemoApplication.java
│ │ └── MvcConfig.java
│ └── resources
│ ├── application.properties
│ ├── public
│ │ └── test.html
│ └── templates
└── test
└── java
└── com
└── example
└── demo
└── DemoApplicationTests.java
and when I start the server, I can browse to
http://localhost:8080/test.html
http://localhost:8080/public/test.html
anything in the folder "public" is accessible by default at your context root (#1 above). MvcConfig.java allows for #2. I always setup that alias so I can ignore security on any URL that starts with /public. In order to do that without the MvcConfig setup, you'd have to put a folder named public inside the public folder, which is just confusing.
I have no idea why spring doesn't do that by default....seems like it would clear up lots of confusion...
I'm porting an application from php to node(sailsjs) at the same time trying to replace ant with grunt. I like the current project build structure and I would like to preserve some of it.
It looks like below...
project root
├── build (git ignored)
│ ├── coverage
│ ├── dist(to be deployed to target env)
│ └── local(to be deployed to local env)
├── lib
│ └── some library files like selenium..etc.
├── src
│ ├── conf
│ │ └── target/local properties
│ ├── scripts(may not be needed with grunt??)
│ │ ├── db
│ │ │ └── create_scripts...
│ │ ├── se
│ │ │ └── run_selenium_scripts...
│ │ └── tests
│ │ └── run_unit_test_scripts...
│ ├── tests
│ │ └── test_code....
│ └── webapp(this is where I'd like to place node[sailsjs] code)
│ └── code....
└── wiki .etc...
It doesn't exactly have to be the same way as above but more or less I prefer to build something similar. Now, pretty much all the sailsjs examples I have seen look like below.
project root
├── .tmp
│ └── stuff...
├── package.json
├── tasks
│ ├── config
│ │ └── grunt task configs...
│ └── register
│ └── grunt task registrations...
├── tests
│ ├── unit
│ └── selenium
└── Gruntfile.js
Where should I place Gruntfile.js, app.js, package.json to achieve what I want? What other detail should I have to make grunt function and create artifacts as I want them?
Note: Obviously I'm not expecting to get all the details of grunt configuration. But I guess it helps to see where most important things go and how basic tasks could be configured.
Thanks for your answer.
It's hard to give a precise answer without a detail of your build steps, but I would suggest:
Gruntfile.js and package.json go to your root folder
you setup your individual build tasks (whatever they are) to output to build: see the doc of each task on how to do that, it's usually the dest option
Hope this helps a bit.
In my symfony 2 project I have a bundle at
src/Cinergy/Bundle/PeopleServiceBundle
Now I'd like to generate a CRUD controller based on a doctrine entity, but I'm constantly failing to enter the correct string for the entity parameter.
I tried things like:
php app/console generate:doctrine:crud --entity=Cinergy/Bundle/PeopleServiceBundle:Group
or
php app/console generate:doctrine:crud --entity=#PeopleServiceBundle:Group
All of them return erros like:
[Doctrine\ORM\ORMException]
Unknown Entity namespace alias '#PeopleServiceBundle'.
What's the right syntax for the --entity parameter? Or is there something missing after all?
This is how the directory structure looks right now:
src/Cinergy/Bundle/PeopleServiceBundle/
├── Controller
│ ├── GroupController.php
│ └── PersonController.php
├── DependencyInjection
│ ├── Configuration.php
│ └── PeopleServiceExtension.php
├── PeopleServiceBundle.php
├── Resources
│ ├── config
│ │ ├── routing.yml
│ │ └── services.yml
│ ├── doc
│ │ └── index.rst
│ ├── public
│ │ ├── css
│ │ ├── images
│ │ └── js
│ ├── translations
│ │ └── messages.fr.xliff
│ └── views
│ └── Default
│ └── index.html.twig
└── Tests
└── Controller
├── GroupControllerTest.php
└── PersonControllerTest.php
After all it turned out that I have to create the entity before I can create the CRUD controller for it. Of course that makes sense. Unfortunately the Sensio Generator Bundle documentation does list the operations in the oposite order which pushed me into the wrong direction.
This means the correct order ist
Generating a New Bundle Skeleton
Generating a New Doctrine Entity Stub
Generating a CRUD Controller Based on a Doctrine Entity
First you need to register your bundle into your AppKernel.
Then simply run the following command.
Don't put # before the bundle's name
php app/console generate:doctrine:crud --entity=PeopleServiceBundle:Group
More about generating a CRUD controller based on a Doctrine entity.
According to the symfony docs, you have to use " The entity name given as a shortcut notation containing the bundle name in which the entity is located and the name of tvhe entity", so it should be something like
--entity=CinergyPeopleServiceBundle:Group
If you have more than one Bundle and want to use different database connection just update your config.yml and parameters.yml by adding configuration and parameters.
This will solve problem with CRUD generation.
I searched for hours until I found out that in my app/config/config.yml under doctrine.orm I removed auto_mapping: true which caused the issue. This may be useful for other people :)
If it still relevant for someone :)
guys, it's because DoctrineBundle DoctrineExtension compile the list of valid aliases based on all registered bundles, that have 'Entity' (or other configured) folder in them.
So in order to use doctrine:generate:crud or generate:doctrine:crud,
you have to create just folder Entity in your bundle, and not required to create entity first (as command says - it's true).
So you it will work if you already have some entity in your bundle,
or if you have just empty Entity folder in your bundle.