aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/package.rs
blob: 680443e3dfdce75e8cbd62a0592c48081c26c8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
//! ref: composer/src/Composer/Package/Package.php

use std::rc::Rc;

use chrono::{DateTime, Utc};
use indexmap::IndexMap;

use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::composer::util::ComposerMirror;
use shirabe_php_shim::{E_USER_DEPRECATED, LogicException, PhpMixed, strpos, trigger_error};

use crate::package::BasePackage;
use crate::package::Link;
use crate::package::PackageInterface;
use crate::package::version::VersionParser;
use crate::repository::RepositoryInterfaceHandle;
use crate::repository::RepositoryInterfaceWeakHandle;

/// Mirror entry, e.g. `['url' => 'https://...', 'preferred' => true]`.
#[derive(Debug, Clone)]
pub struct Mirror {
    pub url: String,
    pub preferred: bool,
}

/// Core package definitions that are needed to resolve dependencies and install packages
#[derive(Debug)]
pub struct Package {
    id: i64,
    name: String,
    pretty_name: String,
    /// Back-reference to the owning repository. `Weak` breaks the repository -> packages cycle.
    repository: Option<RepositoryInterfaceWeakHandle>,

    pub(crate) r#type: Option<String>,
    pub(crate) target_dir: Option<String>,
    /// `'source'` | `'dist'` | `null`
    pub(crate) installation_source: Option<String>,
    pub(crate) source_type: Option<String>,
    pub(crate) source_url: Option<String>,
    pub(crate) source_reference: Option<String>,
    pub(crate) source_mirrors: Option<Vec<Mirror>>,
    pub(crate) dist_type: Option<String>,
    pub(crate) dist_url: Option<String>,
    pub(crate) dist_reference: Option<String>,
    pub(crate) dist_sha1_checksum: Option<String>,
    pub(crate) dist_mirrors: Option<Vec<Mirror>>,
    pub(crate) version: String,
    pub(crate) pretty_version: String,
    pub(crate) release_date: Option<chrono::DateTime<chrono::Utc>>,
    pub(crate) extra: IndexMap<String, PhpMixed>,
    pub(crate) binaries: Vec<String>,
    pub(crate) dev: bool,
    /// `'stable'` | `'RC'` | `'beta'` | `'alpha'` | `'dev'`
    pub(crate) stability: String,
    pub(crate) notification_url: Option<String>,

    pub(crate) requires: IndexMap<String, Link>,
    pub(crate) conflicts: IndexMap<String, Link>,
    pub(crate) provides: IndexMap<String, Link>,
    pub(crate) replaces: IndexMap<String, Link>,
    pub(crate) dev_requires: IndexMap<String, Link>,
    pub(crate) suggests: IndexMap<String, String>,
    pub(crate) autoload: IndexMap<String, PhpMixed>,
    pub(crate) dev_autoload: IndexMap<String, PhpMixed>,
    pub(crate) include_paths: Vec<String>,
    pub(crate) is_default_branch: bool,
    pub(crate) transport_options: IndexMap<String, PhpMixed>,
    pub(crate) php_ext: Option<IndexMap<String, PhpMixed>>,
}

impl Package {
    /// Creates a new in memory package.
    pub fn new(name: String, version: String, pretty_version: String) -> Self {
        let stability = VersionParser::parse_stability(&version).to_string();
        let dev = stability == "dev";
        Self {
            id: -1,
            name: name.to_lowercase(),
            pretty_name: name,
            repository: None,
            r#type: None,
            target_dir: None,
            installation_source: None,
            source_type: None,
            source_url: None,
            source_reference: None,
            source_mirrors: None,
            dist_type: None,
            dist_url: None,
            dist_reference: None,
            dist_sha1_checksum: None,
            dist_mirrors: None,
            version,
            pretty_version,
            release_date: None,
            extra: IndexMap::new(),
            binaries: Vec::new(),
            dev,
            stability,
            notification_url: None,
            requires: IndexMap::new(),
            conflicts: IndexMap::new(),
            provides: IndexMap::new(),
            replaces: IndexMap::new(),
            dev_requires: IndexMap::new(),
            suggests: IndexMap::new(),
            autoload: IndexMap::new(),
            dev_autoload: IndexMap::new(),
            include_paths: Vec::new(),
            is_default_branch: false,
            transport_options: IndexMap::new(),
            php_ext: None,
        }
    }

    pub fn is_dev(&self) -> bool {
        self.dev
    }

    pub fn set_type(&mut self, r#type: String) {
        self.r#type = Some(r#type);
    }

    pub fn get_type(&self) -> String {
        self.r#type
            .clone()
            .filter(|s| !s.is_empty())
            .unwrap_or_else(|| "library".to_string())
    }

    pub fn get_stability(&self) -> &str {
        &self.stability
    }

    pub fn set_target_dir(&mut self, target_dir: Option<String>) {
        self.target_dir = target_dir;
    }

    pub fn get_target_dir(&self) -> Option<String> {
        let target_dir = self.target_dir.as_ref()?;

        let replaced = Preg::replace(
            "{ (?:^|[\\\\/]+) \\.\\.? (?:[\\\\/]+|$) (?:\\.\\.? (?:[\\\\/]+|$) )*}x",
            "/",
            target_dir,
        )
        .unwrap_or_else(|_| target_dir.clone());
        Some(replaced.trim_start_matches('/').to_string())
    }

    pub fn set_extra(&mut self, extra: IndexMap<String, PhpMixed>) {
        self.extra = extra;
    }

    pub fn get_extra(&self) -> &IndexMap<String, PhpMixed> {
        &self.extra
    }

    pub fn set_binaries(&mut self, binaries: Vec<String>) {
        self.binaries = binaries;
    }

    pub fn get_binaries(&self) -> &Vec<String> {
        &self.binaries
    }

    pub fn set_installation_source(&mut self, r#type: Option<String>) {
        self.installation_source = r#type;
    }

    pub fn get_installation_source(&self) -> Option<&str> {
        self.installation_source.as_deref()
    }

    pub fn set_source_type(&mut self, r#type: Option<String>) {
        self.source_type = r#type;
    }

    pub fn get_source_type(&self) -> Option<&str> {
        self.source_type.as_deref()
    }

    pub fn set_source_url(&mut self, url: Option<String>) {
        self.source_url = url;
    }

    pub fn get_source_url(&self) -> Option<&str> {
        self.source_url.as_deref()
    }

    pub fn set_source_reference(&mut self, reference: Option<String>) {
        self.source_reference = reference;
    }

    pub fn get_source_reference(&self) -> Option<&str> {
        self.source_reference.as_deref()
    }

    pub fn set_source_mirrors(&mut self, mirrors: Option<Vec<Mirror>>) {
        self.source_mirrors = mirrors;
    }

    pub fn get_source_mirrors(&self) -> Option<&Vec<Mirror>> {
        self.source_mirrors.as_ref()
    }

    pub fn get_source_urls(&self) -> Vec<String> {
        self.get_urls(
            self.source_url.as_deref(),
            self.source_mirrors.as_ref(),
            self.source_reference.as_deref(),
            self.source_type.as_deref(),
            "source",
        )
    }

    pub fn set_dist_type(&mut self, r#type: Option<String>) {
        self.dist_type = match r#type.as_deref() {
            Some("") => None,
            _ => r#type,
        };
    }

    pub fn get_dist_type(&self) -> Option<&str> {
        self.dist_type.as_deref()
    }

    pub fn set_dist_url(&mut self, url: Option<String>) {
        self.dist_url = match url.as_deref() {
            Some("") => None,
            _ => url,
        };
    }

    pub fn get_dist_url(&self) -> Option<&str> {
        self.dist_url.as_deref()
    }

    pub fn set_dist_reference(&mut self, reference: Option<String>) {
        self.dist_reference = reference;
    }

    pub fn get_dist_reference(&self) -> Option<&str> {
        self.dist_reference.as_deref()
    }

    pub fn set_dist_sha1_checksum(&mut self, sha1checksum: Option<String>) {
        self.dist_sha1_checksum = sha1checksum;
    }

    pub fn get_dist_sha1_checksum(&self) -> Option<&str> {
        self.dist_sha1_checksum.as_deref()
    }

    pub fn set_dist_mirrors(&mut self, mirrors: Option<Vec<Mirror>>) {
        self.dist_mirrors = mirrors;
    }

    pub fn get_dist_mirrors(&self) -> Option<&Vec<Mirror>> {
        self.dist_mirrors.as_ref()
    }

    pub fn get_dist_urls(&self) -> Vec<String> {
        self.get_urls(
            self.dist_url.as_deref(),
            self.dist_mirrors.as_ref(),
            self.dist_reference.as_deref(),
            self.dist_type.as_deref(),
            "dist",
        )
    }

    pub fn get_transport_options(&self) -> &IndexMap<String, PhpMixed> {
        &self.transport_options
    }

    pub fn set_transport_options(&mut self, options: IndexMap<String, PhpMixed>) {
        self.transport_options = options;
    }

    pub fn get_version(&self) -> &str {
        &self.version
    }

    pub fn get_pretty_version(&self) -> &str {
        &self.pretty_version
    }

    pub fn set_release_date(&mut self, release_date: Option<chrono::DateTime<chrono::Utc>>) {
        self.release_date = release_date;
    }

    pub fn get_release_date(&self) -> Option<&chrono::DateTime<chrono::Utc>> {
        self.release_date.as_ref()
    }

    /// Set the required packages
    pub fn set_requires(&mut self, mut requires: IndexMap<String, Link>) {
        if requires.contains_key("0") {
            requires = self.convert_links_to_map(requires, "setRequires");
        }

        self.requires = requires;
    }

    pub fn get_requires(&self) -> &IndexMap<String, Link> {
        &self.requires
    }

    pub fn set_conflicts(&mut self, mut conflicts: IndexMap<String, Link>) {
        if conflicts.contains_key("0") {
            conflicts = self.convert_links_to_map(conflicts, "setConflicts");
        }

        self.conflicts = conflicts;
    }

    pub fn get_conflicts(&self) -> &IndexMap<String, Link> {
        &self.conflicts
    }

    pub fn set_provides(&mut self, mut provides: IndexMap<String, Link>) {
        if provides.contains_key("0") {
            provides = self.convert_links_to_map(provides, "setProvides");
        }

        self.provides = provides;
    }

    pub fn get_provides(&self) -> &IndexMap<String, Link> {
        &self.provides
    }

    pub fn set_replaces(&mut self, mut replaces: IndexMap<String, Link>) {
        if replaces.contains_key("0") {
            replaces = self.convert_links_to_map(replaces, "setReplaces");
        }

        self.replaces = replaces;
    }

    pub fn get_replaces(&self) -> &IndexMap<String, Link> {
        &self.replaces
    }

    pub fn set_dev_requires(&mut self, mut dev_requires: IndexMap<String, Link>) {
        if dev_requires.contains_key("0") {
            dev_requires = self.convert_links_to_map(dev_requires, "setDevRequires");
        }

        self.dev_requires = dev_requires;
    }

    pub fn get_dev_requires(&self) -> &IndexMap<String, Link> {
        &self.dev_requires
    }

    pub fn set_suggests(&mut self, suggests: IndexMap<String, String>) {
        self.suggests = suggests;
    }

    pub fn get_suggests(&self) -> &IndexMap<String, String> {
        &self.suggests
    }

    pub fn set_autoload(&mut self, autoload: IndexMap<String, PhpMixed>) {
        self.autoload = autoload;
    }

    pub fn get_autoload(&self) -> &IndexMap<String, PhpMixed> {
        &self.autoload
    }

    pub fn set_dev_autoload(&mut self, dev_autoload: IndexMap<String, PhpMixed>) {
        self.dev_autoload = dev_autoload;
    }

    pub fn get_dev_autoload(&self) -> &IndexMap<String, PhpMixed> {
        &self.dev_autoload
    }

    pub fn set_include_paths(&mut self, include_paths: Vec<String>) {
        self.include_paths = include_paths;
    }

    pub fn get_include_paths(&self) -> &Vec<String> {
        &self.include_paths
    }

    pub fn set_php_ext(&mut self, php_ext: Option<IndexMap<String, PhpMixed>>) {
        self.php_ext = php_ext;
    }

    pub fn get_php_ext(&self) -> Option<&IndexMap<String, PhpMixed>> {
        self.php_ext.as_ref()
    }

    pub fn set_notification_url(&mut self, notification_url: String) {
        self.notification_url = Some(notification_url);
    }

    pub fn get_notification_url(&self) -> Option<&str> {
        self.notification_url.as_deref()
    }

    pub fn set_is_default_branch(&mut self, default_branch: bool) {
        self.is_default_branch = default_branch;
    }

    pub fn is_default_branch(&self) -> bool {
        self.is_default_branch
    }

    pub fn set_source_dist_references(&mut self, reference: String) {
        self.set_source_reference(Some(reference.clone()));

        // only bitbucket, github and gitlab have auto generated dist URLs that easily allow replacing the reference in the dist URL
        // TODO generalize this a bit for self-managed/on-prem versions? Some kind of replace token in dist urls which allow this?
        if self.get_dist_url().is_some()
            && Preg::is_match(
                "{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com|(?:www\\.)?gitlab\\.com)/}i",
                self.get_dist_url().unwrap_or(""),
            )
            .unwrap_or(false)
        {
            self.set_dist_reference(Some(reference.clone()));
            self.set_dist_url(Some(
                Preg::replace(
                    "{(?<=/|sha=)[a-f0-9]{40}(?=/|$)}i",
                    &reference,
                    self.get_dist_url().unwrap_or(""),
                )
                .unwrap_or_default(),
            ));
        } else if self.get_dist_reference().is_some() {
            // update the dist reference if there was one, but if none was provided ignore it
            self.set_dist_reference(Some(reference));
        }
    }

    /// Replaces current version and pretty version with passed values.
    /// It also sets stability.
    pub fn replace_version(&mut self, version: String, pretty_version: String) {
        self.version = version;
        self.pretty_version = pretty_version;

        self.stability = VersionParser::parse_stability(&self.version).to_string();
        self.dev = self.stability == "dev";
    }

    fn get_urls(
        &self,
        url: Option<&str>,
        mirrors: Option<&Vec<Mirror>>,
        r#ref: Option<&str>,
        r#type: Option<&str>,
        url_type: &str,
    ) -> Vec<String> {
        let url = match url {
            Some(u) if !u.is_empty() => u,
            _ => return Vec::new(),
        };

        let url = if url_type == "dist" && strpos(url, "%").is_some() {
            ComposerMirror::process_url(
                url,
                &self.name,
                &self.version,
                r#ref,
                r#type,
                Some(self.pretty_version.as_str()),
            )
        } else {
            url.to_string()
        };

        let mut urls: Vec<String> = vec![url.clone()];
        if let Some(mirrors) = mirrors {
            for mirror in mirrors {
                let mirror_url = if url_type == "dist" {
                    ComposerMirror::process_url(
                        &mirror.url,
                        &self.name,
                        &self.version,
                        r#ref,
                        r#type,
                        Some(self.pretty_version.as_str()),
                    )
                } else if url_type == "source" && r#type == Some("git") {
                    ComposerMirror::process_git_url(
                        &mirror.url,
                        &self.name,
                        &url,
                        r#type.unwrap_or(""),
                    )
                } else if url_type == "source" && r#type == Some("hg") {
                    ComposerMirror::process_hg_url(
                        &mirror.url,
                        &self.name,
                        &url,
                        r#type.unwrap_or(""),
                    )
                } else {
                    continue;
                };
                if !urls.contains(&mirror_url) {
                    if mirror.preferred {
                        urls.insert(0, mirror_url);
                    } else {
                        urls.push(mirror_url);
                    }
                }
            }
        }

        urls
    }

    fn convert_links_to_map(
        &self,
        links: IndexMap<String, Link>,
        source: &str,
    ) -> IndexMap<String, Link> {
        trigger_error(
            &format!(
                "Package::{} must be called with a map of lowercased package name => Link object, got a indexed array, this is deprecated and you should fix your usage.",
                source
            ),
            E_USER_DEPRECATED,
        );
        let mut new_links: IndexMap<String, Link> = IndexMap::new();
        for (_k, link) in links {
            new_links.insert(link.get_target().to_string(), link);
        }

        new_links
    }
}

impl BasePackage for Package {
    fn id(&self) -> i64 {
        self.id
    }

    fn id_mut(&mut self) -> &mut i64 {
        &mut self.id
    }

    fn name(&self) -> &str {
        &self.name
    }

    fn name_mut(&mut self) -> &mut String {
        &mut self.name
    }

    fn pretty_name(&self) -> &str {
        &self.pretty_name
    }

    fn pretty_name_mut(&mut self) -> &mut String {
        &mut self.pretty_name
    }

    fn repository_opt(&self) -> Option<RepositoryInterfaceHandle> {
        self.repository
            .as_ref()
            .and_then(|w| w.upgrade())
            .map(RepositoryInterfaceHandle::from_rc)
    }

    fn set_repository_box(&mut self, repository: RepositoryInterfaceHandle) {
        self.repository = Some(repository.downgrade());
    }

    fn take_repository(&mut self) -> Option<RepositoryInterfaceHandle> {
        self.repository
            .take()
            .and_then(|w| w.upgrade())
            .map(RepositoryInterfaceHandle::from_rc)
    }
}

impl std::fmt::Display for Package {
    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        todo!()
    }
}

impl PackageInterface for Package {
    fn get_name(&self) -> &str {
        todo!()
    }
    fn get_pretty_name(&self) -> &str {
        todo!()
    }
    fn get_names(&self, _provides: bool) -> Vec<String> {
        todo!()
    }
    fn set_id(&mut self, _id: i64) {
        todo!()
    }
    fn get_id(&self) -> i64 {
        todo!()
    }
    fn is_dev(&self) -> bool {
        todo!()
    }
    fn get_type(&self) -> &str {
        todo!()
    }
    fn get_target_dir(&self) -> Option<&str> {
        todo!()
    }
    fn get_extra(&self) -> IndexMap<String, PhpMixed> {
        todo!()
    }
    fn set_installation_source(&mut self, _type: Option<String>) {
        todo!()
    }
    fn get_installation_source(&self) -> Option<&str> {
        todo!()
    }
    fn get_source_type(&self) -> Option<&str> {
        todo!()
    }
    fn get_source_url(&self) -> Option<&str> {
        todo!()
    }
    fn get_source_urls(&self) -> Vec<String> {
        todo!()
    }
    fn get_source_reference(&self) -> Option<&str> {
        todo!()
    }
    fn get_source_mirrors(&self) -> Option<Vec<IndexMap<String, PhpMixed>>> {
        todo!()
    }
    fn set_source_mirrors(&mut self, _mirrors: Option<Vec<IndexMap<String, PhpMixed>>>) {
        todo!()
    }
    fn get_dist_type(&self) -> Option<&str> {
        todo!()
    }
    fn get_dist_url(&self) -> Option<&str> {
        todo!()
    }
    fn get_dist_urls(&self) -> Vec<String> {
        todo!()
    }
    fn get_dist_reference(&self) -> Option<&str> {
        todo!()
    }
    fn get_dist_sha1_checksum(&self) -> Option<&str> {
        todo!()
    }
    fn get_dist_mirrors(&self) -> Option<Vec<IndexMap<String, PhpMixed>>> {
        todo!()
    }
    fn set_dist_mirrors(&mut self, _mirrors: Option<Vec<IndexMap<String, PhpMixed>>>) {
        todo!()
    }
    fn get_version(&self) -> &str {
        todo!()
    }
    fn get_pretty_version(&self) -> &str {
        todo!()
    }
    fn get_full_pretty_version(&self, _truncate: bool, _display_mode: i64) -> String {
        todo!()
    }
    fn get_release_date(&self) -> Option<DateTime<Utc>> {
        todo!()
    }
    fn get_stability(&self) -> &str {
        todo!()
    }
    fn get_requires(&self) -> IndexMap<String, Link> {
        todo!()
    }
    fn get_conflicts(&self) -> IndexMap<String, Link> {
        todo!()
    }
    fn get_provides(&self) -> IndexMap<String, Link> {
        todo!()
    }
    fn get_replaces(&self) -> IndexMap<String, Link> {
        todo!()
    }
    fn get_dev_requires(&self) -> IndexMap<String, Link> {
        todo!()
    }
    fn get_suggests(&self) -> IndexMap<String, String> {
        todo!()
    }
    fn get_autoload(&self) -> IndexMap<String, PhpMixed> {
        todo!()
    }
    fn get_dev_autoload(&self) -> IndexMap<String, PhpMixed> {
        todo!()
    }
    fn get_include_paths(&self) -> Vec<String> {
        todo!()
    }
    fn get_php_ext(&self) -> Option<IndexMap<String, PhpMixed>> {
        todo!()
    }
    fn set_repository(&mut self, repository: RepositoryInterfaceHandle) -> anyhow::Result<()> {
        if let Some(existing) = self.repository.as_ref().and_then(|w| w.upgrade()) {
            if !Rc::ptr_eq(&existing, repository.as_rc()) {
                return Err(LogicException {
                    message: "A package can only be added to one repository".to_string(),
                    code: 0,
                }
                .into());
            }
        }
        self.repository = Some(repository.downgrade());
        Ok(())
    }
    fn get_repository(&self) -> Option<RepositoryInterfaceHandle> {
        self.repository
            .as_ref()
            .and_then(|w| w.upgrade())
            .map(RepositoryInterfaceHandle::from_rc)
    }
    fn get_binaries(&self) -> Vec<String> {
        todo!()
    }
    fn get_unique_name(&self) -> String {
        todo!()
    }
    fn get_notification_url(&self) -> Option<&str> {
        todo!()
    }
    fn get_pretty_string(&self) -> String {
        todo!()
    }
    fn is_default_branch(&self) -> bool {
        todo!()
    }
    fn get_transport_options(&self) -> IndexMap<String, PhpMixed> {
        todo!()
    }
    fn set_transport_options(&mut self, _options: IndexMap<String, PhpMixed>) {
        todo!()
    }
    fn set_source_reference(&mut self, _reference: Option<String>) {
        todo!()
    }
    fn set_dist_url(&mut self, _url: Option<String>) {
        todo!()
    }
    fn set_dist_type(&mut self, _type: Option<String>) {
        todo!()
    }
    fn set_dist_reference(&mut self, _reference: Option<String>) {
        todo!()
    }
    fn set_source_dist_references(&mut self, _reference: &str) {
        todo!()
    }
}