devdot / bible-text-provider
通过引用从本地文件提供圣经文本。
Requires
- php: ^8.2
Requires (Dev)
- captainhook/captainhook: ^5.23
- friendsofphp/php-cs-fixer: ^3.58
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.1
- rector/rector: ^1.1
- stevenbuehner/bible-verse-bundle: ^2.6
This package is auto-updated.
Last update: 2024-09-05 10:13:02 UTC
README
通过引用从本地文件提供圣经文本。
此库可以很好地为使用stevenbuehner/bible-verse-bundle找到的经文引用提供文本。
安装
使用composer安装库
composer require devdot/bible-data-provider
然后提供您自己的数据文件。由于版权问题,此软件包不提供实际的圣经文本。请参阅构建自己的数据。如果您需要有关如何生成自己的圣经文本的提示,您可以联系我。
基本用法
use Devdot\Bible\Text\BibleTextProvider; use Devdot\Bible\Text\Loaders\BiblesLoader; // build a loader that points to the root file // second argument defaults to 'bibles.php' $loader = new BiblesLoader('dir/to/data'); // build the provider with the given loader // additionally, you may set the default translation $provider = new BibleTextProvider($loader, 'NIV'); // find out about the available bibles foreach($provider->getAvailableBibles() as $bible) { echo $bible->abbreviation; } // retrieve some text $bible = $provider->getBible('NIV'); echo $bible->books->get('JHN')->chapters->get(3)->verses->get(16)->getText(); echo $bible->books['JHN']->chapters[3]->verses[16]; // using array access
您可以快速加载引用的经文(由stevenbuehner/bible-verse-bundle提供)
use StevenBuehner\BibleVerseBundle\Service\BibleVerseService; // find the reference from a string using stevenbuehner/bible-verse-bundle $reference = (new BibleVerseService())->stringToBibleVerse('Genesis 1:1-20')[0]; // load the text $verses = $provider->getVersesFromReference($reference, 'NIV'); // display them foreach($verses as $verse) { echo $verse->getText(); }
构建自己的数据
如上所述,由于法律原因,我无法在此软件包中提供实际的圣经文本。您可以从公共来源构建自己的圣经数据,然后使用此软件包将其提供给您的PHP应用程序。
数据格式的一个例子可以在tests/data中看到。
根文件(bibles.php)
此文件提供给BiblesLoader
。只有当访问任何圣经时才会加载。
<?php // bibles.php return [ 'NIV' => [ // abbreviations are used as keys to identify the bibles when loading 'id' => 'niv', // id has no technical relevance 'abbreviation' => 'NIV', 'name' => 'New International Version', 'description' => 'New International Version', 'copyright' => '1979, 1984, 2011 by Biblica, Inc.', 'language' => 'eng', 'updated_at' => '2024-06-05 11:10:00', 'books' => 'niv/books.php', // relative link from this file to the books list for NIV ], 'VUL' => [ 'id' => 'vul', 'abbreviation' => 'VUL', 'name' => 'Biblia Sacra Vulgata ', 'description' => 'Vulgate', 'copyright' => 'Biblia Sacra Iuxta Vulgatam Versionem', 'language' => 'lat', 'updated_at' => '2024-06-05 11:10:00', 'books' => 'vul/books.php', ], ];
有关工作示例,请参阅tests/data/test-bibles.php。
书籍列表(books.php)
只有当访问给定圣经的书籍时才会加载此文件。其在bibles.php
中的相对位置必须定义。
<?php // books.php return [ // map the book ID (key) to the relative book file (value) 'GEN' => '0-gen.php', 'EXO' => 'exodus.php', // ... ];
有关工作示例,请参阅tests/data/tes/books.php。
有关书籍ID的信息,您可以在BookIdResolver Helper中查看。您也可以引入您自己的书籍ID系统。
书籍文件
只有当访问给定圣经的相应书籍时才会加载这些文件。其在books.php
中的相对位置必须定义。
<?php // book file example: 0-gen.php for NIV return [ 'id' => 'GEN', // same as the key in books.php 'abbreviation' => 'Gen.', 'name' => 'Genesis', 'name_long' => 'Genesis', 'chapters' => [ 1 => [ // chapter number as key // verses as number (key) => text (value) 1 => 'In the beginning God created the heavens and the earth.', 2 => 'Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.', // ... ], 2 => [ 1 => 'Thus the heavens and the earth were completed in all their vast array.', // ... ], // ... ], ];
您的圣经文本可能有多个部分。在这种情况下,经文文本不是string
,而是一个字符串数组(array<string>
)。
<?php // book file example: 74-2es.php for VUL return [ 'id' => '2ES', 'abbreviation' => 'IV Esr', 'name' => 'LIBER EZRAE IIII', 'name_long' => 'LIBER EZRAE QUARTUS', 'chapters' => [ // ... 7 => [ // ... 35 => 'et opus subsequetur et merces ostendetur, et iustitiae vigilabunt et iniustitiae non dormibunt.', 36 => [ // verse 36 is not a string, but an array of strings 'a' => 'Et apparebit lacus tormenti', 'b' => 'et contra illum erit locus requietionis, et clibanus gehennae ostendetur et contra eam iucunditatis paradisus.', ], 37 => 'Et dicet tunc Altissimus ad excitatas gentes: Videte et intellegite quem negastis vel cui non servistis vel cuius diligentias sprevistis.', // ... ], // ... ], ]
默认情况下,这些部分合并为单个经文字符串。您可以通过Verse->getText()
的参数单独访问这些部分。
有关工作示例,请参阅tests/data/tes/0-gen.php。
许可
Bible Text Provider采用MIT许可证。有关详细信息,请参阅LICENSE文件。