Skip to content

Commit

Permalink
Simplify the way shims are created
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Sep 12, 2014
1 parent 63cd5df commit bbac636
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 75 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
@@ -1,9 +1,12 @@
CHANGE LOG
==========

## 1.0.3 (2014-09-12)
- Simplify the way shims are created.

## 1.0.2 (2014-09-11)
- Wrong encoding of Hebrew dates
- Emulate PHP bug 54254 in Hebrew dates
- Wrong encoding of Hebrew dates.
- Emulate PHP bug 54254 in Hebrew dates.

## 1.0.1 (2014-09-11)
- Improve coverage of unit tests.
Expand Down
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -45,25 +45,31 @@ Add the package as a dependency in your `composer.json` file:
"fisharebest/ext-calendar": "1.*"
}

Bootstrap the package:
If you want to create the “shim” functions, you must tell the package to create them.

// bootstrap.php
require 'vendor/autoload.php';
\Fisharebest\ExtCalendar\Bootstrap::init();
// Put this in your bootstrap.php or similar.
\Fisharebest\ExtCalendar\Shim::create();

Use the PHP functions, whether the extension is loaded or not:
Now you can use the PHP functions, whether the ext/calendar is installed or not:

print_r(cal_info(CAL_GREGORIAN));

Use the calendar classes directly:
Alternatively, just use the calendar classes directly.

// Create a calendar
$cal = new FrenchCalendar;
$cal = new GregorianCalendar;
$cal = new JewishCalendar;
$cal = new JulianCalendar;

// Date conversions
$jd = $cal->ymdToJd($year, $month, $day);
list($year, $month, $day) = $cal->jdToYmd($jd);

// Information functions (see the source for more)
$is_leap_year = $cal->leapYear($year);
$day_of_week = $cal->dayOfWeek($jd);
$month_length = $cal->daysInMonth($year, $month);
// See the source for more…

Known restrictions and limitations
==================================
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions src/Bootstrap.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Shim.php
Expand Up @@ -22,6 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class Shim {
/**
* Create the necessary shims to emulate the ext/calendar packate.
*
* @return void
*/
public static function create() {
if (!function_exists('cal_info')) {
require __DIR__ . '/shims.php';
}
}

/**
* Do we need to emulate PHP bug #54254?
*
Expand Down
31 changes: 0 additions & 31 deletions test/BootstrapTest.php

This file was deleted.

10 changes: 10 additions & 0 deletions test/ShimTest.php
Expand Up @@ -32,6 +32,16 @@ class ShimTest extends TestCase {
*/
const LARGE_PRIME = 235741;

/**
* Test that after we call create(), we have the necessary functions/constants.
*
* @return void
*/
public function testCreate() {
Shim::create();
$this->assertTrue(defined('CAL_JEWISH'));
}

/**
* Test the implementation of Shim::calDaysInMonth() against \cal_days_in_month()
*
Expand Down

0 comments on commit bbac636

Please sign in to comment.