dovstone/symfony-blog-admin-bundle-mynosql-based
Installation Add the bundle to your Symfony project via Composer:
composer require dovstone/symfony-blog-admin-bundle-mynosql-based
Enable the bundle in config/bundles.php:
return [
// ...
Dovstone\BlogAdminBundle\DovstoneBlogAdminBundle::class => ['all' => true],
];
Database Configuration
Configure MyNoSQL in .env (adjust per your NoSQL provider, e.g., MongoDB, CouchDB):
MYNOSQL_DSN=mongodb://localhost:27017
MYNOSQL_DATABASE=blog_db
First Use Case: Create a Post Use the provided CLI command to scaffold a blog post:
php bin/console dovstone:blog:post:create --title="First Post" --content="Hello World!"
Verify the post in your NoSQL database (e.g., via MongoDB Compass or php bin/console dovstone:blog:post:list).
src/Resources/doc/index.md for high-level usage.php bin/console list dovstone to explore available CLI tools.src/Controller/ for RESTful endpoints (e.g., PostController).src/Entity/ for NoSQL document structures (e.g., Post.php).CRUD Operations via CLI
dovstone:blog:post:createdovstone:blog:post:list or dovstone:blog:post:show <id>dovstone:blog:post:edit <id> --title="New Title"dovstone:blog:post:delete <id>
Tip: Use --force for destructive actions (e.g., delete).RESTful API Integration
The bundle exposes endpoints under /api/blog:
GET /api/blog/posts → List posts (paginated).POST /api/blog/posts → Create a post (JSON payload).GET /api/blog/posts/{id} → Show a post.
Example Payload:
{
"title": "API Post",
"content": "Created via API",
"tags": ["api", "symfony"]
}
Event-Driven Extensions
Listen to bundle events (e.g., PostCreatedEvent) in your EventSubscriber:
use Dovstone\BlogAdminBundle\Event\PostCreatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
PostCreatedEvent::class => 'onPostCreated',
];
}
public function onPostCreated(PostCreatedEvent $event)
{
// Send notification, log analytics, etc.
}
}
Twig Integration
Embed posts in templates using the blog_post Twig function:
{% for post in blog_post.list() %}
<h2>{{ post.title }}</h2>
<p>{{ post.content|truncate(100) }}</p>
{% endfor %}
Post entity by overriding src/Entity/Post.php and updating the NoSQL schema.# config/packages/security.yaml
access_control:
- { path: ^/api/blog, roles: ROLE_USER }
Test\BlogAdminBundleTest class as a base for functional tests:
use Dovstone\BlogAdminBundle\Test\BlogAdminBundleTest;
class MyBlogTest extends BlogAdminBundleTest
{
public function testPostCreation()
{
$this->createPost(['title' => 'Test']);
$this->assertDatabaseHas('posts', ['title' => 'Test']);
}
}
NoSQL Schema Mismatches
Post entity may not map to the NoSQL schema.#[MyNoSQL\Annotation\Document] and #[MyNoSQL\Annotation\Field] annotations. Example:
#[MyNoSQL\Annotation\Document(collection: "posts")]
class Post
{
#[MyNoSQL\Annotation\Field(type: "string")]
private string $title;
}
CLI Command Conflicts
config/packages/dovstone_blog_admin.yaml:
dovstone_blog_admin:
commands:
create_post: 'app:blog:post:create' # Custom namespace
Pagination Limits
PostRepository to adjust limits:
class CustomPostRepository extends PostRepository
{
public function findAllWithPagination(int $page = 1, int $limit = 50)
{
return $this->createQueryBuilder()
->skip(($page - 1) * $limit)
->limit($limit)
->getQuery()
->execute();
}
}
Event Dispatching
EventDispatcher is autowired in your subscriber and the event class is fully qualified:
use Dovstone\BlogAdminBundle\Event\PostCreatedEvent; // Correct namespace
Enable Debug Mode
Set APP_DEBUG=1 in .env to see detailed errors and SQL/NoSQL queries.
Log NoSQL Queries Configure Monolog to log MyNoSQL queries:
# config/packages/monolog.yaml
handlers:
mynosql:
type: stream
path: "%kernel.logs_dir%/mynosql.log"
level: debug
channels: ["mynosql"]
Validate Entities Use Symfony’s validator to catch entity issues early:
php bin/console debug:validator Dovstone\BlogAdminBundle\Entity\Post
Custom Actions
Add new CLI commands by extending the Command base class:
namespace App\Command;
use Dovstone\BlogAdminBundle\Command\AbstractBlogCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExportPostsCommand extends AbstractBlogCommand
{
protected function configure()
{
$this->setName('app:blog:export');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Custom logic (e.g., export to CSV)
}
}
Override Templates
Customize Twig templates by copying files from vendor/dovstone/symfony-blog-admin-bundle-mynosql-based/templates/ to templates/bundles/dovstoneblogadmin/.
Add Middleware Inject middleware for API requests (e.g., rate limiting):
# config/packages/api_platform.yaml
api_platform:
formats:
jsonld:
mime_types: ['application/ld+json']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
How can I help you explore Laravel packages today?