Skip to content

Commit

Permalink
Merge pull request #621 from octobercms/develop
Browse files Browse the repository at this point in the history
OC Release - v3.5
  • Loading branch information
daftspunk authored Sep 23, 2023
2 parents 42227b1 + 92b3601 commit e07c0bf
Show file tree
Hide file tree
Showing 37 changed files with 620 additions and 221 deletions.
2 changes: 1 addition & 1 deletion helpers/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*
* @see \Illuminate\Database\Schema\Builder
*/
class Schema extends Illuminate\Support\Facades\Schema {}
class Schema extends October\Rain\Support\Facades\Schema {}
2 changes: 1 addition & 1 deletion helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*
* @see \Illuminate\Routing\UrlGenerator
*/
class Url extends Illuminate\Support\Facades\URL {}
class Url extends October\Rain\Support\Facades\Url {}
2 changes: 1 addition & 1 deletion helpers/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*
* @see \October\Rain\Validation\Factory
*/
class Validator extends Illuminate\Support\Facades\Validator {}
class Validator extends October\Rain\Support\Facades\Validator {}
44 changes: 12 additions & 32 deletions src/Argon/Argon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,25 @@
use Carbon\Carbon as DateBase;

/**
* Argon is an umbrella class for Carbon
* Argon is an umbrella class for Carbon that automatically applies localizations
*
* @package october\argon
* @author Alexey Bobkov, Samuel Georges
*/
class Argon extends DateBase
{
/**
* @var string|callable|null formatFunction function to call instead of format
* format
*/
protected static $formatFunction = 'translatedFormat';

/**
* @var string|callable|null createFromFormatFunction function to call instead
* of createFromFormat
*/
protected static $createFromFormatFunction = 'createFromFormatWithCurrentLocale';

/**
* @var string|callable|null parseFunction function to call instead of parse.
*/
protected static $parseFunction = 'parseWithCurrentLocale';

/**
* parseWithCurrentLocale
*/
public static function parseWithCurrentLocale($time = null, $timezone = null)
public function format($format)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return parent::rawParse($time, $timezone);
return parent::translatedFormat($format);
}

/**
* createFromFormatWithCurrentLocale
* createFromFormat
*/
public static function createFromFormatWithCurrentLocale($format, $time = null, $timezone = null)
public static function createFromFormat($format, $time, $timezone = null)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
Expand All @@ -51,14 +31,14 @@ public static function createFromFormatWithCurrentLocale($format, $time = null,
}

/**
* getLanguageFromLocale gets the language portion of the locale.
* @param string $locale
* @return string
* parse
*/
public static function getLanguageFromLocale($locale)
public static function parse($time = null, $timezone = null)
{
$parts = explode('_', str_replace('-', '_', $locale));
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return $parts[0];
return parent::rawParse($time, $timezone);
}
}
21 changes: 15 additions & 6 deletions src/Argon/ArgonServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php namespace October\Rain\Argon;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterval;
use Carbon\CarbonPeriod;
use Illuminate\Support\DateFactory;
use October\Rain\Support\ServiceProvider;

/**
Expand All @@ -15,6 +20,7 @@ class ArgonServiceProvider extends ServiceProvider
*/
public function register()
{
DateFactory::useClass(\October\Rain\Argon\Argon::class);
}

/**
Expand All @@ -24,23 +30,26 @@ public function boot()
{
$locale = $this->app['config']->get('app.locale');

$this->setArgonLocale($locale);
$this->setCarbonLocale($locale);

$this->app['events']->listen('locale.changed', function ($locale) {
$this->setArgonLocale($locale);
$this->setCarbonLocale($locale);
});
}

/**
* setArgonLocale sets the locale using the correct load order.
* setCarbonLocale sets the locale using the correct load order.
*/
protected function setArgonLocale($locale)
protected function setCarbonLocale($locale)
{
Argon::setLocale($locale);
Carbon::setLocale($locale);
CarbonImmutable::setLocale($locale);
CarbonPeriod::setLocale($locale);
CarbonInterval::setLocale($locale);

$fallbackLocale = $this->getFallbackLocale($locale);
if ($locale !== $fallbackLocale) {
Argon::setFallbackLocale($fallbackLocale);
Carbon::setFallbackLocale($fallbackLocale);
}
}

Expand Down
50 changes: 50 additions & 0 deletions src/Composer/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ public function removePackages(array $packageNames)
$this->writePackages($requirements);
}

/**
* getPackageVersions returns version numbers for the specified packages
*/
public function getPackageVersions(array $packageNames): array
{
$result = [];
$packages = $this->listAllPackages();

foreach ($packageNames as $wantPackage) {
$wantPackageLower = mb_strtolower($wantPackage);

foreach ($packages as $package) {
if (!isset($package['name'])) {
continue;
}
if (mb_strtolower($package['name']) === $wantPackageLower) {
$result[$wantPackage] = $package['version'] ?? null;
}
}
}

return $result;
}

/**
* hasPackage returns true if the specified package is installed
*/
public function hasPackage($name): bool
{
$name = mb_strtolower($name);

return array_key_exists($name, $this->getPackageVersions([$name]));
}

/**
* listPackages returns a list of directly installed packages
*/
Expand Down Expand Up @@ -226,6 +260,22 @@ public function addAuthCredentials($hostname, $username, $password, $type = null
]);
}

/**
* getAuthCredentials returns auth credentials added to the config file
*/
public function getAuthCredentials($hostname, $type = null): ?array
{
if ($type === null) {
$type = 'http-basic';
}

$authFile = $this->getAuthPath();

$config = json_decode(file_get_contents($authFile), true);

return $config[$type][$hostname] ?? null;
}

/**
* makeComposer returns a new instance of composer
*/
Expand Down
107 changes: 56 additions & 51 deletions src/Database/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,134 +19,139 @@
use InvalidArgumentException;

/**
* HasRelationships concern for a model
* HasRelationships concern for a model, using a cleaner declaration of relationships.
*
* Uses a similar approach to the relation methods used by Eloquent, but as separate properties
* that make the class file less cluttered.
*
* It should be declared with keys as the relation name, and value being a mixed array.
* The relation type $morphTo does not include a class name as the first value.
*
* Example:
*
* class Order extends Model
* {
* protected $hasMany = [
* 'items' => Item::class
* ];
* }
*
* @package october\database
* @author Alexey Bobkov, Samuel Georges
*/
trait HasRelationships
{
/**
* Cleaner declaration of relationships.
* Uses a similar approach to the relation methods used by Eloquent, but as separate properties
* that make the class file less cluttered.
*
* It should be declared with keys as the relation name, and value being a mixed array.
* The relation type $morphTo does not include a class name as the first value.
* @var array hasOne related record, inverse of belongsTo.
*
* Example:
* class Order extends Model
* {
* protected $hasMany = [
* 'items' => 'Item'
* ];
* }
* protected $hasOne = [
* 'owner' => [User::class, 'key' => 'user_id']
* ];
*
* @var array
*/
public $hasMany = [];
public $hasOne = [];

/**
* protected $hasOne = [
* 'owner' => ['User', 'key' => 'user_id']
* ];
* @var array hasMany related records, inverse of belongsTo.
*
* @var array
* protected $hasMany = [
* 'items' => Item::class
* ];
*/
public $hasOne = [];
public $hasMany = [];

/**
* @var array belongsTo another record with a local key attribute
*
* protected $belongsTo = [
* 'parent' => ['Category', 'key' => 'parent_id']
* 'parent' => [Category::class, 'key' => 'parent_id']
* ];
*
* @var array
*/
public $belongsTo = [];

/**
* @var array belongsToMany to multiple records using a join table.
*
* protected $belongsToMany = [
* 'groups' => ['Group', 'table'=> 'join_groups_users']
* 'groups' => [Group::class, 'table'=> 'join_groups_users']
* ];
*
* @var array
*/
public $belongsToMany = [];

/**
* @var array morphTo another record using local key and type attributes
*
* protected $morphTo = [
* 'pictures' => []
* ];
*
* @var array
*/
public $morphTo = [];

/**
* @var array morphOne related record, inverse of morphTo.
*
* protected $morphOne = [
* 'log' => ['History', 'name' => 'user']
* 'log' => [History::class, 'name' => 'user']
* ];
*
* @var array
*/
public $morphOne = [];

/**
* @var array morphMany related records, inverse of morphTo.
*
* protected $morphMany = [
* 'log' => ['History', 'name' => 'user']
* 'log' => [History::class, 'name' => 'user']
* ];
*
* @var array
*/
public $morphMany = [];

/**
* @var array morphToMany to multiple records using a join table.
*
* protected $morphToMany = [
* 'tag' => ['Tag', 'table' => 'tagables', 'name' => 'tagable']
* 'tag' => [Tag::class, 'table' => 'tagables', 'name' => 'tagable']
* ];
*
* @var array
*/
public $morphToMany = [];

/**
* @var array
* @var array morphedByMany
*/
public $morphedByMany = [];

/**
* @var array attachOne file attachment.
*
* protected $attachOne = [
* 'picture' => ['October\Rain\Database\Attach\File', 'public' => false]
* 'picture' => [\October\Rain\Database\Attach\File::class, 'public' => false]
* ];
*
* @var array
*/
public $attachOne = [];

/**
* @var array attachMany file attachments.
*
* protected $attachMany = [
* 'pictures' => ['October\Rain\Database\Attach\File', 'name'=> 'imageable']
* 'pictures' => [\October\Rain\Database\Attach\File::class, 'name'=> 'imageable']
* ];
*
* @var array
*/
public $attachMany = [];

/**
* @var array hasManyThrough is related records through another record.
*
* protected $hasManyThrough = [
* 'posts' => ['Posts', 'through' => 'User']
* 'posts' => [Post::class, 'through' => User::class]
* ];
*
* @var array
*/
public $hasManyThrough = [];

/**
* @var array hasOneThrough is a related record through another record.
*
* protected $hasOneThrough = [
* 'post' => ['Posts', 'through' => 'User']
* 'post' => [Post::class, 'through' => User::class]
* ];
*
* @var array
*/
public $hasOneThrough = [];

Expand Down
Loading

0 comments on commit e07c0bf

Please sign in to comment.