/** * Initialize the {@link $parent}, {@link $related}, {@link $as}, {@link $local_key}, and * {@link $foreign_key} properties. * * @param Model $parent The parent model of the relation. * @param Model|string $related The related model of the relation. Can be specified using its * instance or its identifier. * @param array $options the following options are available: * * - `as`: The name of the magic property to add to the prototype. Default: a plural name * resolved from the foreign model's id. * - `local_key`: The name of the local key. Default: The parent model's primary key. * - `foreign_key`: The name of the foreign key. Default: The parent model's primary key. */ public function __construct(Model $parent, $related, array $options = []) { $options += ['as' => null, 'local_key' => $parent->primary, 'foreign_key' => $parent->primary]; $this->parent = $parent; $this->related = $related; $this->as = $options['as'] ?: $this->resolve_property_name($related); $this->local_key = $options['local_key']; $this->foreign_key = $options['foreign_key']; $activerecord_class = $this->resolve_activerecord_class($parent); $prototype = Prototype::from($activerecord_class); $this->alter_prototype($prototype, $this->as); }
/** * Configures the application. * * The `configure` event of class {@link Core\ConfigureEvent} is fired after the application * is configured. Event hooks may use this event to further configure the application. */ protected function configure() { $this->change_status(self::STATUS_CONFIGURING, function () { Debug::configure($this->configs['debug']); Prototype::configure($this->configs['prototype']); $this->events; new Core\ConfigureEvent($this); }); }
<?php /* * This file is part of the Icybee package. * * (c) Olivier Laviale <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Icybee\Modules\Images; use ICanBoogie\Modules\Thumbnailer\Version; use ICanBoogie\Modules\Thumbnailer\Versions; use ICanBoogie\Prototype; require __DIR__ . '/../vendor/autoload.php'; # # Thumbnailer setup # $prototype = Prototype::from(__NAMESPACE__ . '\\Image'); $prototype['thumbnail'] = 'ICanBoogie\\Modules\\Thumbnailer\\Hooks::method_thumbnail'; # # Image setup # $prototype = Prototype::from('Icybee\\Modules\\Nodes\\Node'); $prototype['lazy_get_image'] = __NAMESPACE__ . '\\Hooks::prototype_get_image'; # # Mocking core # $core = (object) array('models' => array('images' => array(1 => Image::from(array('nid' => 1)), 2 => Image::from(array('nid' => 2)), 3 => Image::from(array('nid' => 3)))), 'thumbnailer_versions' => new Versions(array('articles-list' => new Version('w:120;h:100'), 'articles-view' => new Version('w:420;h:340'))));
/** * Returns the prototype associated with the class. * * @return Prototype */ protected function get_prototype() { return $this->prototype ?: ($this->prototype = Prototype::from($this)); }
/** * Consolidate the methods of the prototype. * * The method creates a single array from the prototype methods and those of its parents. * * @return callable[] */ private function consolidate_methods() { $methods = $this->methods; if ($this->parent) { $methods += $this->parent->get_consolidated_methods(); } return $methods; }
/** * Boot enabled modules. * * Before the modules are actually booted up, their index is used to alter the I18n load * paths and the config paths. * * @param Core\BootEvent $event * @param Core|CoreBindings $app */ public static function on_core_boot(Core\BootEvent $event, Core $app) { # # Revoke prototypes and events. # Prototype::configure($app->configs['prototype']); $app->events->attach_many($app->configs['event']); }