-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to specify fields in linked tables
- Loading branch information
1 parent
05c4e89
commit b0b2bc4
Showing
7 changed files
with
210 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Airmad | ||
* | ||
* An Airtable integration for Automad. | ||
* | ||
* @author Marc Anton Dahmen | ||
* @copyright Copyright (C) 2023 Marc Anton Dahmen - <https://marcdahmen.de> | ||
* @license MIT license | ||
*/ | ||
|
||
namespace Airmad; | ||
|
||
defined('AUTOMAD') or die('Direct access not permitted!'); | ||
|
||
class Debug { | ||
/** | ||
* The log entries array. | ||
*/ | ||
private static $entries = array(); | ||
|
||
/** | ||
* Get the log entries | ||
* | ||
* @return array | ||
*/ | ||
public static function get(): array { | ||
return self::$entries; | ||
} | ||
|
||
/** | ||
* Add an entry to the entries array. | ||
* | ||
* @param mixed $entry | ||
* @return void | ||
*/ | ||
public static function log(mixed $entry): void { | ||
$backtraceAll = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5); | ||
$ignoreFunctions = array('log', __NAMESPACE__ . '\{closure}'); | ||
|
||
$backtrace = array_filter($backtraceAll, function ($item) use ($ignoreFunctions) { | ||
return (isset($item['class'], $item['type'], $item['function']) && !in_array($item['function'], $ignoreFunctions)); | ||
}); | ||
|
||
if (count($backtrace) > 0) { | ||
// When the backtrace array got reduced to the actually relevant items in the backtrace, take the first element (the one calling Debug::log()). | ||
$backtrace = array_shift($backtrace); | ||
$src = basename(str_replace('\\', '/', $backtrace['class'] ?? '')) . ($backtrace['type'] ?? '') . $backtrace['function'] . '(): '; | ||
} else { | ||
$src = basename($backtraceAll[0]['file']); | ||
} | ||
|
||
self::$entries[] = array($src, $entry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Airmad | ||
* | ||
* An Airtable integration for Automad. | ||
* | ||
* @author Marc Anton Dahmen | ||
* @copyright Copyright (C) 2023 Marc Anton Dahmen - <https://marcdahmen.de> | ||
* @license MIT license | ||
*/ | ||
|
||
namespace Airmad; | ||
|
||
defined('AUTOMAD') or die('Direct access not permitted!'); | ||
|
||
class Table { | ||
/** | ||
* A list of fields that have to be included in the request. | ||
*/ | ||
public array $fields; | ||
|
||
/** | ||
* The table name to be requested. | ||
*/ | ||
public string $name; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param string $name | ||
* @param array $fields | ||
*/ | ||
public function __construct(string $name, array $fields) { | ||
$this->name = $name; | ||
$this->fields = $fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Airmad | ||
* | ||
* An Airtable integration for Automad. | ||
* | ||
* @author Marc Anton Dahmen | ||
* @copyright Copyright (C) 2023 Marc Anton Dahmen - <https://marcdahmen.de> | ||
* @license MIT license | ||
*/ | ||
|
||
namespace Airmad; | ||
|
||
defined('AUTOMAD') or die('Direct access not permitted!'); | ||
|
||
class TableLink { | ||
/** | ||
* A field that links to the table. | ||
*/ | ||
public string $field; | ||
|
||
/** | ||
* The table name to be requested. | ||
*/ | ||
public Table $Table; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param string $name | ||
* @param Table $Table | ||
*/ | ||
public function __construct(string $field, string $table, array $tableFields) { | ||
$this->field = $field; | ||
$this->Table = new Table($table, $tableFields); | ||
} | ||
|
||
/** | ||
* Parse a table link string. | ||
* | ||
* Possible link formats are: | ||
* Table | ||
* Table[Field1 Field2] | ||
* Field => Table | ||
* Field => Table[Field1 Field2] | ||
* | ||
* @param string $link | ||
* @return TableLink|null | ||
*/ | ||
public static function fromString(string $link): ?TableLink { | ||
$parts = preg_split('/\s*\=\>\s*/', $link); | ||
|
||
if (empty($parts)) { | ||
return null; | ||
} | ||
|
||
$field = trim(preg_replace('/\[[\w\s]+\]/is', '', $parts[0])); | ||
|
||
if (empty($parts[1])) { | ||
$tableAndFields = $parts[0]; | ||
} else { | ||
$tableAndFields = $parts[1]; | ||
} | ||
|
||
preg_match('/(?P<name>\w+)(?:\[(?P<fields>[\w\s]+)\])?/', $tableAndFields, $matches); | ||
|
||
if (!empty($matches) && !empty($matches['name'])) { | ||
$tableFields = array(); | ||
|
||
if (!empty($matches['fields'])) { | ||
$tableFields = preg_split('/\s+/', $matches['fields']); | ||
} | ||
|
||
return new TableLink($field, $matches['name'], $tableFields); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters