定制 langemike/php-store-hours 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

langemike/php-store-hours

Composer 安装命令:

composer require langemike/php-store-hours

包简介

Bringing php-store-hours into Laravel

README 文档

README

PHP Store Hours is a simple PHP class that outputs content based on time-of-day and-day-of-week. Simply include the script in any PHP page, adjust opening and closing hours for each day of the week and the script will output content based on the time ranges you specify.

Easily set open hours for each day of the week

// REQUIRED
// Define daily open hours
// Must be in 24-hour format, separated by dash
// If closed for the day, leave blank (ex. sunday) or don't add line
// If open multiple times in one day, enter time ranges separated by a comma
$hours = array(
    'mon' => array('11:00-20:30'),
    'tue' => array('11:00-13:00', '18:00-20:30'),
    'wed' => array('11:00-20:30'),
    'thu' => array('11:00-1:30'), // Open late
    'fri' => array('11:00-20:30'),
    'sat' => array('11:00-20:00'),
    'sun' => array() // Closed all day
);

Add exceptions for specific dates / holidays

// OPTIONAL
// Add exceptions (great for holidays etc.)
// MUST be in format month/day[/year] or year-month-day
// Do not include the year if the exception repeats annually
$exceptions = array(
    '2/24'  => array('11:00-18:00'),
    '10/18' => array('11:00-16:00', '18:00-20:30')
);

Customize the final output with shortcodes

Choose what you'd like to output if you're currently open, currently closed, or closed all day. Shortcodes add dynamic times to your open or closed message.

// OPTIONAL
// Place HTML for output below. This is what will show in the browser.
// Use {%hours%} shortcode to add dynamic times to your open or closed message.
$template = array(
    'open'           => "<h3>Yes, we're open! Today's hours are {%hours%}.</h3>",
    'closed'         => "<h3>Sorry, we're closed. Today's hours are {%hours%}.</h3>",
    'closed_all_day' => "<h3>Sorry, we're closed today.</h3>",
    'separator'      => " - ",
    'join'           => " and ",
    'format'         => "g:ia", // options listed here: http://php.net/manual/en/function.date.php
    'hours'          => "{%open%}{%separator%}{%closed%}"
);

Available Methods

render([timestamp = time()])

This is the default method that outputs the templated content. You'll most likely want to use this.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->render();

hours_overview([groupSameDays = false])

This returns an array with a full list of open hours (for a week without exceptions). Days with same hours will be grouped.

$store_hours = new StoreHours($hours, $exceptions, $template);

echo '<table>';
foreach ($store_hours->hours_overview() as $days => $hours) {
    echo '<tr>';
    echo '<td>' . $days . '</td>';
    echo '<td>' . $hours . '</td>';
    echo '</tr>';
}
echo '</table>';

hours_today([timestamp = time()])

This returns an array of the current day's hours.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->hours_today();

is_open([timestamp = time()])

This returns true/false depending on if the store is currently open.

$store_hours = new StoreHours($hours, $exceptions, $template);
$store_hours->is_open();

Use Cases

Multiple stores / sets of hours

If you'd like to show multiple sets of hours on the same page, simply invoke two separate instances of StoreHours. Remember to set the timezone before each new instance.

// New York Hours
date_default_timezone_set('America/New_York');
$nyc_store_hours = new StoreHours($nyc_hours, $nyc_exceptions, $nyc_template);
$nyc_store_hours->render();

// Los Angeles Hours
date_default_timezone_set('America/Los_Angeles');
$la_store_hours = new StoreHours($la_hours, $la_exceptions, $la_template);
$la_store_hours->render();

Testing

$ phpunit

Troubleshooting

If you're getting errors or if times are not rendering as expected, please double check these items before filing an issue on GitHub:

  • Make sure your timezone is configured
  • Ensure all exceptions use the month/day format
  • Verify that StoreHours.class.php is properly included on the page

Please report any bugs or issues here on GitHub. I'd love to hear your ideas for improving this script or see how you've used it in your latest project.

Sites using PHP Store Hours

Credits

Goes to Cory Etzkorn for developing php-store-hours

langemike/php-store-hours 适用场景与选型建议

langemike/php-store-hours 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.9k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「storehours」 「openingtimes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 langemike/php-store-hours 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 langemike/php-store-hours 我们能提供哪些服务?
定制开发 / 二次开发

基于 langemike/php-store-hours 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 54
  • 开发语言: PHP

其他信息

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