コード例 #1
0
 /**
  * {@inheritDoc}
  */
 public function __construct(array $data)
 {
     foreach ($data as $key => $value) {
         $property = Inflector::get()->camelize($key, true);
         $this->{$property} = $value;
     }
 }
コード例 #2
0
 /**
  * Create a new command instance.
  *
  * @param \Illuminate\Filesystem\Filesystem $files
  * @param \Illuminate\Support\Composer $composer
  */
 public function __construct(Filesystem $files, Composer $composer)
 {
     parent::__construct();
     $this->files = $files;
     $this->composer = $composer;
     $this->inflector = Inflector::get('en');
 }
コード例 #3
0
ファイル: TableData.php プロジェクト: WebDevBr/MvcRest
 public final function __construct($controller_origin = null)
 {
     if (empty($this->entity)) {
         $inflector = \ICanBoogie\Inflector::get();
         $entity = $inflector->singularize($inflector->camelize($controller_origin));
         $this->entity = '\\App\\Mvc\\Models\\Entities\\' . $entity;
     }
 }
コード例 #4
0
ファイル: CommandParser.php プロジェクト: BapCat/Console
 public function __construct(CommandRegistry $registry)
 {
     $this->registry = $registry;
     $this->regex_params = new Regex('#@param\\h+?([\\w\\\\]+)\\h+?\\$(\\w+)\\h+(?:\\(short:\\h(\\w)\\)\\h+)?([\\w\\h]+)#');
     $this->regex_opts = new Regex('#@opt\\h+?\\$(\\w+)\\h+(?:\\(short:\\h(\\w)\\)\\h+)?([\\w\\h]+)#');
     $this->text_dash = new Text('-');
     $this->text_underscore = new Text('_');
     $this->inflector = Inflector::get();
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $country = $this->zonesService->getCountryByIsoCode2Letters($request->get('country'));
     $inflector = Inflector::get(strtolower($country->getIsoCode2Letters()));
     $zoneTypeSlug = $inflector->singularize($request->get($name));
     $zoneType = $this->zonesService->getZoneTypeFromSlug($zoneTypeSlug, $country);
     $request->attributes->set('zoneType', $zoneType);
     return true;
 }
コード例 #6
0
ファイル: ServiceProvider.php プロジェクト: mooti/framework
 /**
  * Get the details of the services we are providing     
  *
  * @return array
  */
 public function getServices()
 {
     return [self::INFLECTOR => function () {
         return Inflector::get('en');
     }, self::APPLICATION_RUNTIME => function () {
         return new ApplicationRuntime();
     }, self::CONFIG_FACTORY => function () {
         return new ConfigFactory();
     }];
 }
コード例 #7
0
 protected function setUp()
 {
     $name = $this->getResourceName();
     $jsonFilename = Inflector::get()->pluralize(strtolower($name));
     $mockData = $this->getMockData($jsonFilename);
     $this->setMockResponses([[200, $mockData]]);
     $mapper = ResourceMapperFactory::factory($name, $this->getAdapter());
     $collection = $mapper->findAll();
     $this->resource = $collection->current();
 }
コード例 #8
0
 /**
  * @param string $camelCasing
  * @param Inflector|null $inflector
  * 
  * @return string
  */
 protected static function tableize($camelCasing, $inflector = null)
 {
     if (null === $inflector) {
         $inflector = Inflector::get();
     }
     $underscored = $inflector->underscore($camelCasing);
     if ('_table' === substr($underscored, -6)) {
         $underscored = substr($underscored, 0, strlen($underscored) - 6);
     }
     return $inflector->pluralize($underscored);
 }
コード例 #9
0
 /**
  * @param string $attribute
  * @return string
  * @throws AnnotationNotFound
  * @throws InvalidAttributeType
  */
 public function getAttributeType(string $attribute) : string
 {
     $attribute = Inflector::get()->camelize($attribute, Inflector::DOWNCASE_FIRST_LETTER);
     $docblock = $this->reflectionClass->getProperty($attribute)->getDocComment();
     $annotations = [];
     preg_match_all('/@var\\s*([^\\s]+)/i', $docblock, $annotations, PREG_SET_ORDER);
     if (empty($annotations) || !isset($annotations[0][1])) {
         throw new AnnotationNotFound();
     }
     $type = strtolower($annotations[0][1]);
     return $type;
 }
コード例 #10
0
ファイル: PropifierTrait.php プロジェクト: bapcat/propifier
 /**
  * Builds and caches the properties for a given object, if not already cached
  *
  * @param $obj The object to cache
  */
 private static function buildDependencies($obj)
 {
     $name = get_class($obj);
     if (!array_key_exists($name, self::$method_map)) {
         $class = new ReflectionClass($obj);
         $methods = $class->getMethods(ReflectionMethod::IS_PROTECTED);
         $properties = self::filterProperties($methods);
         $inflector = Inflector::get();
         $method_map = self::remapProperties([$inflector, 'underscore'], $properties);
         self::$method_map[$name] = self::extractProperties($obj, $method_map);
     }
 }
コード例 #11
0
ファイル: HasMany.php プロジェクト: jaredtking/pulsar
 /**
  * @param Model  $localModel
  * @param string $localKey     identifying key on local model
  * @param string $foreignModel foreign model class
  * @param string $foreignKey   identifying key on foreign model
  */
 public function __construct(Model $localModel, $localKey, $foreignModel, $foreignKey)
 {
     // the default foreign key would look like
     // `user_id` for a model named User
     if (!$foreignKey) {
         $inflector = Inflector::get();
         $foreignKey = strtolower($inflector->underscore($localModel::modelName())) . '_id';
     }
     if (!$localKey) {
         $localKey = Model::DEFAULT_ID_PROPERTY;
     }
     parent::__construct($localModel, $localKey, $foreignModel, $foreignKey);
 }
コード例 #12
0
ファイル: BaseCommand.php プロジェクト: enzyme/axiom
 /**
  * {@inheritDoc}
  *
  * @throws Exception If there is no namespace or location defined for the
  * class type(s) being generated.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inflector = Inflector::get(Inflector::DEFAULT_LOCALE);
     $type_plural = $inflector->pluralize($this->getGeneratorType());
     $this->namespace = $input->getOption('namespace') !== null ? $input->getOption('namespace') : $this->config->get("{$type_plural}.namespace");
     $this->location = $input->getOption('location') !== null ? $input->getOption('location') : $this->config->get("{$type_plural}.location");
     if (null === $this->namespace) {
         throw new Exception("There is no namespace defined for {$type_plural}");
     }
     if (null === $this->location) {
         throw new Exception("There is no location defined for {$type_plural}");
     }
 }
コード例 #13
0
ファイル: EntityMap.php プロジェクト: vsmoraes/dynamo-mapper
 /**
  * @param mixed $entity
  * @param string $field
  * @param mixed $value
  * @throws AttributeUnreachable
  */
 protected function setEntityValue($entity, string $field, $value)
 {
     $method = Inflector::get()->camelize('set_' . $field);
     if (method_exists($entity, $method)) {
         $entity->{$method}($value);
         return;
     }
     $property = new \ReflectionProperty($entity, $field);
     if ($property->isPublic()) {
         $entity->{$field} = $value;
         return;
     }
     throw new AttributeUnreachable("Cannot access the attribute: '{$field}'");
 }
コード例 #14
0
ファイル: DataMap.php プロジェクト: vsmoraes/dynamo-mapper
 /**
  * @param string $field
  * @return mixed
  * @throws AttributeUnreachable
  */
 protected function getEntityValue($field)
 {
     $method = Inflector::get()->camelize('get_' . $field);
     if (method_exists($this->entity, $method)) {
         return $this->entity->{$method}();
     }
     $boolMethod = Inflector::get()->camelize('is_' . $field);
     if (method_exists($this->entity, $boolMethod)) {
         return $this->entity->{$boolMethod}();
     }
     $property = new \ReflectionProperty($this->entity, $field);
     if ($property->isPublic()) {
         return $this->entity->{$field};
     }
     throw new AttributeUnreachable("Cannot access the attribute: '{$field}'");
 }
コード例 #15
0
 /**
  * @param array $array
  * @param $identifier
  * @param $key
  *
  * @return array
  */
 public static function mergeBy(array $array, $identifier, $key)
 {
     $inflector = Inflector::get();
     $uniqueValues = [];
     $newKey = $inflector->pluralize($key);
     foreach ($array as $item) {
         if (!array_key_exists($item[$identifier], $uniqueValues)) {
             $uniqueValues[$item[$identifier]] = $item;
             $uniqueValues[$item[$identifier]][$newKey] = [];
         }
         array_push($uniqueValues[$item[$identifier]][$newKey], $item[$key]);
         if ($key !== $newKey) {
             unset($uniqueValues[$item[$identifier]][$key]);
         }
     }
     return array_values($uniqueValues);
 }
コード例 #16
0
 /**
  * This function tells the controller to process the Stripe event.
  *
  * @return string output
  */
 public function handle(array $event)
 {
     if (!isset($event['id'])) {
         return self::ERROR_INVALID_EVENT;
     }
     // check that the livemode matches our development state
     $environment = $this->app['environment'];
     if (!($event['livemode'] && $environment === Application::ENV_PRODUCTION || !$event['livemode'] && $environment !== Application::ENV_PRODUCTION)) {
         return self::ERROR_LIVEMODE_MISMATCH;
     }
     if (isset($event['user_id'])) {
         return self::ERROR_STRIPE_CONNECT_EVENT;
     }
     // grab up the API key
     $this->apiKey = $this->app['config']->get('stripe.secret');
     try {
         // retreive the event, unless it is a deauth event
         // since those cannot be retrieved
         $validatedEvent = $event['type'] == 'account.application.deauthorized' ? (object) $event : Event::retrieve($event['id'], $this->apiKey);
         // get the data attached to the event
         $eventData = $validatedEvent->data->object;
         // find out which user this event is for by cross-referencing the customer id
         $modelClass = $this->app['config']->get('billing.model');
         $member = $modelClass::where('stripe_customer', $eventData->customer)->first();
         if (!$member) {
             return self::ERROR_CUSTOMER_NOT_FOUND;
         }
         // determine handler by checking if the method exists
         // i.e customer.subscription.created -> handleCustomerSubscriptionCreated
         $inflector = Inflector::get();
         $method = str_replace('.', '_', $validatedEvent->type);
         $method = 'handle' . $inflector->camelize($method);
         if (!method_exists($this, $method)) {
             return self::ERROR_EVENT_NOT_SUPPORTED;
         }
         if ($this->{$method}($eventData, $member)) {
             return self::SUCCESS;
         }
     } catch (StripeError $e) {
         $this->app['logger']->error($e);
     }
     return self::ERROR_GENERIC;
 }
コード例 #17
0
ファイル: Router.php プロジェクト: ultractiv/lean
 protected function __construct()
 {
     $this->inflector = Inflector::get();
     if (!class_exists('\\Controller')) {
         throw new ControllerException("No Controller class found in " . LEAN_APP_ROOT);
     }
     $this->controller = \Controller::instance();
     $this->request = $_SERVER['REQUEST_METHOD'];
     if (isset($_SERVER['PATH_INFO'])) {
         $this->path = $_SERVER['PATH_INFO'];
     } else {
         if (isset($_GET['path'])) {
             $this->path = $_GET['path'];
         }
     }
     $this->init();
     $this->route();
     $this->controller->respond();
 }
コード例 #18
0
 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $country = $request->get('country', null);
     $inflector = Inflector::get(strtolower($country));
     $zoneType = $request->get('zoneType', null);
     switch (true) {
         case $zoneType instanceof ZoneType:
             $zoneType = $inflector->singularize($zoneType->getSlug());
             break;
         case $zoneType != null:
             $zoneType = $inflector->singularize($zoneType);
             break;
     }
     $slug = $request->get($name);
     $zone = $this->zonesService->getZoneFromSlug($slug, $zoneType, $country);
     $request->attributes->set('zone', $zone);
     return true;
 }
コード例 #19
0
 public function getFilters()
 {
     return array(new \Twig_SimpleFilter('low', function ($key) {
         return strtolower($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('up', function ($key) {
         return strtoupper($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('singularize', function ($key) {
         return Inflector::get()->singularize($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('pluralize', function ($key) {
         return Inflector::get()->pluralize($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('camelize', function ($key) {
         return Inflector::get()->camelize($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('variableize', function ($key) {
         return Inflector::get()->camelize($key, true);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('underscore', function ($key) {
         return Inflector::get()->underscore($key);
     }, ['is_safe' => ['html']]), new \Twig_SimpleFilter('humanize', function ($key) {
         return Inflector::get()->humanize($key);
     }, ['is_safe' => ['html']]));
 }
コード例 #20
0
 public function calculate(AddressInterface $origin, AddressInterface $destination, ShippableInterface $shippable)
 {
     $result = (new Request($this->beta))->getGetRatesReply(Factory::createRateRequest($origin, $destination, $shippable, $this->key, $this->password, $this->accountNumber, $this->meterNumber));
     if ('ERROR' === $result->HighestSeverity) {
         $message = '';
         if (is_array($result->Notifications)) {
             foreach ($result->Notifications as $notification) {
                 $message .= $notification->Message;
             }
         } else {
             $message = $result->Notifications->Message;
         }
         throw new CalculatorException($message);
     }
     $estimations = [];
     if (isset($result->RateReplyDetails)) {
         foreach ($result->RateReplyDetails as $rateReplyDetails) {
             foreach ($rateReplyDetails->RatedShipmentDetails as $rateShipmentDetails) {
                 if (isset($rateShipmentDetails->TotalNetCharge)) {
                     $details = $rateShipmentDetails;
                     $charge = $details->TotalNetCharge;
                 } elseif (isset($rateShipmentDetails->ShipmentRateDetail)) {
                     $details = $rateShipmentDetails->ShipmentRateDetail;
                     $charge = $details->TotalNetCharge;
                 } elseif (isset($rateShipmentDetails->PackageRateDetail)) {
                     $details = $rateShipmentDetails->PackageRateDetail;
                     $charge = $details->NetCharge;
                 } else {
                     throw new CalculatorException('Failed to extract shipping cost.');
                 }
                 if ($rateReplyDetails->ActualRateType !== $details->RateType) {
                     continue;
                 }
                 $estimations[] = (new Estimation())->setCarrier('FedEx')->setServiceName(Inflector::get()->humanize($rateReplyDetails->ServiceType))->setServiceCode($rateReplyDetails->ServiceType)->setDeliveryDate(isset($rateReplyDetails->DeliveryTimestamp) ? new DateTime($rateReplyDetails->DeliveryTimestamp) : null)->setCost((new Cost())->setCurrency($charge->Currency)->setAmount($charge->Amount));
             }
         }
     }
     return $estimations;
 }
コード例 #21
0
ファイル: BelongsToMany.php プロジェクト: jaredtking/pulsar
 /**
  * @param Model  $localModel
  * @param string $localKey     identifying key on local model
  * @param string $tablename    pivot table name
  * @param string $foreignModel foreign model class
  * @param string $foreignKey   identifying key on foreign model
  */
 public function __construct(Model $localModel, $localKey, $tablename, $foreignModel, $foreignKey)
 {
     // the default local key would look like `user_id`
     // for a model named User
     if (!$localKey) {
         $inflector = Inflector::get();
         $localKey = strtolower($inflector->underscore($foreignModel::modelName())) . '_id';
     }
     if (!$foreignKey) {
         $foreignKey = Model::DEFAULT_ID_PROPERTY;
     }
     // the default pivot table name looks like
     // RoleUser for models named Role and User.
     // the tablename is built from the model names
     // in alphabetic order.
     if (!$tablename) {
         $names = [$localModel::modelName(), $foreignModel::modelName()];
         sort($names);
         $tablename = implode($names);
     }
     $this->tablename = $tablename;
     parent::__construct($localModel, $localKey, $foreignModel, $foreignKey);
 }
コード例 #22
0
ファイル: AbstractResource.php プロジェクト: pbousa/php-sdk
 /**
  * @param string $name
  * @param array $arguments
  */
 public function __call($name, $arguments)
 {
     $inflector = Inflector::get();
     /**
      * Get a resource attribute
      */
     if (strtolower(substr($name, 0, 3)) == 'get' && count($arguments) === 0) {
         $key = str_replace('get', '', $name);
         $key = $inflector->underscore($key);
         if (isset($this->_attributes) && is_array($this->_attributes) && array_key_exists($key, $this->_attributes)) {
             return $this->_attributes[$key];
         }
     }
     /**
      * Set a resource attribute
      */
     if (strtolower(substr($name, 0, 3)) == 'set' && count($arguments) === 1) {
         $key = str_replace('set', '', $name);
         $key = $inflector->underscore($key);
         if (isset($this->_attributes) && is_array($this->_attributes) && array_key_exists($key, $this->_attributes)) {
             $this->_attributes[$key] = $arguments[0];
         }
     }
 }
コード例 #23
0
 static function addTaxonomy($name, $content_type, $args = null)
 {
     $inflector = ICanBoogie\Inflector::get('en');
     $sanitised = str_replace(" ", "_", strtolower($name));
     $human = $inflector->titleize($sanitised);
     $plural = $inflector->pluralize($human);
     $singular = $inflector->singularize($human);
     $default_args = array('name' => $plural, 'singular_name' => $singular, 'labels' => array('name' => $plural, 'singular_name' => $singular, 'menu_name' => $plural, 'all_items' => "All {$plural}", 'edit_item' => "Edit {$singular}", 'view_item' => "View {$singular}", 'update_item' => "Update {$singular}", 'add_new_item' => "Add new {$singular}", 'new_item_name' => "New {$singular} name", 'parent_item' => "Parent {$singular}", 'parent_item_colon' => "Parent {$singular}:", 'search_items' => "Search {$plural}", 'popular_items' => "Popular {$plural}", 'separate_items_with_commas' => "Separate {$plural} with commas", 'add_or_remove_items' => "Add or remove {$plural}", 'choose_from_most_used' => "Most used {$plural}", 'not_found' => "No {$plural} found"), 'show_in_rest' => true, 'query_var' => true);
     if (is_null($args) || !is_array($args)) {
         $args = $default_args;
     } else {
         $args = array_merge($default_args, $args);
     }
     if (is_array($content_type)) {
         $types = $content_type;
     } elseif ($content_type == 'all') {
         $types = get_post_types(array('public' => true));
     } else {
         $types = [$content_type];
     }
     foreach ($types as $key => $type) {
         register_taxonomy($sanitised, $type, $args);
     }
 }
コード例 #24
0
/**
 * Smarty singularize modifier plugin.
 *
 * Type:     modifier<br>
 * Name:     singularize<br>
 * Purpose:  singularize words in the string
 *
 * @param string $string Input string to singularize.
 *
 * @return string
 */
function smarty_modifier_singularize($string)
{
    $inflector = Inflector::get();
    return $inflector->singularize($string);
}
コード例 #25
0
 /**
  * Get the collection name or lazy load the plural default collection
  * @return string
  */
 public function getCollectionName()
 {
     if (empty($this->collectionName)) {
         $modelName = $this->getModelName();
         if ($modelName) {
             $inflector = Inflector::get();
             $this->setCollectionName($inflector->pluralize($this->modelName));
         }
     }
     return $this->collectionName;
 }
コード例 #26
0
ファイル: DomainEntity.php プロジェクト: codelusion/scheduler
 public function __construct(IEntityValidator $validator)
 {
     $this->validator = $validator;
     $this->inflector = Inflector::get();
 }
コード例 #27
0
ファイル: Factory.php プロジェクト: vsmoraes/dynamo-mapper
 /**
  * @param string $type
  * @return string|null
  */
 protected function isDefaultMapping(string $type)
 {
     $className = sprintf('%s\\%sMapping', static::DEFAULT_NAMESPACE, Inflector::get()->camelize($type));
     return class_exists($className) ? $className : null;
 }
コード例 #28
0
 private function getInflector()
 {
     return Inflector::get('en');
 }
コード例 #29
0
ファイル: BaseModel.php プロジェクト: dwsla/deal
 /**
  * Dynamically build a collection name, typically for those models that
  * don't explicitly declare their own collection names.
  *
  * @return string
  */
 protected function buildCollectionName()
 {
     $inflector = Inflector::get();
     $className = explode('\\', get_class($this));
     $class = end($className);
     return $inflector->underscore($class);
 }
コード例 #30
0
<?php

$this->Breadcrumb->build(['Home' => '/', 'Customers' => '/customers', 'View' => '/customers/view/' . $customer['id'], 'Devices' => '/customers/view/' . $customer['id'] . '#devices', 'View' => '/devices/view/' . $device['id'], 'Invoice']);
use ICanBoogie\Inflector;
$inflector = Inflector::get();
?>
<style type="text/css">
    body, html, #wrapper {
        background: none;
        border: 0;
        box-shadow: none;
        margin: 0;
        overflow: visible;
        padding: 0;
        width: auto;
    }
    .print-page { 
        border: 2px dashed;
        border-radius: 0;
        margin: 0 auto;
        padding: 2cm;
        width: 19cm;
    }
    #top {
        display:none;
    }
    h1 {
        margin: 0 0 0.6em;
    }
    h3 {
        margin: 0;