Repository navigation
ScripturNum ScripturNum
The ScripturNum class, which represents a single continuous passage.
- Class name: ScripturNum
- Namespace: \ScripturNum
const BOOK_MASK = 4278190080
const START_MASK = 16773120
const END_MASK = 4095
const BARE_BOOKS_NONE = 'none'
const BARE_BOOKS_UNCOMMON = 'uncommon'
const BARE_BOOKS_ALL = 'all'
const UNREADABLE_IGNORE = 'ignore'
const UNREADABLE_REPORT = 'report'
protected mixed int
- Visibility: protected
protected mixed book
- Visibility: protected
protected mixed startCh
- Visibility: protected
protected mixed startV
- Visibility: protected
protected mixed endCh
- Visibility: protected
protected mixed endV
- Visibility: protected
protected mixed bibleClass = \ScripturNum\Bible::class
- Visibility: protected
protected mixed stringSettings = ['abbrev' => ['space' => '', 'cvsep' => '.', 'range' => '-', 'names' => 1, 'plurl' => false], 'long' => ['space' => ' ', 'cvsep' => ':', 'range' => '-', 'names' => 0, 'plurl' => true]]
- Visibility: protected
mixed ScripturNum\ScripturNum::__construct(int|string intOrString)
ScripturNum constructor.
- Visibility: public
- intOrString int|string - ScripturNum int or a human-readable string.
- mixed
int ScripturNum\ScripturNum::__get(mixed what)
- Visibility: public
- what mixed
- int -
mixed ScripturNum\ScripturNum::startInt()
- Visibility: protected
- mixed
mixed ScripturNum\ScripturNum::endInt()
- Visibility: protected
- mixed
void ScripturNum\ScripturNum::setStringSettings(mixed key, array settings)
Update string settings.
- Visibility: public
- This method is static.
- key mixed* settings array
int ScripturNum\ScripturNum::getInt()
Get the ScripturNum integer.
- Visibility: public
- int - The ScripturNum integer
string ScripturNum\ScripturNum::__toString()
Generic toString. Uses the long form.
- Visibility: public
- string -
string ScripturNum\ScripturNum::getAbbrev()
Get a human-readable abbreviation for the passage. By default, these are meant for usage in short links.
- Visibility: public
- string - An abbreviation
string ScripturNum\ScripturNum::getLongString()
Get a human-readable name of the passage. By default, these are meant for humans to read.
- Visibility: public
- string - The name of the passage, as one might pronounce it.
mixed ScripturNum\ScripturNum::toString(mixed options)
Get a string. Publicly-accessible.
- Visibility: public
- options mixed
- mixed
string ScripturNum\ScripturNum::getStringWithSettings(string|array options)
Returns a human-readable string with the settings defined in a given set of settings.
- Visibility: protected
- options string|array - The setting set to use, or an array of options.
- string - The human-intelligible string.
\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::remove(mixed passageToRemove)
Remove a passage from this passage, returning an array of ScripturNum objects that represent the difference.
- Visibility: public
- passageToRemove mixed
- \ScripturNum\ScripturNumArray -
bool ScripturNum\ScripturNum::isWholeChapters()
Returns true if the passage is an entire chapter.
- Visibility: public
- bool -
static ScripturNum\ScripturNum::getWholeChapters()
Returns a ScripturNum for the current range, expanded to the whole chapter.
- Visibility: public
- static -
static ScripturNum\ScripturNum::getNextChapter()
Returns a ScripturNum for the chapter after the current highest chapter.
- Visibility: public
- static -
static ScripturNum\ScripturNum::getPrevChapter()
Returns a ScripturNum for the chapter prior to the current lowest chapter.
- Visibility: public
- static -
\ScripturNum\ScripturNum ScripturNum\ScripturNum::getWholeBook()
Get a ScripturNum for the whole book of the Bible that this passage is in, or this one if already a whole book.
- Visibility: public
- \ScripturNum\ScripturNum -
bool ScripturNum\ScripturNum::isWholeBook()
Returns true if the passage is a whole book.
- Visibility: public
- bool -
bool ScripturNum\ScripturNum::isSingleVerse()
Returns true if the passage is just a single verse.
- Visibility: public
- bool -
bool ScripturNum\ScripturNum::bookHasSingleChapter()
Returns true if the book only has one chapter (e.g. Jude)
- Visibility: public
- bool -
int ScripturNum\ScripturNum::bookNameToBookNum(mixed bookName)
- Visibility: protected
- This method is static.
- bookName mixed
- int -
string[][] ScripturNum\ScripturNum::getBookNames()
- Visibility: protected
- This method is static.
- string[][] -
string[] ScripturNum\ScripturNum::getCommonTerms()
- Visibility: protected
- This method is static.
- string[] -
string[] ScripturNum\ScripturNum::getConjunctions()
- Visibility: protected
- This method is static.
- string[] -
string ScripturNum\ScripturNum::pluralizeBookName(string bookNameSingular)
- Visibility: protected
- This method is static.
- bookNameSingular string
- string -
\ScripturNum\ScripturNum ScripturNum\ScripturNum::newFromParsed(string bookStr, ?int startCh, ?int startV, ?int endCh, ?int endV)
- Visibility: public
- This method is static.
- bookStr string* startCh ?int* startV ?int* endCh ?int* endV ?int
- \ScripturNum\ScripturNum -
\ScripturNum\ScripturNum ScripturNum\ScripturNum::newFromInts(int book, int startCh, int|null startV, int|null endCh, int|null endV)
- Visibility: public
- This method is static.
- book int - The book of the Bible the range is within. 1-rel.
- startCh int - The chapter of the start of the range. 1-rel.
- startV int|null - The verse of the start of the range. 1-rel. Defaults to 1.
- endCh int|null - The end chapter of the range. If null or not provided, assumed to be the same as the start chapter.
- endV int|null - The end verse of the range. If null or not provided, assumed to be the end of the chapter.
- \ScripturNum\ScripturNum - The ScripturNum object that represents this range of scripture.
void ScripturNum\ScripturNum::report(\ScripturNum\ScripturNumException e, bool|array|null exceptions, string|null input)
Either throws the exception, or--if an array was provided to collect them--adds it to the array. If the exception doesn't already know what text it couldn't read, it is told.
- Visibility: protected
- This method is static.
- e ScripturNum\ScripturNumException* exceptions bool|array|null - If an array, the exception is appended to it. Otherwise, it is thrown.
- input string|null - The text that couldn't be read.
int ScripturNum\ScripturNum::stringToInt(string string)
Takes a string that represents a single passage and returns it as an int.
- Visibility: public
- This method is static.
- string string - A human-readable scripture reference that should be converted to an int.
- int - The int.
int[] ScripturNum\ScripturNum::stringToInts(string string, bool|array exceptions)
Takes a reference string for a single book and returns a plurality of ints for corresponding passages. This should only be passed values that are known to be references, not just any text.
Replacement: use parseString() with every book name allowed and unreadable text reported:
$passages = ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_ALL, ScripturNum::UNREADABLE_REPORT, $exceptions);
The differences are that the replacement:
- Returns a ScripturNumArray, not an array of ints. Call getInt() on each passage to get the ints.
- Puts the passages in the order of the Bible, and combines any that overlap or are adjacent (so "John 3:16, 17" is one passage, not two), whereas this method keeps the passages in the order written.
- Reads references to more than one book (e.g. "John 3:16; Romans 8"), which this method does not.
Passing an array for $exceptions has the same effect in both. Without one, the first exception is thrown.
- Visibility: public
- This method is static.
- string string - A human-readable scripture reference that should be converted to one or more ints. Allows for commas and semicolons.
- exceptions bool|array - Pass an array to this parameter, and it will be populated with any exceptions that occur. By passing an array, this will not throw the exception, and by not throwing the exception, execution continues and you may be apprised of multiple errors that may exist.
- int[] - The ints.
string ScripturNum\ScripturNum::normalize(string string)
Standardizes the punctuation and whitespace of reference text, so that conjunctions, "through", and the like are expressed as the separators that the parser understands.
- Visibility: protected
- This method is static.
- string string
- string -
string[][] ScripturNum\ScripturNum::punctuationPatterns()
The words and symbols (the language's conjunctions, and the various dashes) that stand for separators, as regular expressions, and the kinds of space. Words must stand alone, so "and" within "Sandy" is not a conjunction, and neither is "y" within the Spanish "Reyes", or next to a digit. Anything that isn't a letter or digit is a break. Case doesn't matter.
- Visibility: protected
- This method is static.
- string[][] - Each is [the regular expression, what it is replaced with by normalize(), what it is replaced with (before being padded to its original length) by maskPunctuation()].
int[] ScripturNum\ScripturNum::parseSpan(string string, bool|array exceptions)
Parses a single span: one book's name, followed by any number of references within that book.
- Visibility: protected
- This method is static.
- string string - The span, e.g. "John 3:16, 18; 4:2"
- exceptions bool|array - Pass an array to have exceptions collected, rather than thrown.
- int[] -
void ScripturNum\ScripturNum::singleChapterBookNumbersAreVerses(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)
In a book of only one chapter (Obadiah, Philemon, 2 John, 3 John, and Jude), a number that is written alone is a verse, and not the chapter. So "Jude 1" is verse 1, as "Jude 5" is verse 5, and as "Jude 1:1" is. This makes what getAbbrev() writes for the first verse (such as "Ob1") readable. A book's whole is written as its name.
This is for numbers that were read from a string. (Numbers larger than 1 are made into verses by validateRefNums(), which is also used for numbers that weren't.)
- Visibility: protected
- This method is static.
- book int - The book number, starting from 1.
- startCh ?int* startV ?int* endCh ?int* endV ?int
void ScripturNum\ScripturNum::validateRefNums(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)
Validate that reference numbers can be matched to verses that exist.
- Visibility: protected
- This method is static.
- book int* startCh ?int* startV ?int* endCh ?int* endV ?int
int ScripturNum\ScripturNum::refNumsToInt(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)
Take reference indexes and convert them to the ScripturNum int. Assumes numbers are already validated by either safely existing or being validated against self::validateRefNums()
- Visibility: protected
- This method is static.
- book int* startCh ?int* startV ?int* endCh ?int* endV ?int
- int -
mixed ScripturNum\ScripturNum::refNumStringToRefNums(string string, mixed chapterStart, mixed verseStart, mixed chapterEnd, mixed verseEnd, bool useHints)
This function reads through a single ref string (e.g. 3:5-6:9) one character at a time to parse it into a known reference.
- Visibility: protected
- This method is static.
- string string - The string to parse.
- chapterStart mixed* verseStart mixed* chapterEnd mixed* verseEnd mixed* useHints bool - If true, will consider the values provided to the chapter and verse parameters in parsing the string. Default false.
- mixed
mixed ScripturNum\ScripturNum::intToRefNums(int int, int book, int chapterStart, int verseStart, int chapterEnd, int verseEnd)
Converts a ScripturNum int into reference numbers.
- Visibility: protected
- This method is static.
- int int - The ScripturNum integer
- book int - The book number
- chapterStart int - The first Chapter
- verseStart int - The first Verse
- chapterEnd int - The last Chapter
- verseEnd int - The last Verse
- mixed
mixed ScripturNum\ScripturNum::intToConcats(int int, string|int concatStart, string|int concatEnd)
Convert a ScrupturNum int into a concatenated number. (Concatenated numbers are often used for text libraries.)
- Visibility: public
- This method is static.
- int int - The int representing the full passage
- concatStart string|int - The concatenated "number" possibly larger than an int representing the start of the passage.
- concatEnd string|int - The concatenated "number" possibly larger than an int representing the end of the passage.
- mixed
mixed ScripturNum\ScripturNum::bkIndexToSingleRef(int book, int index, int chapter, int verse)
Parse a book index number into a chapter and verse.
- Visibility: protected
- This method is static.
- book int - Book number
- index int - Verse Index Number
- chapter int - Chapter
- verse int - Verse
- mixed
\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::extractFromString(string string, bool excludeAllBookOnlyRefs, null exceptions)
Given a string with any kind of text content, this method will search for any human-readable scripture references and try to parse them into discrete passages. Returns a ScripturNumArray.
Replacement: use parseString(), which returns the same thing and takes the same $exceptions. The $excludeAllBookOnlyRefs flag becomes the $bareBookNames option:
// extractFromString($string, false, $exceptions) is the same as:
ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_UNCOMMON, ScripturNum::UNREADABLE_IGNORE, $exceptions);
// extractFromString($string, true, $exceptions) is the same as:
ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_NONE, ScripturNum::UNREADABLE_IGNORE, $exceptions);
The options in the first example are the defaults, so if $exceptions isn't needed, it is simply parseString($string).
- Visibility: public
- This method is static.
- string string* excludeAllBookOnlyRefs bool* exceptions null - To have exceptions collected rather than thrown, pass an array to this parameter.
- \ScripturNum\ScripturNumArray -
\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::parseString(string string, string bareBookNames, string unreadableText, bool|array exceptions)
Finds and parses the scripture references in a string. The string may be prose with references in it, or text that is known to be a list of references, such as what a person types into a "scripture" field. The options say which of these to expect.
Prose (the defaults): references are found wherever they appear, and everything else is skipped.
ScripturNum::parseString('Read John 3:16 and Romans 8 today.'); // John 3:16, Romans 8
A list of references: every reference that can be read is returned, and every item that can't is reported with its text, so that a person can be told what wasn't understood. Book names are always allowed on their own, since there's no prose to protect. Each item that can't be read is reported separately.
$exceptions = [];
$passages = ScripturNum::parseString('Romans 8; Hezekiah 1; Acts 2:38',
ScripturNum::BARE_BOOKS_ALL,
ScripturNum::UNREADABLE_REPORT,
$exceptions);
// $passages has Acts 2:38 and Romans 8. $exceptions has one exception, and $exceptions[0]->getInput() is
// "Hezekiah 1".
Items can be separated by semicolons, commas, line breaks, and the language's conjunction for "and". A separator followed by chapters or verses continues the same book ("John 3:16; 4:2" is John 3:16 and John 4:2), and one followed by a book name starts a new passage. Empty items are ignored.
A chapter and a verse can be separated by either ":" or "." ("John 3:16" and "John 3.16" are the same), so that the short form that getAbbrev() writes ("Jn3.16") can be read. In a book of one chapter, a number that is alone is a verse ("Jude 5", and "Ob1" for Obadiah 1:1).
Book names, common terms and conjunctions are those of the class that this is called on, so a class with another language's Bible reads that language.
The passages are returned in a ScripturNumArray, which puts them in the order of the Bible and combines any that overlap or are adjacent. Each is an instance of the class this was called on.
References that are found but are not valid (e.g. John 3:99) are always reported, whatever $unreadableText is.
- Visibility: public
- This method is static.
- string string - The text to read.
- bareBookNames string - Whether a book name with nothing after it counts as a reference to the whole book. One of:
- BARE_BOOKS_NONE: never. "John 3" is found, but "John" is not.
- BARE_BOOKS_UNCOMMON: only if the name isn't a common word, as listed by Bible::getCommonTerms(). "Genesis" is found, but "Mark" and "Job" are not, which keeps "mark my words" from being read as the book of Mark. This is the default.
- BARE_BOOKS_ALL: always, even for common words. A name that is part of a longer reference ("John 3:16") is not also returned as the whole book.
- unreadableText string - What to do with text that isn't a reference. One of:
- UNREADABLE_IGNORE: skip it. This is the default.
- UNREADABLE_REPORT: report it as an exception, with the text available from the exception's getInput(). Each item (text between semicolons, commas, ampersands, line breaks and conjunctions) is reported separately. Separators and conjunctions don't count as text.
- exceptions bool|array - To have exceptions collected rather than thrown, pass an array. Otherwise, the first exception is thrown.
- \ScripturNum\ScripturNumArray -
string ScripturNum\ScripturNum::maskPunctuation(string string)
Replaces conjunctions, dashes, and the like with the separator they stand for, so that they can be recognized when scanning. The length in bytes is preserved, so that offsets in the result are also offsets in the original.
- Visibility: protected
- This method is static.
- string string
- string -
array[] ScripturNum\ScripturNum::scan(string masked, string bareBookNames)
Finds the spans of a string that look like references. Either a ":" or a "." can be between a chapter and a verse, so that what getAbbrev() writes ("Jn3.16") is found. (A "." counts only if a digit follows it right away, so that the period that ends a sentence about "Psalm 23." is not a separator.)
- Visibility: protected
- This method is static.
- masked string - The string, as processed by maskPunctuation().
- bareBookNames string - One of the BARE_BOOKS_* constants.
- array[] - Each is [the matched text, its offset], in the order found. Matches that overlap an earlier one are left out.
string[] ScripturNum\ScripturNum::unreadableItems(string original, string masked, int from, int to)
Gets the items in part of the original string that are neither references nor mere separators. Items are separated by semicolons, commas, ampersands, line breaks, and conjunctions.
- Visibility: protected
- This method is static.
- original string* masked string - The string, as processed by maskPunctuation().
- from int - Offset of the start of the part to check.
- to int - Offset of the end of the part to check.
- string[] - The original text of each item, without surrounding separators. Empty if there is nothing but separators.
bool ScripturNum\ScripturNum::isWithinInt(int largerPassage)
Test whether a given passage is within a given larger passage. Will also return true if they are the same.
- Visibility: public
- largerPassage int
- bool -
bool ScripturNum\ScripturNum::isWithin(\ScripturNum\ScripturNum largerPassage)
Test whether a given passage is within a given larger passage. Will also return true if they are the same.
- Visibility: public
- largerPassage ScripturNum\ScripturNum
- bool -
bool ScripturNum\ScripturNum::overlapsWithInt(int otherPassage)
Test whether a given passage has any commonality with another passage.
- Visibility: public
- otherPassage int
- bool -
bool ScripturNum\ScripturNum::overlapsWith(\ScripturNum\ScripturNum otherPassage)
Test whether a given passage has any commonality with another passage.
- Visibility: public
- otherPassage ScripturNum\ScripturNum
- bool -
bool ScripturNum\ScripturNum::overlapsOrAdjacentInt(int otherPassage)
Test whether a given passage has any commonality with another passage, or is adjacent to it.
- Visibility: public
- otherPassage int
- bool -
bool ScripturNum\ScripturNum::overlapsOrAdjacent(\ScripturNum\ScripturNum otherPassage)
Test whether a given passage has any commonality with another passage, or is adjacent to it.
- Visibility: public
- otherPassage ScripturNum\ScripturNum
- bool -
int ScripturNum\ScripturNum::combineWithInt(int otherPassage)
Combines two adjacent or overlapping passages into one int.
- Visibility: public
- otherPassage int
- int -
\ScripturNum\ScripturNum ScripturNum\ScripturNum::combineWith(\ScripturNum\ScripturNum otherPassage)
Combines two adjacent or overlapping passages into one ScripturNum.
- Visibility: public
- otherPassage ScripturNum\ScripturNum
- \ScripturNum\ScripturNum -
bool ScripturNum\ScripturNum::containsInt(int smallerPassage)
Test whether a given passage contains a given smaller passage. Will also return true if they are the same.
- Visibility: public
- smallerPassage int
- bool -
bool ScripturNum\ScripturNum::contains(\ScripturNum\ScripturNum smallerPassage)
Test whether a given passage contains a given smaller passage. Will also return true if they are the same.
- Visibility: public
- smallerPassage ScripturNum\ScripturNum
- bool -
string ScripturNum\ScripturNum::toSqlExclusive(string columnRef)
Generate a query statement that can be used to search an int column in generic SQL for a passage that is entirely contained within the given ScripturNum.
- Visibility: public
- columnRef string - The name of the column or value to use in the query.
- string -
string ScripturNum\ScripturNum::toSqlExclusive3(string bookColumnRef, string startColumnRef, string endColumnRef)
Generate a query statement that can be used to search three numeric columns in generic SQL for a passage that is entirely contained within the given ScripturNum. The three columns should represent book, start index, and end index respectively.
- Visibility: public
- bookColumnRef string - The name of the column or value to use for the book index.
- startColumnRef string - The name of the column or value to use for the start index.
- endColumnRef string - The name of the column or value to use for the end index.
- string -
string ScripturNum\ScripturNum::toSqlInclusive(string columnRef)
Generate a query statement that can be used to search an int column in generic SQL for a passage that overlaps with the given ScripturNum.
- Visibility: public
- columnRef string - The name of the column or value to use in the query.
- string -
string ScripturNum\ScripturNum::toSqlInclusive3(string bookColumnRef, string startColumnRef, string endColumnRef)
Generate a query statement that can be used to search three numeric columns in generic SQL for a passage that overlaps with the given ScripturNum. The three columns should represent book, start index, and end index respectively.
- Visibility: public
- bookColumnRef string - The name of the column or value to use for the book index.
- startColumnRef string - The name of the column or value to use for the start index.
- endColumnRef string - The name of the column or value to use for the end index.
- string -
\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::getWholeBible()
Get a ScripturNumArray representing the whole Bible.
- Visibility: public
- This method is static.
- \ScripturNum\ScripturNumArray -
- ScripturNum