GithubHelp home page GithubHelp logo

liberu-genealogy / php-gedcom Goto Github PK

View Code? Open in Web Editor NEW
74.0 4.0 41.0 1.15 MB

Gedcom reading and writing for PHP 8.3

Home Page: https://www.liberu.co.uk

License: MIT License

PHP 100.00%
gedcom gedcom-parser gedcom-parsing php php8 laravel laravel10

php-gedcom's Introduction

php-gedcom

Latest Stable Version Tests

Requirements

  • php-gedcom 1.0+ requires PHP 8.3 (or later).

Installation

There are two ways of installing php-gedcom.

Composer

To install php-gedcom in your project using composer, simply add the following require line to your project's composer.json file:

{
    "require": {
        "liberu-genealogy/php-gedcom": "2.0.*"
    }
}

Download and __autoload

If you are not using composer, you can download an archive of the source from GitHub and extract it into your project. You'll need to setup an autoloader for the files, unless you go through the painstaking process if requiring all the needed files one-by-one. Something like the following should suffice:

spl_autoload_register(function ($class) {
    $pathToGedcom = __DIR__ . '/library/'; // TODO FIXME

    if (!substr(ltrim($class, '\\'), 0, 7) == 'Gedcom\\') {
        return;
    }

    $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
    if (file_exists($pathToGedcom . $class)) {
        require_once($pathToGedcom . $class);
    }
});

Usage

To parse a GEDCOM file and load it into a collection of PHP Objects, simply instantiate a new Parser object and pass it the file name to parse. The resulting Gedcom object will contain all the information stored within the supplied GEDCOM file:

$parser = new \Gedcom\Parser();
$gedcom = $parser->parse('tmp.ged');

foreach ($gedcom->getIndi() as $individual) {
    $names = $individual->getName();
    if (!empty($names)) {
        $name = reset($names); // Get the first name object from the array
        echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL;
    }
}

Contributing

Pull requests are welcome, as are issues.

License

MIT License (see License.md). This means you must retain the copyright and permission notice is all copies, or substantial portions of this software.

Contributors

php-gedcom's People

Contributors

albarin avatar curtisdelicata avatar dench0 avatar heru0502 avatar joshkisb avatar juliengeneanet avatar juliolopez78 avatar jyyblue avatar litui avatar mrkrstphr avatar oguz463 avatar skypal avatar stuporglue avatar sweep-ai[bot] avatar tlesseli avatar vfftech avatar webstar1027 avatar workingdevel avatar xeanu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php-gedcom's Issues

Sweep: improve codebase for modularization and efficiency

Checklist
  • Create src/Parser/Interfaces/ParserInterface.php8d25f04 Edit
  • Running GitHub Actions for src/Parser/Interfaces/ParserInterface.phpEdit
  • Create src/Models/RecordInterface.php4de8a74 Edit
  • Running GitHub Actions for src/Models/RecordInterface.phpEdit
  • Modify src/Parser.php87c4d46 Edit
  • Running GitHub Actions for src/Parser.phpEdit
  • Modify src/Record.phpdd9bc65 Edit
  • Running GitHub Actions for src/Record.phpEdit
  • Modify src/Writer/Sour.phpcfff69e Edit
  • Running GitHub Actions for src/Writer/Sour.phpEdit
  • Create src/Utils/DataOptimizer.php25e65fb Edit
  • Running GitHub Actions for src/Utils/DataOptimizer.phpEdit

Sweep: bug duplicate issue

Details

The DEST Tag is an optional part of the HEAD tag.
The DEST tag itself has no value, only sub-tags.
THE DEST tag is very much like the SOUR tag, the mandatory part of the HEAD tag.

The error is thrown in \vendor\liberu-genealogy\php-gedcom\src\Parser\Head.php in line 62:

case 'DEST':
    $head->setDest(trim((string) $record[2]));
    break;

Handling the DEST tag should be like handling the SOUR tag.

case 'DEST':
    $dest= \Gedcom\Parser\Head\Dest::parse($parser);
    $head->setDest($dest);
    break;

The files for handling the DEST sub-tags and their class files are to be implemented.

Parsing a DEST tag generates an error : Undefined array key 2.

The DEST Tag is an optional part of the HEAD tag.
The DEST tag itself has no value, only sub-tags.
THE DEST tag is very much like the SOUR tag, the mandatory part of the HEAD tag.

The error is thrown in \vendor\liberu-genealogy\php-gedcom\src\Parser\Head.php in line 62:

case 'DEST':
    $head->setDest(trim((string) $record[2]));
    break;

Handling the DEST tag should be like handling the SOUR tag.

case 'DEST':
    $dest= \Gedcom\Parser\Head\Dest::parse($parser);
    $head->setDest($dest);
    break;

The files for handling the DEST sub-tags and their class files are to be implemented.

Multiple Events of Same Type

When a record, say an INDI record, contains multiple events of the same type, say CENS, only the last occurrence of the event is retained. INDI->getEven('CENS)' should return an array with all of the census events attached to the individual not just the last one encounterd.

Checklist
  • Create src/Gedcom/Record/Indi.php83b621d Edit
  • Running GitHub Actions for src/Gedcom/Record/Indi.phpEdit
  • Modify src/Gedcom.php ! No changes made Edit
  • Running GitHub Actions for src/Gedcom.phpEdit
  • Modify src/Writer.php52a73cb Edit
  • Running GitHub Actions for src/Writer.phpEdit

Sweep: psr4

Details

Make use of php psr4 standard.

Checklist
  • Modify composer.json ! No changes made Edit
  • Running GitHub Actions for composer.jsonEdit
  • Create src/ExampleClass.php0285e5e Edit
  • Running GitHub Actions for src/ExampleClass.phpEdit

PSR-4 Error during composer install

Class Gedcom\Record\Indi located in ./vendor/liberu-genealogy/php-gedcom/src/Gedcom/Record/Indi.php does not comply with psr-4 autoloading standard. Skipping.

Your Example does not work

Hello team,
your example does not work

$parser = new \Gedcom\Parser();
$gedcom = $parser->parse('tmp.ged');

foreach ($gedcom->getIndi() as $individual) {
    echo $individual->getId() . ': ' . current($individual->getName())->getSurn() .
        ', ' . current($indi->$individual())->getGivn();
}

this is not a valid php code. Can you give a working example?

These lines are not executable in any PHP version:

echo $individual->getId() . ': ' . current($individual->getName())->getSurn() .
        ', ' . current($indi->$individual())->getGivn();

In my case the parser seems to work, but I can't access the decoded objects like name etc.

This part

current($individual->getName())->getSurn()

throws an exception

Call to a member function getSurn() on bool

Calling current in foreach should not make sense!

and this part

current($indi->$individual())->getGivn()

is not defined, because $indi is not defined and $indi->$individual() makes no sense.

Can you help with a few tips or provide a more detailed example?

Best regards
cmette

Checklist
  • Modify README.md8b60952 Edit
  • Running GitHub Actions for README.mdEdit

Missing DATA element

If a record has a DATA sub record like the following

1 BURI
2 PLAC Warwick, Lambton County, Ontario, CANADA
2 SOUR @s0002@
3 DATA
4 TEXT James Hawkins
5 CONT died May 16 1894
5 CONT aged 82 yrs

The DATA sub record doesn't seem to be parsed or there doesn't seem to be a way to retrieve it.

Checklist
  • Modify src/Record/Data.php ! No changes made Edit
  • Running GitHub Actions for src/Record/Data.phpEdit
  • Modify src/Parser.php479e5dc Edit
  • Running GitHub Actions for src/Parser.phpEdit

Sweep: write full tests

Write tests for the whole project using phpunit 11

Checklist
  • Modify composer.json80a68ac Edit
  • Running GitHub Actions for composer.jsonEdit
  • Create tests/library/Gedcom/GedcomTest.php2c63b69 Edit
  • Running GitHub Actions for tests/library/Gedcom/GedcomTest.phpEdit
  • Modify tests/library/Gedcom/ParserTest.phpb38ecd6 Edit
  • Running GitHub Actions for tests/library/Gedcom/ParserTest.phpEdit
  • Modify tests/phpunit.xml42c21bb Edit
  • Running GitHub Actions for tests/phpunit.xmlEdit

Sweep: psr4

Details

src\Gedcom\Record\Indi.php does not comply with psr-4 autoloading standard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.