-
-
Notifications
You must be signed in to change notification settings - Fork 17
Proj 16 mail namespace decoupling #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6956c5
feat(mail): decouple canonical runtime from Zend shim namespace
Wachhund ba20541
fix(db): add idempotent legacy ip_addr schema repair migration
Wachhund 5e55ed0
fix(db): validate identifiers in schema repair migration
Wachhund e3f45df
fix(review): address copilot feedback for PROJ-16
Wachhund 4e67e11
fix(review): address remaining copilot comments
Wachhund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
82 changes: 82 additions & 0 deletions
82
db/migrate/20260218101500_ensure_legacy_ip_addr_columns_exist.php
This file contains hidden or 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,82 @@ | ||
| <?php | ||
| class EnsureLegacyIpAddrColumnsExist extends Rails\ActiveRecord\Migration\Base | ||
| { | ||
| public function up() | ||
| { | ||
| $targets = [ | ||
| ['table' => 'dmails', 'column' => 'ip_addr', 'limit' => 46], | ||
| ['table' => 'forum_posts', 'column' => 'ip_addr', 'limit' => 46], | ||
| ['table' => 'forum_posts', 'column' => 'updater_ip_addr', 'limit' => 46], | ||
| ['table' => 'comments', 'column' => 'updater_ip_addr', 'limit' => 46], | ||
| ]; | ||
|
|
||
| foreach ($targets as $target) { | ||
| $this->ensureNullableVarcharColumn($target['table'], $target['column'], $target['limit']); | ||
| } | ||
| } | ||
|
|
||
| private function ensureNullableVarcharColumn($tableName, $columnName, $limit) | ||
| { | ||
| if (!$this->tableExists($tableName)) { | ||
| return; | ||
| } | ||
|
|
||
| $metadata = $this->fetchColumnMetadata($tableName, $columnName); | ||
| if (!$metadata) { | ||
| $this->execute( | ||
| sprintf( | ||
| "ALTER TABLE `%s` ADD `%s` VARCHAR(%d) NULL", | ||
| $this->quoteIdentifier($tableName), | ||
| $this->quoteIdentifier($columnName), | ||
| (int)$limit | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| if ($this->columnMatchesExpected($metadata, $limit)) { | ||
| return; | ||
| } | ||
|
|
||
| $this->execute( | ||
| sprintf( | ||
| "ALTER TABLE `%s` MODIFY `%s` VARCHAR(%d) NULL", | ||
| $this->quoteIdentifier($tableName), | ||
| $this->quoteIdentifier($columnName), | ||
| (int)$limit | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| private function fetchColumnMetadata($tableName, $columnName) | ||
| { | ||
| $stmt = $this->connection->executeSql( | ||
| "SELECT COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ? LIMIT 1", | ||
| $tableName, | ||
| $columnName | ||
| ); | ||
|
|
||
| $row = $stmt->fetch(\PDO::FETCH_ASSOC); | ||
| return $row ?: null; | ||
| } | ||
|
|
||
| private function columnMatchesExpected(array $metadata, $limit) | ||
| { | ||
| $columnType = strtolower((string)$metadata['COLUMN_TYPE']); | ||
| $length = (int)$metadata['CHARACTER_MAXIMUM_LENGTH']; | ||
| $isNullable = strtoupper((string)$metadata['IS_NULLABLE']) === 'YES'; | ||
|
|
||
| return strpos($columnType, 'varchar(') === 0 | ||
| && $length === (int)$limit | ||
| && $isNullable; | ||
| } | ||
|
|
||
| private function quoteIdentifier($identifier) | ||
| { | ||
| if (!preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $identifier)) { | ||
| throw new \InvalidArgumentException('Invalid SQL identifier: ' . $identifier); | ||
| } | ||
|
|
||
| return str_replace('`', '``', $identifier); | ||
| } | ||
| } |
This file contains hidden or 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,35 @@ | ||
| <?php | ||
|
|
||
| namespace MyImouto\Mail; | ||
|
|
||
| class Address | ||
| { | ||
| private $email = ''; | ||
| private $name = ''; | ||
|
|
||
| public function __construct($email, $name = '') | ||
| { | ||
| $email = trim((string)$email); | ||
| $name = trim((string)$name); | ||
|
|
||
| if ($email === '') { | ||
| throw new \InvalidArgumentException('Email cannot be empty'); | ||
| } | ||
| if (strpos($email, "\r") !== false || strpos($email, "\n") !== false) { | ||
| throw new \InvalidArgumentException('Email contains invalid characters'); | ||
| } | ||
|
|
||
| $this->email = $email; | ||
| $this->name = $name; | ||
| } | ||
|
|
||
| public function getEmail() | ||
| { | ||
| return $this->email; | ||
| } | ||
|
|
||
| public function getName() | ||
| { | ||
| return $this->name; | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| <?php | ||
|
|
||
| namespace MyImouto\Mail\Header; | ||
|
|
||
| class ContentType | ||
| { | ||
| private $type = 'text/plain'; | ||
|
|
||
| public function __construct($type = 'text/plain') | ||
| { | ||
| $this->setType($type); | ||
| } | ||
|
|
||
| public function setType($type) | ||
| { | ||
| $type = trim((string)$type); | ||
| if ($type === '') { | ||
| $type = 'text/plain'; | ||
| } | ||
|
|
||
| $this->type = $type; | ||
| return $this; | ||
| } | ||
|
|
||
| public function getType() | ||
| { | ||
| return $this->type; | ||
| } | ||
| } |
This file contains hidden or 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,31 @@ | ||
| <?php | ||
|
|
||
| namespace MyImouto\Mail\Header; | ||
|
|
||
| class GenericHeader | ||
| { | ||
| private $name = ''; | ||
| private $value = ''; | ||
|
|
||
| public function __construct($name, $value = '') | ||
| { | ||
| $this->name = strtolower(trim((string)$name)); | ||
| $this->setFieldValue($value); | ||
| } | ||
|
|
||
| public function setFieldValue($value) | ||
| { | ||
| $this->value = trim((string)$value); | ||
| return $this; | ||
| } | ||
|
|
||
| public function getFieldValue() | ||
| { | ||
| return $this->value; | ||
| } | ||
|
|
||
| public function getFieldName() | ||
| { | ||
| return $this->name; | ||
| } | ||
| } |
This file contains hidden or 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,50 @@ | ||
| <?php | ||
|
|
||
| namespace MyImouto\Mail; | ||
|
|
||
| use MyImouto\Mail\Header\ContentType; | ||
| use MyImouto\Mail\Header\GenericHeader; | ||
|
|
||
| class Headers | ||
| { | ||
| private $headers = []; | ||
|
|
||
| public function get($name) | ||
| { | ||
| $key = strtolower(trim((string)$name)); | ||
| if ($key === '') { | ||
| throw new \InvalidArgumentException('Header name cannot be empty'); | ||
| } | ||
|
|
||
| if (!isset($this->headers[$key])) { | ||
| $this->headers[$key] = $this->createHeader($key); | ||
| } | ||
|
|
||
| return $this->headers[$key]; | ||
| } | ||
|
|
||
| public function set($name, $header) | ||
| { | ||
| $key = strtolower(trim((string)$name)); | ||
| if ($key === '') { | ||
| throw new \InvalidArgumentException('Header name cannot be empty'); | ||
| } | ||
|
|
||
| $this->headers[$key] = $header; | ||
| return $this; | ||
| } | ||
|
|
||
| public function toArray() | ||
| { | ||
| return $this->headers; | ||
| } | ||
|
|
||
| private function createHeader($name) | ||
| { | ||
| if ($name === 'content-type') { | ||
| return new ContentType(); | ||
| } | ||
|
|
||
| return new GenericHeader($name); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.