tourze / hotel-profile-bundle
酒店档案管理模块,提供酒店信息和房型管理功能
Installs: 416
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/hotel-profile-bundle
Requires
- php: ^8.1
- doctrine/collections: ^2.3
- doctrine/data-fixtures: ^2.0
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-fixtures-bundle: ^4.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- phpoffice/phpspreadsheet: ^3.9
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/routing: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/easy-admin-menu-bundle: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/symfony-routing-auto-loader-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
[]
(https://packagist.org/packages/tourze/hotel-profile-bundle)
[
]
(https://packagist.org/packages/tourze/hotel-profile-bundle)
Hotel profile management bundle for Symfony applications. This bundle provides comprehensive hotel and room type management functionality with administrative interfaces, Excel import/export capabilities, and EasyAdmin integration.
Note: This is an internal package for the monorepo architecture and is not published to Packagist.
Table of Contents
- Features
- Installation
- Quick Start
- Requirements
- Configuration
- Entities
- Services
- Enums
- Admin Interface
- API Endpoints
- Advanced Usage
- Testing
- Contributing
- License
- Support
Features
- Hotel Management: Complete CRUD operations for hotel profiles
- Room Type Management: Room type configurations for each hotel
- Excel Import/Export: Bulk import and export hotel data via Excel files
- EasyAdmin Integration: Ready-to-use administrative interface
- Status Management: Hotel operational status tracking
- Validation: Comprehensive data validation with Symfony constraints
- Audit Trail: Automatic timestamp tracking for all entities
Installation
Step 1: Monorepo Usage
This bundle is designed for use within the monorepo architecture. It's automatically available when you set up the monorepo project.
Step 2: Enable the Bundle
The bundle is automatically registered in the Symfony kernel. You can verify it's enabled by checking:
bin/console debug:container --tag=kernel.bundles
Step 3: Update Database Schema
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
Step 4: Verify Installation
# Check if hotel-related routes are available bin/console debug:router | grep hotel # Check if services are registered bin/console debug:container HotelService
Quick Start
Basic Usage
<?php use Tourze\HotelProfileBundle\Entity\Hotel; use Tourze\HotelProfileBundle\Enum\HotelStatusEnum; use Tourze\HotelProfileBundle\Service\HotelService; // Create a new hotel $hotel = new Hotel(); $hotel->setName('Grand Hotel'); $hotel->setAddress('123 Main Street'); $hotel->setStarLevel(5); $hotel->setContactPerson('John Doe'); $hotel->setPhone('+1234567890'); $hotel->setStatus(HotelStatusEnum::OPERATING); // Use the hotel service $hotelService = $container->get(HotelService::class); // Find hotels by status $operatingHotels = $hotelService->findHotelsByStatus(HotelStatusEnum::OPERATING); // Update hotel status $hotelService->updateHotelStatus($hotelId, HotelStatusEnum::SUSPENDED);
Requirements
- PHP 8.1+
- Symfony 7.3+
- Doctrine ORM 3.0+
- EasyAdmin Bundle 4+
- Doctrine DBAL 4.0+
- PHPSpreadsheet for Excel operations
Configuration
The bundle requires minimal configuration. After installation, it automatically registers all necessary services.
Entities
Hotel Entity
The Hotel entity includes:
- Basic information (name, address, contact details)
- Star rating (1-5 stars)
- Photo gallery (JSON array of URLs)
- Facilities information (JSON array)
- Operational status
- One-to-many relationship with room types
Room Type Entity
The RoomType entity includes:
- Room type details and pricing
- Availability status
- Association with hotel
Services
HotelService
Core business service for hotel operations:
use Tourze\HotelProfileBundle\Service\HotelService; // Find hotels by status $operatingHotels = $hotelService->findHotelsByStatus(HotelStatusEnum::OPERATING); // Update hotel status $hotelService->updateHotelStatus($hotelId, HotelStatusEnum::SUSPENDED);
RoomTypeService
Room type management service:
use Tourze\HotelProfileBundle\Service\RoomTypeService; // Find room types by hotel $roomTypes = $roomTypeService->findRoomTypesByHotel($hotelId); // Find room types by status $activeRoomTypes = $roomTypeService->findRoomTypesByStatus(RoomTypeStatusEnum::ACTIVE);
HotelImportExportService
Excel import/export functionality:
use Tourze\HotelProfileBundle\Service\HotelImportExportService; // Export hotels to Excel $exportResult = $importExportService->exportHotelsToExcel(); // Create import template $template = $importExportService->createImportTemplate(); // Import hotels from Excel $importResult = $importExportService->importHotelsFromExcel($uploadedFile);
Enums
HotelStatusEnum
Hotel operational status:
OPERATING: Hotel is currently operatingSUSPENDED: Hotel cooperation is suspended
RoomTypeStatusEnum
Room type availability status:
ACTIVE: Room type is available for bookingDISABLED: Room type is temporarily disabled
Admin Interface
The bundle provides EasyAdmin CRUD controllers:
- Hotel management at
/admin/hotel - Room type management at
/admin/room-type - Import/export functionality in admin interface
API Endpoints
Administrative API endpoints are available for:
- Room type management
- Hotel data operations
Advanced Usage
Custom Validation Rules
You can extend the bundle's validation by creating custom validators:
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; class CustomHotelValidator extends ConstraintValidator { public function validate($value, Constraint $constraint): void { // Custom validation logic } }
Event Listeners
Listen to hotel-related events:
use Symfony\Component\EventDispatcher\EventSubscriberInterface; class HotelEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ 'hotel.created' => 'onHotelCreated', 'hotel.updated' => 'onHotelUpdated', ]; } public function onHotelCreated(HotelEvent $event): void { // Handle hotel creation } }
Custom Export Formats
Extend the import/export service to support additional formats:
use Tourze\HotelProfileBundle\Service\HotelImportExportService; class CustomImportExportService extends HotelImportExportService { public function exportToCsv(): Response { // Custom CSV export logic } }
Data Fixtures
Sample data fixtures are provided for testing:
HotelFixtures: Sample hotel dataRoomTypeFixtures: Sample room type configurations
Testing
The bundle includes comprehensive test coverage:
# Run all tests vendor/bin/phpunit packages/hotel-profile-bundle/tests # Run specific test categories vendor/bin/phpunit packages/hotel-profile-bundle/tests/Entity vendor/bin/phpunit packages/hotel-profile-bundle/tests/Service vendor/bin/phpunit packages/hotel-profile-bundle/tests/Controller # Run with coverage vendor/bin/phpunit packages/hotel-profile-bundle/tests --coverage-html coverage/ # Run static analysis vendor/bin/phpstan analyse packages/hotel-profile-bundle
Contributing
We welcome contributions to this bundle! Here's how you can help:
Reporting Issues
If you find a bug or have a feature request, please create an issue on our GitHub repository.
Submitting Pull Requests
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests:
vendor/bin/phpunit packages/hotel-profile-bundle/tests - Run static analysis:
vendor/bin/phpstan analyse packages/hotel-profile-bundle - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Standards
- Follow PSR-12 coding standards
- Add PHPDoc comments for all public methods
- Write unit tests for new features
- Ensure backward compatibility
License
This bundle is open-sourced software licensed under the MIT License. Please see the LICENSE file for more information.
Support
For issues and feature requests, please use the GitHub issue tracker.