承接 salamek/doctrine-daterange 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

salamek/doctrine-daterange

最新稳定版本:v1.1

Composer 安装命令:

composer require salamek/doctrine-daterange

包简介

Supports postgre DateRange in Doctrine DBAL.

README 文档

README

Build Status

Supports PostgreSQL DateRange in Doctrine DBAL.

Summary

The DateRange library

  • adds a daterange type to DBAL

Installation

Add it to your list of Composer dependencies:

composer require salamek/doctrine-daterange

Register it with Doctrine DBAL:

<?php

use Doctrine\DBAL\Types\Type;
use Salamek\Doctrine\DBAL\Types\DateRangeType;

Type::addType(
    DateRangeType::DATERANGE,
    'Salamek\\Doctrine\\DBAL\\Types\\DateRangeType'
);

When using Symfony2 with Doctrine you can do the same as above by only changing your configuration:

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            daterange: daterange
        types:
            daterange:  Salamek\Doctrine\DBAL\Types\DateRangeType

Usage

<?php

/**
 * @Entity()
 * @Table(name="jobs")
 */
class Job
{
    /**
     * @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     * @Id()
     */
    private $id;

    /**
     * @Column(type="daterange")
     */
    private $range;

    /**
     * @return \Salamek\DateRange
     */
    public function getRange()
    {
        return $this->range;
    }

    /**
     * @param \Salamek\DateRange $range
     */
    public function setRange(\Salamek\DateRange $range)
    {
        $this->range = $range;
    }
}

$annualJob = new Job();
$annualJob->setRange(new \Salamek\DateRange(new \DateTime, (new \DateTime)->modify('+1 year')));

$entityManager->persist($annualJob);
$entityManager->flush();
$entityManager->clear();

$jobs = $entityManager->createQuery(
    "SELECT j FROM Jobs j"
)->getResult();

echo $jobs[0]->getRange()->getStartDate()->format(DateTime::ISO8601); // "NOW"
echo $jobs[0]->getRange()->getEndDate()->format(DateTime::ISO8601); //  "NOW +1 year"

统计信息

  • 总下载量: 16.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-23