Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Memos for Visual FoxPro #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Header/Writer/VisualFoxproHeaderWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ protected function writeRest(Header $header): void

parent::writeRest($header);

$this->fp->write(str_pad($header->backlist, 263));
$this->fp->write(str_pad($header->backlist, 263, chr(0)));
}
}
2 changes: 1 addition & 1 deletion src/Memo/Creator/AbstractMemoCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function getExtension(): string
public function createFile(): string
{
$pi = pathinfo($this->table->filepath);
$memoFilepath = sprintf('%s/%s.%s', $pi['dirname'], $pi['filename'], self::getExtension());
$memoFilepath = sprintf('%s/%s.%s', $pi['dirname'], $pi['filename'], $this->getExtension());

$stream = Stream::createFromFile($memoFilepath, 'wb+');
$this->writeHeader($stream);
Expand Down
26 changes: 26 additions & 0 deletions src/Memo/Creator/FoxProMemoCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace XBase\Memo\Creator;

use XBase\Stream\Stream;

class FoxProMemoCreator extends AbstractMemoCreator
{
public static function getExtension(): string
{
return 'fpt';
}

protected function writeHeader(Stream $stream): void
{
$stream->write(pack('N', 8)); //next block

$stream->seek(4);
$stream->write(str_pad('', 2, chr(0))); //reserved

$stream->seek(6);
$stream->write(pack('n', 64)); //Block size. 8 * 64 == 512, which will start records after the header
}
}
2 changes: 2 additions & 0 deletions src/Memo/Creator/MemoCreatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static function create(Table $table)
case TableType::DBASE_7_MEMO:
return new DBase7MemoCreator($table);
//todo foxpro
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we delete this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The todo? That I'm not sure, actually. I don't know anything about the other FoxPro versions and I've found that documentation is a bit scarce. I'm not sure if my changes here will work properly for the other versions :/

case TableType::VISUAL_FOXPRO:
return new FoxProMemoCreator($table);
default:
throw new \Exception('Memo creator not realized for table version '.$table->getVersion());
}
Expand Down
1 change: 1 addition & 0 deletions src/Memo/MemoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use XBase\DataConverter\Encoder\EncoderInterface;
use XBase\Enum\TableType;
use XBase\Table\Table;
use XBase\Memo\Creator\MemoCreatorFactory;

class MemoFactory
{
Expand Down